Skip to content

Commit

Permalink
rename to SemanticNullable
Browse files Browse the repository at this point in the history
  • Loading branch information
twof committed Nov 8, 2024
1 parent 0a8b68f commit 24474fa
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"test": "npm run lint && npm run check && npm run testonly && npm run prettier:check && npm run check:spelling && npm run check:integrations",
"lint": "eslint --cache --max-warnings 0 .",
"check": "tsc --pretty",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts -g 'SemanticOptional allows null values'",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts",
"testonly:cover": "c8 npm run testonly",
"prettier": "prettier --write --list-different .",
"prettier:check": "prettier --check .",
Expand Down
8 changes: 4 additions & 4 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
GraphQLObjectType,
GraphQLScalarType,
GraphQLSemanticNonNull,
GraphQLSemanticOptional,
GraphQLSemanticNullable,
GraphQLUnionType,
} from '../../type/definition';
import { GraphQLBoolean, GraphQLInt, GraphQLString } from '../../type/scalars';
Expand Down Expand Up @@ -1339,7 +1339,7 @@ describe('Execute: Handles Semantic Nullability', () => {
const DataType: GraphQLObjectType = new GraphQLObjectType({
name: 'DataType',
fields: () => ({
a: { type: new GraphQLSemanticOptional(GraphQLString) },
a: { type: new GraphQLSemanticNullable(GraphQLString) },
b: { type: new GraphQLSemanticNonNull(GraphQLString) },
c: { type: new GraphQLNonNull(GraphQLString) },
d: { type: new GraphQLSemanticNonNull(DeepDataType) }
Expand Down Expand Up @@ -1471,7 +1471,7 @@ describe('Execute: Handles Semantic Nullability', () => {
});
});

it('SemanticOptional allows null values', async () => {
it('SemanticNullable allows null values', async () => {
const data = {
a: () => null,
b: () => null,
Expand All @@ -1497,7 +1497,7 @@ describe('Execute: Handles Semantic Nullability', () => {
});
});

it('SemanticOptional allows non-null values', async () => {
it('SemanticNullable allows non-null values', async () => {
const data = {
a: () => 'Apple',
b: () => null,
Expand Down
6 changes: 3 additions & 3 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
isNonNullType,
isObjectType,
isSemanticNonNullType,
isSemanticOptionalType,
isSemanticNullableType,
} from '../type/definition';
import {
SchemaMetaFieldDef,
Expand Down Expand Up @@ -689,8 +689,8 @@ function completeValue(
return completed;
}

// If field type is SemanticOptional, complete for inner type
if (isSemanticOptionalType(returnType)) {
// If field type is SemanticNullable, complete for inner type
if (isSemanticNullableType(returnType)) {
return completeValue(
exeContext,
returnType.ofType,
Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ describe('Parser', () => {
it('parses nullable types', () => {
const result = parseType('MyType?', { useSemanticNullability: true });
expectJSON(result).toDeepEqual(
{ kind: Kind.SEMANTIC_OPTIONAL_TYPE,
{ kind: Kind.SEMANTIC_NULLABLE_TYPE,
loc: { start: 0, end: 7 },
type: {
kind: Kind.NAMED_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/schema-printer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('Printer: SDL document', () => {
expect(print(parseType('MyType', { useSemanticNullability: false }))).to.equal(dedent`MyType`);
});

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

Expand Down
10 changes: 5 additions & 5 deletions src/language/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export type ASTNode =
| ListTypeNode
| NonNullTypeNode
| SemanticNonNullTypeNode
| SemanticOptionalTypeNode
| SemanticNullableTypeNode
| SchemaDefinitionNode
| OperationTypeDefinitionNode
| ScalarTypeDefinitionNode
Expand Down Expand Up @@ -238,7 +238,7 @@ export const QueryDocumentKeys: {
ListType: ['type'],
NonNullType: ['type'],
SemanticNonNullType: ['type'],
SemanticOptionalType: ['type'],
SemanticNullableType: ['type'],

SchemaDefinition: ['description', 'directives', 'operationTypes'],
OperationTypeDefinition: ['type'],
Expand Down Expand Up @@ -529,7 +529,7 @@ export type TypeNode =
| ListTypeNode
| NonNullTypeNode
| SemanticNonNullTypeNode
| SemanticOptionalTypeNode;
| SemanticNullableTypeNode;

export interface NamedTypeNode {
readonly kind: Kind.NAMED_TYPE;
Expand All @@ -555,8 +555,8 @@ export interface SemanticNonNullTypeNode {
readonly type: NamedTypeNode | ListTypeNode;
}

export interface SemanticOptionalTypeNode {
readonly kind: Kind.SEMANTIC_OPTIONAL_TYPE;
export interface SemanticNullableTypeNode {
readonly kind: Kind.SEMANTIC_NULLABLE_TYPE;
readonly loc?: Location;
readonly type: NamedTypeNode | ListTypeNode;
}
Expand Down
2 changes: 1 addition & 1 deletion src/language/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum Kind {
LIST_TYPE = 'ListType',
NON_NULL_TYPE = 'NonNullType',
SEMANTIC_NON_NULL_TYPE = 'SemanticNonNullType',
SEMANTIC_OPTIONAL_TYPE = 'SemanticOptionalType',
SEMANTIC_NULLABLE_TYPE = 'SemanticNullableType',

/** Type System Definitions */
SCHEMA_DEFINITION = 'SchemaDefinition',
Expand Down
6 changes: 3 additions & 3 deletions src/language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import type {
SelectionNode,
SelectionSetNode,
SemanticNonNullTypeNode,
SemanticOptionalTypeNode,
SemanticNullableTypeNode,
StringValueNode,
Token,
TypeNode,
Expand Down Expand Up @@ -775,8 +775,8 @@ export class Parser {
type,
});
} else if (this.expectOptionalToken(TokenKind.QUESTION_MARK)) {
return this.node<SemanticOptionalTypeNode>(start, {
kind: Kind.SEMANTIC_OPTIONAL_TYPE,
return this.node<SemanticNullableTypeNode>(start, {
kind: Kind.SEMANTIC_NULLABLE_TYPE,
type,
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/language/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const printDocASTReducer: ASTReducer<string> = {
ListType: { leave: ({ type }) => '[' + type + ']' },
NonNullType: { leave: ({ type }) => type + '!' },
SemanticNonNullType: { leave: ({ type }) => type },
SemanticOptionalType: { leave: ({ type }) => type + '?' },
SemanticNullableType: { leave: ({ type }) => type + '?' },

// Type System Definitions

Expand Down
36 changes: 18 additions & 18 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type GraphQLType =
| GraphQLInputObjectType
| GraphQLList<GraphQLType>
>
| GraphQLSemanticOptional<
| GraphQLSemanticNullable<
| GraphQLScalarType
| GraphQLObjectType
| GraphQLInterfaceType
Expand Down Expand Up @@ -248,25 +248,25 @@ export function assertSemanticNonNullType(
return type;
}

export function isSemanticOptionalType(
export function isSemanticNullableType(
type: GraphQLInputType,
): type is GraphQLSemanticOptional<GraphQLInputType>;
export function isSemanticOptionalType(
): type is GraphQLSemanticNullable<GraphQLInputType>;
export function isSemanticNullableType(
type: GraphQLOutputType,
): type is GraphQLSemanticOptional<GraphQLOutputType>;
export function isSemanticOptionalType(
): type is GraphQLSemanticNullable<GraphQLOutputType>;
export function isSemanticNullableType(
type: unknown,
): type is GraphQLSemanticOptional<GraphQLType>;
export function isSemanticOptionalType(
): type is GraphQLSemanticNullable<GraphQLType>;
export function isSemanticNullableType(
type: unknown,
): type is GraphQLSemanticOptional<GraphQLType> {
return instanceOf(type, GraphQLSemanticOptional);
): type is GraphQLSemanticNullable<GraphQLType> {
return instanceOf(type, GraphQLSemanticNullable);
}

export function assertSemanticOptionalType(
export function assertSemanticNullableType(
type: unknown,
): GraphQLSemanticOptional<GraphQLType> {
if (!isSemanticOptionalType(type)) {
): GraphQLSemanticNullable<GraphQLType> {
if (!isSemanticNullableType(type)) {
throw new Error(
`Expected ${inspect(type)} to be a GraphQL Semantic-Non-Null type.`,
);
Expand Down Expand Up @@ -546,7 +546,7 @@ export class GraphQLSemanticNonNull<T extends GraphQLNullableType> {
}

/**
* Semantic-Non-Null Type Wrapper
* Semantic-Nullable Type Wrapper
*
* A semantic-non-null is a wrapping type which points to another type.
* Semantic-non-null types enforce that their values are never null unless
Expand All @@ -569,7 +569,7 @@ export class GraphQLSemanticNonNull<T extends GraphQLNullableType> {
*
* @experimental
*/
export class GraphQLSemanticOptional<T extends GraphQLNullableType> {
export class GraphQLSemanticNullable<T extends GraphQLNullableType> {
readonly ofType: T;

constructor(ofType: T) {
Expand All @@ -582,7 +582,7 @@ export class GraphQLSemanticOptional<T extends GraphQLNullableType> {
}

get [Symbol.toStringTag]() {
return 'GraphQLSemanticOptional';
return 'GraphQLSemanticNullable';
}

toString(): string {
Expand All @@ -602,10 +602,10 @@ export type GraphQLWrappingType =
| GraphQLList<GraphQLType>
| GraphQLNonNull<GraphQLType>
| GraphQLSemanticNonNull<GraphQLType>
| GraphQLSemanticOptional<GraphQLType>;
| GraphQLSemanticNullable<GraphQLType>;

export function isWrappingType(type: unknown): type is GraphQLWrappingType {
return isListType(type) || isNonNullType(type) || isSemanticNonNullType(type) || isSemanticOptionalType(type);
return isListType(type) || isNonNullType(type) || isSemanticNonNullType(type) || isSemanticNullableType(type);
}

export function assertWrappingType(type: unknown): GraphQLWrappingType {
Expand Down

0 comments on commit 24474fa

Please sign in to comment.