Skip to content

Commit 930c7d2

Browse files
committed
Remove SemanticNonNull from TypeNode
This type is reused for variables, inputs and list-types which can't be smantically non-null. list-types can be but only if they are used in an SDL context. This is kind of a short-coming of our types, we conflate SDL and execution language.
1 parent 2321f93 commit 930c7d2

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

src/language/ast.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,7 @@ export interface SemanticNonNullTypeNode {
529529

530530
/** Type Reference */
531531

532-
export type TypeNode =
533-
| NamedTypeNode
534-
| ListTypeNode
535-
| NonNullTypeNode
536-
| SemanticNonNullTypeNode;
532+
export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
537533

538534
export interface NamedTypeNode {
539535
readonly kind: Kind.NAMED_TYPE;
@@ -609,7 +605,7 @@ export interface FieldDefinitionNode {
609605
readonly description?: StringValueNode;
610606
readonly name: NameNode;
611607
readonly arguments?: ReadonlyArray<InputValueDefinitionNode>;
612-
readonly type: TypeNode;
608+
readonly type: TypeNode | SemanticNonNullTypeNode;
613609
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
614610
}
615611

src/language/parser.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export function parseConstValue(
184184
export function parseType(
185185
source: string | Source,
186186
options?: ParseOptions | undefined,
187-
): TypeNode {
187+
): TypeNode | SemanticNonNullTypeNode {
188188
const parser = new Parser(source, options);
189189
parser.expectToken(TokenKind.SOF);
190190
const type = parser.parseTypeReference();
@@ -403,7 +403,8 @@ export class Parser {
403403
return this.node<VariableDefinitionNode>(this._lexer.token, {
404404
kind: Kind.VARIABLE_DEFINITION,
405405
variable: this.parseVariable(),
406-
type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()),
406+
type: (this.expectToken(TokenKind.COLON),
407+
this.parseTypeReference()) as TypeNode,
407408
defaultValue: this.expectOptionalToken(TokenKind.EQUALS)
408409
? this.parseConstValueLiteral()
409410
: undefined,
@@ -773,15 +774,15 @@ export class Parser {
773774
* - ListType
774775
* - NonNullType
775776
*/
776-
parseTypeReference(): TypeNode {
777+
parseTypeReference(): TypeNode | SemanticNonNullTypeNode {
777778
const start = this._lexer.token;
778779
let type;
779780
if (this.expectOptionalToken(TokenKind.BRACKET_L)) {
780781
const innerType = this.parseTypeReference();
781782
this.expectToken(TokenKind.BRACKET_R);
782783
type = this.node<ListTypeNode>(start, {
783784
kind: Kind.LIST_TYPE,
784-
type: innerType,
785+
type: innerType as TypeNode,
785786
});
786787
} else {
787788
type = this.parseNamedType();
@@ -992,7 +993,7 @@ export class Parser {
992993
kind: Kind.INPUT_VALUE_DEFINITION,
993994
description,
994995
name,
995-
type,
996+
type: type as TypeNode,
996997
defaultValue,
997998
directives,
998999
});

src/utilities/extendSchema.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
ScalarTypeExtensionNode,
2525
SchemaDefinitionNode,
2626
SchemaExtensionNode,
27+
SemanticNonNullTypeNode,
2728
TypeDefinitionNode,
2829
TypeNode,
2930
UnionTypeDefinitionNode,
@@ -431,7 +432,9 @@ export function extendSchemaImpl(
431432
return type;
432433
}
433434

434-
function getWrappedType(node: TypeNode): GraphQLType {
435+
function getWrappedType(
436+
node: TypeNode | SemanticNonNullTypeNode,
437+
): GraphQLType {
435438
if (node.kind === Kind.LIST_TYPE) {
436439
return new GraphQLList(getWrappedType(node.type));
437440
}

src/utilities/typeFromAST.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import type {
77
import { Kind } from '../language/kinds';
88

99
import type { GraphQLNamedType, GraphQLType } from '../type/definition';
10-
import {
11-
GraphQLList,
12-
GraphQLNonNull,
13-
GraphQLSemanticNonNull,
14-
} from '../type/definition';
10+
import { GraphQLList, GraphQLNonNull } from '../type/definition';
1511
import type { GraphQLSchema } from '../type/schema';
1612

1713
/**
@@ -50,12 +46,6 @@ export function typeFromAST(
5046
const innerType = typeFromAST(schema, typeNode.type);
5147
return innerType && new GraphQLNonNull(innerType);
5248
}
53-
// We only use typeFromAST for fragment/variable type inference
54-
// which should not be affected by semantic non-null types
55-
// case Kind.SEMANTIC_NON_NULL_TYPE: {
56-
// const innerType = typeFromAST(schema, typeNode.type);
57-
// return innerType && new GraphQLSemanticNonNull(innerType);
58-
// }
5949
case Kind.NAMED_TYPE:
6050
return schema.getType(typeNode.name.value);
6151
}

0 commit comments

Comments
 (0)