diff --git a/src/execution/execute.js b/src/execution/execute.js index 72dbcec6cc..af9163aa9d 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -33,7 +33,6 @@ import { isListType, isNonNullType, } from '../type/definition'; -import type { GraphQLList } from '../type/wrappers'; import type { GraphQLObjectType, GraphQLOutputType, @@ -43,6 +42,7 @@ import type { GraphQLFieldResolver, GraphQLResolveInfo, ResponsePath, + GraphQLList, } from '../type/definition'; import { GraphQLSchema } from '../type/schema'; import { diff --git a/src/type/__tests__/schema-test.js b/src/type/__tests__/schema-test.js index 6e37a63301..1f8a5563e1 100644 --- a/src/type/__tests__/schema-test.js +++ b/src/type/__tests__/schema-test.js @@ -12,11 +12,11 @@ import { GraphQLString, GraphQLInputObjectType, GraphQLDirective, + GraphQLList, } from '../'; import { describe, it } from 'mocha'; import { expect } from 'chai'; -import { GraphQLList } from '../wrappers'; const InterfaceType = new GraphQLInterfaceType({ name: 'Interface', diff --git a/src/type/definition.js b/src/type/definition.js index 428304f71d..c1385da4c6 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -32,7 +32,6 @@ import type { } from '../language/ast'; import type { GraphQLSchema } from './schema'; import type { MaybePromise } from '../jsutils/MaybePromise'; -import { GraphQLList, GraphQLNonNull } from './wrappers'; // Predicates & Assertions @@ -315,6 +314,86 @@ export function assertAbstractType(type: mixed): GraphQLAbstractType { return type; } +/** + * List Type Wrapper + * + * A list is a wrapping type which points to another type. + * Lists are often created within the context of defining the fields of + * an object type. + * + * Example: + * + * const PersonType = new GraphQLObjectType({ + * name: 'Person', + * fields: () => ({ + * parents: { type: GraphQLList(PersonType) }, + * children: { type: GraphQLList(PersonType) }, + * }) + * }) + * + */ +declare class GraphQLList<+T: GraphQLType> { + +ofType: T; + static (ofType: T): GraphQLList; + // Note: constructors cannot be used for covariant types. Drop the "new". + constructor(ofType: any): void; +} +// eslint-disable-next-line no-redeclare +export function GraphQLList(ofType) { + if (this instanceof GraphQLList) { + this.ofType = assertType(ofType); + } else { + return new GraphQLList(ofType); + } +} + +// Also provide toJSON and inspect aliases for toString. +const listProto: any = GraphQLList.prototype; +listProto.toString = listProto.toJSON = listProto.inspect = function toString() { + return '[' + String(this.ofType) + ']'; +}; + +/** + * Non-Null Type Wrapper + * + * A non-null is a wrapping type which points to another type. + * Non-null types enforce that their values are never null and can ensure + * an error is raised if this ever occurs during a request. It is useful for + * fields which you can make a strong guarantee on non-nullability, for example + * usually the id field of a database row will never be null. + * + * Example: + * + * const RowType = new GraphQLObjectType({ + * name: 'Row', + * fields: () => ({ + * id: { type: GraphQLNonNull(GraphQLString) }, + * }) + * }) + * + * Note: the enforcement of non-nullability occurs within the executor. + */ +declare class GraphQLNonNull<+T: GraphQLNullableType> { + +ofType: T; + static (ofType: T): GraphQLNonNull; + // Note: constructors cannot be used for covariant types. Drop the "new". + constructor(ofType: any): void; +} +// eslint-disable-next-line no-redeclare +export function GraphQLNonNull(ofType) { + if (this instanceof GraphQLNonNull) { + this.ofType = assertNullableType(ofType); + } else { + return new GraphQLNonNull(ofType); + } +} + +// Also provide toJSON and inspect aliases for toString. +const nonNullProto: any = GraphQLNonNull.prototype; +nonNullProto.toString = nonNullProto.toJSON = nonNullProto.inspect = function toString() { + return String(this.ofType) + '!'; +}; + /** * These types wrap and modify other types */ diff --git a/src/type/directives.js b/src/type/directives.js index aa8a734cce..9d4d7764f8 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -11,7 +11,7 @@ import type { GraphQLFieldConfigArgumentMap, GraphQLArgument, } from './definition'; -import { GraphQLNonNull } from './wrappers'; +import { GraphQLNonNull } from './definition'; import { GraphQLString, GraphQLBoolean } from './scalars'; import instanceOf from '../jsutils/instanceOf'; import invariant from '../jsutils/invariant'; diff --git a/src/type/index.js b/src/type/index.js index 1f23b363ac..f7ac4fd8cd 100644 --- a/src/type/index.js +++ b/src/type/index.js @@ -63,13 +63,10 @@ export { GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, -} from './definition'; - -export { // Type Wrappers GraphQLList, GraphQLNonNull, -} from './wrappers'; +} from './definition'; export { // Predicate diff --git a/src/type/introspection.js b/src/type/introspection.js index 41bbbb53fd..a4810c6b63 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -14,6 +14,8 @@ import { print } from '../language/printer'; import { GraphQLObjectType, GraphQLEnumType, + GraphQLList, + GraphQLNonNull, isScalarType, isObjectType, isInterfaceType, @@ -25,7 +27,6 @@ import { isAbstractType, isNamedType, } from './definition'; -import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; import { GraphQLString, GraphQLBoolean } from './scalars'; import { DirectiveLocation } from '../language/directiveLocation'; import type { GraphQLField } from './definition'; diff --git a/src/type/wrappers.js b/src/type/wrappers.js deleted file mode 100644 index 8ebec67729..0000000000 --- a/src/type/wrappers.js +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict - */ - -import { assertType, assertNullableType } from './definition'; -import type { GraphQLType, GraphQLNullableType } from './definition'; - -/** - * List Type Wrapper - * - * A list is a wrapping type which points to another type. - * Lists are often created within the context of defining the fields of - * an object type. - * - * Example: - * - * const PersonType = new GraphQLObjectType({ - * name: 'Person', - * fields: () => ({ - * parents: { type: GraphQLList(PersonType) }, - * children: { type: GraphQLList(PersonType) }, - * }) - * }) - * - */ -declare class GraphQLList<+T: GraphQLType> { - +ofType: T; - static (ofType: T): GraphQLList; - // Note: constructors cannot be used for covariant types. Drop the "new". - constructor(ofType: any): void; -} -// eslint-disable-next-line no-redeclare -export function GraphQLList(ofType) { - if (this instanceof GraphQLList) { - this.ofType = assertType(ofType); - } else { - return new GraphQLList(ofType); - } -} - -// Also provide toJSON and inspect aliases for toString. -const listProto: any = GraphQLList.prototype; -listProto.toString = listProto.toJSON = listProto.inspect = function toString() { - return '[' + String(this.ofType) + ']'; -}; - -/** - * Non-Null Type Wrapper - * - * A non-null is a wrapping type which points to another type. - * Non-null types enforce that their values are never null and can ensure - * an error is raised if this ever occurs during a request. It is useful for - * fields which you can make a strong guarantee on non-nullability, for example - * usually the id field of a database row will never be null. - * - * Example: - * - * const RowType = new GraphQLObjectType({ - * name: 'Row', - * fields: () => ({ - * id: { type: GraphQLNonNull(GraphQLString) }, - * }) - * }) - * - * Note: the enforcement of non-nullability occurs within the executor. - */ -declare class GraphQLNonNull<+T: GraphQLNullableType> { - +ofType: T; - static (ofType: T): GraphQLNonNull; - // Note: constructors cannot be used for covariant types. Drop the "new". - constructor(ofType: any): void; -} -// eslint-disable-next-line no-redeclare -export function GraphQLNonNull(ofType) { - if (this instanceof GraphQLNonNull) { - this.ofType = assertNullableType(ofType); - } else { - return new GraphQLNonNull(ofType); - } -} - -// Also provide toJSON and inspect aliases for toString. -const nonNullProto: any = GraphQLNonNull.prototype; -nonNullProto.toString = nonNullProto.toJSON = nonNullProto.inspect = function toString() { - return String(this.ofType) + '!'; -}; diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index c28da3aea3..2ff2f7dd1d 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -49,10 +49,10 @@ import { GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, + GraphQLList, + GraphQLNonNull, } from '../type/definition'; -import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; - import { GraphQLDirective, GraphQLSkipDirective, diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index 3dddb07d50..b86b9bff40 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -25,13 +25,13 @@ import { GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, + GraphQLList, + GraphQLNonNull, assertNullableType, assertObjectType, assertInterfaceType, } from '../type/definition'; -import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; - import type { GraphQLType, GraphQLInputType, diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 3c1a57aa7f..cab1321acb 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -23,11 +23,12 @@ import { isUnionType, isListType, isNonNullType, + GraphQLList, + GraphQLNonNull, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, } from '../type/definition'; -import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; import { GraphQLDirective } from '../type/directives'; diff --git a/src/utilities/lexicographicSortSchema.js b/src/utilities/lexicographicSortSchema.js index 8593d24d7c..570d3e45f9 100644 --- a/src/utilities/lexicographicSortSchema.js +++ b/src/utilities/lexicographicSortSchema.js @@ -12,7 +12,6 @@ import keyValMap from '../jsutils/keyValMap'; import objectValues from '../jsutils/objectValues'; import { GraphQLSchema } from '../type/schema'; import { GraphQLDirective } from '../type/directives'; -import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; import type { GraphQLNamedType } from '../type/definition'; import { GraphQLObjectType, @@ -20,6 +19,8 @@ import { GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, + GraphQLList, + GraphQLNonNull, isListType, isNonNullType, isScalarType, diff --git a/src/utilities/typeFromAST.js b/src/utilities/typeFromAST.js index 07a25fd02b..596e16f9d4 100644 --- a/src/utilities/typeFromAST.js +++ b/src/utilities/typeFromAST.js @@ -13,7 +13,7 @@ import type { ListTypeNode, NonNullTypeNode, } from '../language/ast'; -import { GraphQLList, GraphQLNonNull } from '../type/wrappers'; +import { GraphQLList, GraphQLNonNull } from '../type/definition'; import type { GraphQLNamedType } from '../type/definition'; import type { GraphQLSchema } from '../type/schema'; diff --git a/src/validation/rules/VariablesInAllowedPosition.js b/src/validation/rules/VariablesInAllowedPosition.js index 47073e5757..25a95f5943 100644 --- a/src/validation/rules/VariablesInAllowedPosition.js +++ b/src/validation/rules/VariablesInAllowedPosition.js @@ -10,8 +10,7 @@ import type ValidationContext from '../ValidationContext'; import { GraphQLError } from '../../error'; import type { ASTVisitor } from '../../language/visitor'; -import { isNonNullType } from '../../type/definition'; -import { GraphQLNonNull } from '../../type/wrappers'; +import { GraphQLNonNull, isNonNullType } from '../../type/definition'; import { isTypeSubTypeOf } from '../../utilities/typeComparators'; import { typeFromAST } from '../../utilities/typeFromAST'; import type { GraphQLType } from '../../type/definition';