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 bb401a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ 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 +541,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 +612,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
5 changes: 2 additions & 3 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 @@ -433,7 +432,7 @@ export function extendSchemaImpl(
}

function getWrappedType(
node: TypeNode | SemanticNonNullTypeNode,
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 bb401a3

Please sign in to comment.