Skip to content

Commit

Permalink
Fix a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Feb 2, 2025
1 parent 17461b9 commit 7c0b4bb
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('Execute: Handles basic execution tasks', () => {
schema,
rootValue,
operation,
errorPropagation: true
errorPropagation: true,
});

const field = operation.selectionSet.selections[0];
Expand Down
6 changes: 3 additions & 3 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export interface ExecutionArgs {
*
* @experimental
*/
errorPropagation?: boolean;
errorPropagation?: boolean;
}

/**
Expand Down Expand Up @@ -296,7 +296,7 @@ export function buildExecutionContext(
fieldResolver,
typeResolver,
subscribeFieldResolver,
errorPropagation
errorPropagation,
} = args;

let operation: OperationDefinitionNode | undefined;
Expand Down Expand Up @@ -671,7 +671,7 @@ function completeValue(
return completed;
}

// If field type is SemanticNonNull, complete for inner type, and throw field error
// If field type is SemanticNonNull, complete for inner type, and throw field error
// if result is null and an error doesn't exist.
if (isSemanticNonNullType(returnType)) {
const completed = completeValue(
Expand Down
1 change: 1 addition & 0 deletions src/language/__tests__/predicates-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('AST node predicates', () => {
'ListType',
'NonNullType',
'SemanticNonNullType',
'SemanticNullableType',
]);
});

Expand Down
1 change: 0 additions & 1 deletion src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ export interface ConstDirectiveNode {
readonly arguments?: ReadonlyArray<ConstArgumentNode>;
}


export interface SemanticNonNullTypeNode {
readonly kind: Kind.SEMANTIC_NON_NULL_TYPE;
readonly loc?: Location;
Expand Down
7 changes: 6 additions & 1 deletion src/language/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ function readNextToken(lexer: Lexer, start: number): Token {
case 0x0021: // !
return createToken(lexer, TokenKind.BANG, position, position + 1);
case 0x003f: // ?
return createToken(lexer, TokenKind.QUESTION_MARK, position, position + 1);
return createToken(
lexer,
TokenKind.QUESTION_MARK,
position,
position + 1,
);
case 0x0024: // $
return createToken(lexer, TokenKind.DOLLAR, position, position + 1);
case 0x0026: // &
Expand Down
21 changes: 20 additions & 1 deletion src/language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import type {
SchemaExtensionNode,
SelectionNode,
SelectionSetNode,
StringValueNode,
SemanticNonNullTypeNode,
SemanticNullableTypeNode,
StringValueNode,
Token,
TypeNode,
TypeSystemExtensionNode,
Expand Down Expand Up @@ -788,6 +788,25 @@ export class Parser {
type = this.parseNamedType();
}

if (this._options.allowSemanticNullability) {
if (this.expectOptionalToken(TokenKind.BANG)) {
return this.node<NonNullTypeNode>(start, {
kind: Kind.NON_NULL_TYPE,
type,
});
} else if (this.expectOptionalToken(TokenKind.QUESTION_MARK)) {
return this.node<SemanticNullableTypeNode>(start, {
kind: Kind.SEMANTIC_NULLABLE_TYPE,
type,
});
}

return this.node<SemanticNonNullTypeNode>(start, {
kind: Kind.SEMANTIC_NON_NULL_TYPE,
type,
});
}

if (this.expectOptionalToken(TokenKind.BANG)) {
return this.node<NonNullTypeNode>(start, {
kind: Kind.NON_NULL_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/introspection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Introspection', () => {
expect(result).to.deep.equal({
data: {
__schema: {
queryType: { name: 'SomeObject' },
queryType: { kind: 'OBJECT', name: 'SomeObject' },
mutationType: null,
subscriptionType: null,
types: [
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/predicate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,4 +765,4 @@ describe('Directive predicates', () => {
expect(isSpecifiedDirective(Directive)).to.equal(false);
});
});
});
});
50 changes: 26 additions & 24 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ export type GraphQLType =
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>
| GraphQLSemanticNonNull<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>
| GraphQLSemanticNonNull<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>
| GraphQLSemanticNullable<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>;
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>;

export function isType(type: unknown): type is GraphQLType {
return (
Expand Down Expand Up @@ -325,13 +325,15 @@ export type GraphQLOutputType =
| GraphQLUnionType
| GraphQLEnumType
| GraphQLList<GraphQLOutputType>
> | GraphQLSemanticNonNull<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLList<GraphQLOutputType> >;
>
| GraphQLSemanticNonNull<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLUnionType
| GraphQLEnumType
| GraphQLList<GraphQLOutputType>
>;

export function isOutputType(type: unknown): type is GraphQLOutputType {
return (
Expand Down
8 changes: 4 additions & 4 deletions src/type/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ export const __Field: GraphQLObjectType = new GraphQLObjectType({
}

Check warning on line 417 in src/type/introspection.ts

View check run for this annotation

Codecov / codecov/patch

src/type/introspection.ts#L416-L417

Added lines #L416 - L417 were not covered by tests

const mode =
nullability === TypeNullability.AUTO
? info.errorPropagation
? TypeNullability.TRADITIONAL
: TypeNullability.SEMANTIC
nullability === TypeNullability.AUTO
? info.errorPropagation
? TypeNullability.TRADITIONAL
: TypeNullability.SEMANTIC
: nullability;

Check warning on line 424 in src/type/introspection.ts

View check run for this annotation

Codecov / codecov/patch

src/type/introspection.ts#L421-L424

Added lines #L421 - L424 were not covered by tests
return convertOutputTypeToNullabilityMode(field.type, mode);
},
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/buildClientSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
GraphQLNonNull,
GraphQLObjectType,
GraphQLScalarType,
GraphQLUnionType,
GraphQLSemanticNonNull,
GraphQLUnionType,
isInputType,
isOutputType,
} from '../type/definition';
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/extendSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ import {
GraphQLNonNull,
GraphQLObjectType,
GraphQLScalarType,
GraphQLUnionType,
GraphQLSemanticNonNull,
GraphQLSemanticNullable,
GraphQLUnionType,
isEnumType,
isInputObjectType,
isInterfaceType,
Expand Down
5 changes: 5 additions & 0 deletions src/utilities/typeFromAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
GraphQLList,
GraphQLNonNull,
GraphQLSemanticNonNull,
GraphQLSemanticNullable,
} from '../type/definition';
import type { GraphQLSchema } from '../type/schema';

Expand Down Expand Up @@ -54,6 +55,10 @@ export function typeFromAST(
const innerType = typeFromAST(schema, typeNode.type);
return innerType && new GraphQLSemanticNonNull(innerType);
}

Check warning on line 57 in src/utilities/typeFromAST.ts

View check run for this annotation

Codecov / codecov/patch

src/utilities/typeFromAST.ts#L55-L57

Added lines #L55 - L57 were not covered by tests
case Kind.SEMANTIC_NULLABLE_TYPE: {
const innerType = typeFromAST(schema, typeNode.type);
return innerType && new GraphQLSemanticNullable(innerType);
}

Check warning on line 61 in src/utilities/typeFromAST.ts

View check run for this annotation

Codecov / codecov/patch

src/utilities/typeFromAST.ts#L59-L61

Added lines #L59 - L61 were not covered by tests
case Kind.NAMED_TYPE:
return schema.getType(typeNode.name.value);
}
Expand Down

0 comments on commit 7c0b4bb

Please sign in to comment.