Skip to content

Commit 0f13010

Browse files
committed
Fix a few tests
1 parent 17461b9 commit 0f13010

File tree

14 files changed

+73
-42
lines changed

14 files changed

+73
-42
lines changed

src/execution/__tests__/executor-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ describe('Execute: Handles basic execution tasks', () => {
276276
schema,
277277
rootValue,
278278
operation,
279-
errorPropagation: true
279+
errorPropagation: true,
280280
});
281281

282282
const field = operation.selectionSet.selections[0];

src/execution/execute.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export interface ExecutionArgs {
161161
*
162162
* @experimental
163163
*/
164-
errorPropagation?: boolean;
164+
errorPropagation?: boolean;
165165
}
166166

167167
/**
@@ -296,7 +296,7 @@ export function buildExecutionContext(
296296
fieldResolver,
297297
typeResolver,
298298
subscribeFieldResolver,
299-
errorPropagation
299+
errorPropagation,
300300
} = args;
301301

302302
let operation: OperationDefinitionNode | undefined;
@@ -671,7 +671,7 @@ function completeValue(
671671
return completed;
672672
}
673673

674-
// If field type is SemanticNonNull, complete for inner type, and throw field error
674+
// If field type is SemanticNonNull, complete for inner type, and throw field error
675675
// if result is null and an error doesn't exist.
676676
if (isSemanticNonNullType(returnType)) {
677677
const completed = completeValue(

src/language/__tests__/parser-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ describe('Parser', () => {
659659
});
660660

661661
describe('parseDocumentDirective', () => {
662-
it('doesnt throw on document-level directive', () => {
662+
it('doesn\'t throw on document-level directive', () => {
663663
parse(dedent`
664664
@SemanticNullability
665665
type Query {

src/language/__tests__/predicates-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('AST node predicates', () => {
9393
'ListType',
9494
'NonNullType',
9595
'SemanticNonNullType',
96+
'SemanticNullableType',
9697
]);
9798
});
9899

src/language/ast.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ export interface ConstDirectiveNode {
523523
readonly arguments?: ReadonlyArray<ConstArgumentNode>;
524524
}
525525

526-
527526
export interface SemanticNonNullTypeNode {
528527
readonly kind: Kind.SEMANTIC_NON_NULL_TYPE;
529528
readonly loc?: Location;

src/language/lexer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ function readNextToken(lexer: Lexer, start: number): Token {
251251
case 0x0021: // !
252252
return createToken(lexer, TokenKind.BANG, position, position + 1);
253253
case 0x003f: // ?
254-
return createToken(lexer, TokenKind.QUESTION_MARK, position, position + 1);
254+
return createToken(
255+
lexer,
256+
TokenKind.QUESTION_MARK,
257+
position,
258+
position + 1,
259+
);
255260
case 0x0024: // $
256261
return createToken(lexer, TokenKind.DOLLAR, position, position + 1);
257262
case 0x0026: // &

src/language/parser.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ import type {
5050
SchemaExtensionNode,
5151
SelectionNode,
5252
SelectionSetNode,
53-
StringValueNode,
5453
SemanticNonNullTypeNode,
5554
SemanticNullableTypeNode,
55+
StringValueNode,
5656
Token,
5757
TypeNode,
5858
TypeSystemExtensionNode,
@@ -109,10 +109,10 @@ export interface ParseOptions {
109109
/**
110110
* When enabled, the parser will understand and parse semantic nullability
111111
* annotations. This means that every type suffixed with `!` will remain
112-
* non-nulllable, every type suffxed with `?` will be the classic nullable, and
112+
* non-nullable, every type suffixed with `?` will be the classic nullable, and
113113
* types without a suffix will be semantically nullable. Semantic nullability
114114
* will be the new default when this is enabled. A semantically nullable type
115-
* can only be null when there's an error assocaited with the field.
115+
* can only be null when there's an error associated with the field.
116116
*
117117
* @experimental
118118
*/
@@ -788,6 +788,25 @@ export class Parser {
788788
type = this.parseNamedType();
789789
}
790790

