Skip to content

Commit

Permalink
Be stricter about types
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Feb 12, 2025
1 parent ac213fa commit 1861f71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ export interface SemanticNonNullTypeNode {
/** Type Reference */

export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
export type SchemaOutputTypeNode =
| NamedTypeNode
| ListTypeNode
| NonNullTypeNode
| SemanticNonNullTypeNode;

export interface NamedTypeNode {
readonly kind: Kind.NAMED_TYPE;
Expand All @@ -540,7 +545,13 @@ export interface NamedTypeNode {
export interface ListTypeNode {
readonly kind: Kind.LIST_TYPE;
readonly loc?: Location;
readonly type: TypeNode | SemanticNonNullTypeNode;
readonly type: TypeNode;
}

export interface SchemaListTypeNode {
readonly kind: Kind.LIST_TYPE;
readonly loc?: Location;
readonly type: SchemaOutputTypeNode;
}

export interface NonNullTypeNode {
Expand Down Expand Up @@ -605,7 +616,7 @@ export interface FieldDefinitionNode {
readonly description?: StringValueNode;
readonly name: NameNode;
readonly arguments?: ReadonlyArray<InputValueDefinitionNode>;
readonly type: TypeNode | SemanticNonNullTypeNode;
readonly type: SchemaOutputTypeNode;
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
}

Expand Down
7 changes: 2 additions & 5 deletions src/utilities/extendSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import type {
ScalarTypeExtensionNode,
SchemaDefinitionNode,
SchemaExtensionNode,
SemanticNonNullTypeNode,
SchemaOutputTypeNode,
TypeDefinitionNode,
TypeNode,
UnionTypeDefinitionNode,
UnionTypeExtensionNode,
} from '../language/ast';
Expand Down Expand Up @@ -432,9 +431,7 @@ export function extendSchemaImpl(
return type;
}

function getWrappedType(
node: TypeNode | SemanticNonNullTypeNode,
): GraphQLType {
function getWrappedType(node: SchemaOutputTypeNode): GraphQLType {
if (node.kind === Kind.LIST_TYPE) {
return new GraphQLList(getWrappedType(node.type));
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/typeFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function typeFromAST(
): GraphQLType | undefined {
switch (typeNode.kind) {
case Kind.LIST_TYPE: {
const innerType = typeFromAST(schema, typeNode.type as TypeNode);
const innerType = typeFromAST(schema, typeNode.type);
return innerType && new GraphQLList(innerType);
}
case Kind.NON_NULL_TYPE: {
Expand Down

0 comments on commit 1861f71

Please sign in to comment.