Skip to content

Propose single wrapping type #4339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/execution/__tests__/semantic-nullability-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GraphQLNonNull,
GraphQLObjectType,
GraphQLSemanticNonNull,
GraphQLSemanticNullable,
} from '../../type/definition';
import { GraphQLString } from '../../type/scalars';
import { GraphQLSchema } from '../../type/schema';
Expand All @@ -28,7 +27,7 @@ describe('Execute: Handles Semantic Nullability', () => {
const DataType: GraphQLObjectType = new GraphQLObjectType({
name: 'DataType',
fields: () => ({
a: { type: new GraphQLSemanticNullable(GraphQLString) },
a: { type: GraphQLString },
b: { type: new GraphQLSemanticNonNull(GraphQLString) },
c: { type: new GraphQLNonNull(GraphQLString) },
d: { type: new GraphQLSemanticNonNull(DeepDataType) },
Expand Down
13 changes: 0 additions & 13 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
isNonNullType,
isObjectType,
isSemanticNonNullType,
isSemanticNullableType,
} from '../type/definition';
import {
SchemaMetaFieldDef,
Expand Down Expand Up @@ -690,18 +689,6 @@ function completeValue(
return completed;
}

// If field type is SemanticNullable, complete for inner type
if (isSemanticNullableType(returnType)) {
return completeValue(
exeContext,
returnType.ofType,
fieldNodes,
info,
path,
result,
);
}

// If result value is null or undefined then return null.
if (result == null) {
return null;
Expand Down
16 changes: 6 additions & 10 deletions src/language/__tests__/parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ describe('Parser', () => {
});

describe('parseDocumentDirective', () => {
it('doesn\'t throw on document-level directive', () => {
it("doesn't throw on document-level directive", () => {
parse(dedent`
@SemanticNullability
type Query {
Expand Down Expand Up @@ -690,16 +690,12 @@ describe('Parser', () => {
it('parses nullable types', () => {
const result = parseType('MyType?', { allowSemanticNullability: true });
expectJSON(result).toDeepEqual({
kind: Kind.SEMANTIC_NULLABLE_TYPE,
loc: { start: 0, end: 7 },
type: {
kind: Kind.NAMED_TYPE,
kind: Kind.NAMED_TYPE,
loc: { start: 0, end: 6 },
name: {
kind: Kind.NAME,
loc: { start: 0, end: 6 },
name: {
kind: Kind.NAME,
loc: { start: 0, end: 6 },
value: 'MyType',
},
value: 'MyType',
},
});
});
Expand Down
1 change: 0 additions & 1 deletion src/language/__tests__/predicates-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('AST node predicates', () => {
'ListType',
'NonNullType',
'SemanticNonNullType',
'SemanticNullableType',
]);
});

Expand Down
20 changes: 15 additions & 5 deletions src/language/__tests__/schema-printer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,38 @@ describe('Printer: SDL document', () => {

it('prints NamedType', () => {
expect(
print(parseType('MyType', { allowSemanticNullability: false })),
print(parseType('MyType', { allowSemanticNullability: false }), {
useSemanticNullability: false,
}),
).to.equal(dedent`MyType`);
});

it('prints SemanticNullableType', () => {
expect(
print(parseType('MyType?', { allowSemanticNullability: true })),
print(parseType('MyType?', { allowSemanticNullability: true }), {
useSemanticNullability: true,
}),
).to.equal(dedent`MyType?`);
});

it('prints SemanticNonNullType', () => {
expect(
print(parseType('MyType', { allowSemanticNullability: true })),
print(parseType('MyType', { allowSemanticNullability: true }), {
useSemanticNullability: true,
}),
).to.equal(dedent`MyType`);
});

it('prints NonNullType', () => {
expect(
print(parseType('MyType!', { allowSemanticNullability: true })),
print(parseType('MyType!', { allowSemanticNullability: true }), {
useSemanticNullability: true,
}),
).to.equal(dedent`MyType!`);
expect(
print(parseType('MyType!', { allowSemanticNullability: false })),
print(parseType('MyType!', { allowSemanticNullability: false }), {
useSemanticNullability: true,
}),
).to.equal(dedent`MyType!`);
});
});
11 changes: 1 addition & 10 deletions src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export type ASTNode =
| ListTypeNode
| NonNullTypeNode
| SemanticNonNullTypeNode
| SemanticNullableTypeNode
| SchemaDefinitionNode
| OperationTypeDefinitionNode
| ScalarTypeDefinitionNode
Expand Down Expand Up @@ -238,7 +237,6 @@ export const QueryDocumentKeys: {
ListType: ['type'],
NonNullType: ['type'],
SemanticNonNullType: ['type'],
SemanticNullableType: ['type'],

SchemaDefinition: ['description', 'directives', 'operationTypes'],
OperationTypeDefinition: ['type'],
Expand Down Expand Up @@ -529,20 +527,13 @@ export interface SemanticNonNullTypeNode {
readonly type: NamedTypeNode | ListTypeNode;
}

export interface SemanticNullableTypeNode {
readonly kind: Kind.SEMANTIC_NULLABLE_TYPE;
readonly loc?: Location;
readonly type: NamedTypeNode | ListTypeNode;
}

/** Type Reference */

export type TypeNode =
| NamedTypeNode
| ListTypeNode
| NonNullTypeNode
| SemanticNonNullTypeNode
| SemanticNullableTypeNode;
| SemanticNonNullTypeNode;

export interface NamedTypeNode {
readonly kind: Kind.NAMED_TYPE;
Expand Down
1 change: 0 additions & 1 deletion src/language/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ enum Kind {
LIST_TYPE = 'ListType',
NON_NULL_TYPE = 'NonNullType',
SEMANTIC_NON_NULL_TYPE = 'SemanticNonNullType',
SEMANTIC_NULLABLE_TYPE = 'SemanticNullableType',

/** Type System Definitions */
SCHEMA_DEFINITION = 'SchemaDefinition',
Expand Down
6 changes: 1 addition & 5 deletions src/language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import type {
SelectionNode,
SelectionSetNode,
SemanticNonNullTypeNode,
SemanticNullableTypeNode,
StringValueNode,
Token,
TypeNode,
Expand Down Expand Up @@ -795,10 +794,7 @@ export class Parser {
type,
});
} else if (this.expectOptionalToken(TokenKind.QUESTION_MARK)) {
return this.node<SemanticNullableTypeNode>(start, {
kind: Kind.SEMANTIC_NULLABLE_TYPE,
type,
});
return type;
}

return this.node<SemanticNonNullTypeNode>(start, {
Expand Down
3 changes: 1 addition & 2 deletions src/language/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export function isTypeNode(node: ASTNode): node is TypeNode {
node.kind === Kind.NAMED_TYPE ||
node.kind === Kind.LIST_TYPE ||
node.kind === Kind.NON_NULL_TYPE ||
node.kind === Kind.SEMANTIC_NON_NULL_TYPE ||
node.kind === Kind.SEMANTIC_NULLABLE_TYPE
node.kind === Kind.SEMANTIC_NON_NULL_TYPE
);
}

Expand Down
Loading
Loading