Skip to content

Commit cecaa88

Browse files
committed
Yet more updates
1 parent a4ec545 commit cecaa88

File tree

11 files changed

+67
-3
lines changed

11 files changed

+67
-3
lines changed

src/language/__tests__/parser-test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,23 @@ describe('Parser', () => {
631631
});
632632
});
633633

634+
it('parses semantic-non-null types', () => {
635+
const result = parseType('MyType*');
636+
expectJSON(result).toDeepEqual({
637+
kind: Kind.SEMANTIC_NON_NULL_TYPE,
638+
loc: { start: 0, end: 7 },
639+
type: {
640+
kind: Kind.NAMED_TYPE,
641+
loc: { start: 0, end: 6 },
642+
name: {
643+
kind: Kind.NAME,
644+
loc: { start: 0, end: 6 },
645+
value: 'MyType',
646+
},
647+
},
648+
});
649+
});
650+
634651
it('parses nested types', () => {
635652
const result = parseType('[MyType!]');
636653
expectJSON(result).toDeepEqual({

src/language/ast.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export type ASTNode =
161161
| NamedTypeNode
162162
| ListTypeNode
163163
| NonNullTypeNode
164+
| SemanticNonNullTypeNode
164165
| SchemaDefinitionNode
165166
| OperationTypeDefinitionNode
166167
| ScalarTypeDefinitionNode
@@ -520,7 +521,11 @@ export interface ConstDirectiveNode {
520521

521522
/** Type Reference */
522523

523-
export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
524+
export type TypeNode =
525+
| NamedTypeNode
526+
| ListTypeNode
527+
| NonNullTypeNode
528+
| SemanticNonNullTypeNode;
524529

525530
export interface NamedTypeNode {
526531
readonly kind: Kind.NAMED_TYPE;

src/language/parser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
NamedTypeNode,
3838
NameNode,
3939
NonNullTypeNode,
40+
SemanticNonNullTypeNode,
4041
NullValueNode,
4142
ObjectFieldNode,
4243
ObjectTypeDefinitionNode,
@@ -740,6 +741,7 @@ export class Parser {
740741
* - NamedType
741742
* - ListType
742743
* - NonNullType
744+
* - SemanticNonNullType
743745
*/
744746
parseTypeReference(): TypeNode {
745747
const start = this._lexer.token;
@@ -761,6 +763,12 @@ export class Parser {
761763
type,
762764
});
763765
}
766+
if (this.expectOptionalToken(TokenKind.ASTERISK)) {
767+
return this.node<SemanticNonNullTypeNode>(start, {
768+
kind: Kind.SEMANTIC_NON_NULL_TYPE,
769+
type,
770+
});
771+
}
764772

765773
return type;
766774
}

src/language/predicates.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export function isTypeNode(node: ASTNode): node is TypeNode {
6767
return (
6868
node.kind === Kind.NAMED_TYPE ||
6969
node.kind === Kind.LIST_TYPE ||
70-
node.kind === Kind.NON_NULL_TYPE
70+
node.kind === Kind.NON_NULL_TYPE ||
71+
node.kind === Kind.SEMANTIC_NON_NULL_TYPE
7172
);
7273
}
7374

src/language/tokenKind.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum TokenKind {
66
SOF = '<SOF>',
77
EOF = '<EOF>',
88
BANG = '!',
9+
ASTERISK = '*',
910
DOLLAR = '$',
1011
AMP = '&',
1112
PAREN_L = '(',

src/type/introspection.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ export const __TypeKind: GraphQLEnumType = new GraphQLEnumType({
502502
description:
503503
'Indicates this type is a non-null. `ofType` is a valid field.',
504504
},
505+
SEMANTIC_NON_NULL: {
506+
value: TypeKind.SEMANTIC_NON_NULL,
507+
description:
508+
'Indicates this type is a semantic-non-null. `ofType` is a valid field.',
509+
},
505510
},
506511
});
507512

src/utilities/__tests__/printSchema-test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,9 @@ describe('Type System Printer', () => {
770770
771771
"""Indicates this type is a non-null. \`ofType\` is a valid field."""
772772
NON_NULL
773+
774+
"""Indicates this type is a semantic-non-null. \`ofType\` is a valid field."""
775+
SEMANTIC_NON_NULL
773776
}
774777
775778
"""

src/utilities/buildClientSchema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
GraphQLInterfaceType,
2121
GraphQLList,
2222
GraphQLNonNull,
23+
GraphQLSemanticNonNull,
2324
GraphQLObjectType,
2425
GraphQLScalarType,
2526
GraphQLUnionType,
@@ -137,6 +138,14 @@ export function buildClientSchema(
137138
const nullableType = getType(nullableRef);
138139
return new GraphQLNonNull(assertNullableType(nullableType));
139140
}
141+
if (typeRef.kind === TypeKind.SEMANTIC_NON_NULL) {
142+
const nullableRef = typeRef.ofType;
143+
if (!nullableRef) {
144+
throw new Error('Decorated type deeper than introspection query.');
145+
}
146+
const nullableType = getType(nullableRef);
147+
return new GraphQLSemanticNonNull(assertNullableType(nullableType));
148+
}
140149
return getNamedType(typeRef);
141150
}
142151

src/utilities/extendSchema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
GraphQLInterfaceType,
5252
GraphQLList,
5353
GraphQLNonNull,
54+
GraphQLSemanticNonNull,
5455
GraphQLObjectType,
5556
GraphQLScalarType,
5657
GraphQLUnionType,
@@ -437,6 +438,9 @@ export function extendSchemaImpl(
437438
if (node.kind === Kind.NON_NULL_TYPE) {
438439
return new GraphQLNonNull(getWrappedType(node.type));
439440
}
441+
if (node.kind === Kind.SEMANTIC_NON_NULL_TYPE) {
442+
return new GraphQLSemanticNonNull(getWrappedType(node.type));
443+
}
440444
return getNamedType(node);
441445
}
442446

src/utilities/getIntrospectionQuery.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ export type IntrospectionTypeRef =
297297
| IntrospectionListTypeRef
298298
| IntrospectionNonNullTypeRef<
299299
IntrospectionNamedTypeRef | IntrospectionListTypeRef
300+
>
301+
| IntrospectionSemanticNonNullTypeRef<
302+
IntrospectionNamedTypeRef | IntrospectionListTypeRef
300303
>;
301304

302305
export type IntrospectionOutputTypeRef =

0 commit comments

Comments
 (0)