791+
if (this._options.allowSemanticNullability) {
792+
if (this.expectOptionalToken(TokenKind.BANG)) {
793+
return this.node<NonNullTypeNode>(start, {
794+
kind: Kind.NON_NULL_TYPE,
795+
type,
796+
});
797+
} else if (this.expectOptionalToken(TokenKind.QUESTION_MARK)) {
798+
return this.node<SemanticNullableTypeNode>(start, {
799+
kind: Kind.SEMANTIC_NULLABLE_TYPE,
800+
type,
801+
});
802+
}
803+
804+
return this.node<SemanticNonNullTypeNode>(start, {
805+
kind: Kind.SEMANTIC_NON_NULL_TYPE,
806+
type,
807+
});
808+
}
809+
791810
if (this.expectOptionalToken(TokenKind.BANG)) {
792811
return this.node<NonNullTypeNode>(start, {
793812
kind: Kind.NON_NULL_TYPE,

src/type/__tests__/introspection-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Introspection', () => {
3232
expect(result).to.deep.equal({
3333
data: {
3434
__schema: {
35-
queryType: { name: 'SomeObject' },
35+
queryType: { kind: 'OBJECT', name: 'SomeObject' },
3636
mutationType: null,
3737
subscriptionType: null,
3838
types: [

src/type/__tests__/predicate-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,4 +765,4 @@ describe('Directive predicates', () => {
765765
expect(isSpecifiedDirective(Directive)).to.equal(false);
766766
});
767767
});
768-
});
768+
});

src/type/definition.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@ export type GraphQLType =
6767
| GraphQLInputObjectType
6868
| GraphQLList<GraphQLType>
6969
>
70-
| GraphQLSemanticNonNull<
71-
| GraphQLScalarType
72-
| GraphQLObjectType
73-
| GraphQLInterfaceType
74-
| GraphQLUnionType
75-
| GraphQLEnumType
76-
| GraphQLInputObjectType
77-
| GraphQLList<GraphQLType>
78-
>
70+
| GraphQLSemanticNonNull<
71+
| GraphQLScalarType
72+
| GraphQLObjectType
73+
| GraphQLInterfaceType
74+
| GraphQLUnionType
75+
| GraphQLEnumType
76+
| GraphQLInputObjectType
77+
| GraphQLList<GraphQLType>
78+
>
7979
| GraphQLSemanticNullable<
80-
| GraphQLScalarType
81-
| GraphQLObjectType
82-
| GraphQLInterfaceType
83-
| GraphQLUnionType
84-
| GraphQLEnumType
85-
| GraphQLInputObjectType
86-
| GraphQLList<GraphQLType>
87-
>;
80+
| GraphQLScalarType
81+
| GraphQLObjectType
82+
| GraphQLInterfaceType
83+
| GraphQLUnionType
84+
| GraphQLEnumType
85+
| GraphQLInputObjectType
86+
| GraphQLList<GraphQLType>
87+
>;
8888

8989
export function isType(type: unknown): type is GraphQLType {
9090
return (
@@ -325,13 +325,15 @@ export type GraphQLOutputType =
325325
| GraphQLUnionType
326326
| GraphQLEnumType
327327
| GraphQLList<GraphQLOutputType>
328-
> | GraphQLSemanticNonNull<
329-
| GraphQLScalarType
330-
| GraphQLObjectType
331-
| GraphQLInterfaceType
332-
| GraphQLUnionType
333-
| GraphQLEnumType
334-
| GraphQLList<GraphQLOutputType> >;
328+
>
329+
| GraphQLSemanticNonNull<
330+
| GraphQLScalarType
331+
| GraphQLObjectType
332+
| GraphQLInterfaceType
333+
| GraphQLUnionType
334+
| GraphQLEnumType
335+
| GraphQLList<GraphQLOutputType>
336+
>;
335337

336338
export function isOutputType(type: unknown): type is GraphQLOutputType {
337339
return (

0 commit comments

Comments
 (0)