graphql 16.14.0 → 16.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/error/GraphQLError.d.ts +151 -15
- package/error/GraphQLError.js +143 -12
- package/error/GraphQLError.mjs +143 -12
- package/error/index.d.ts +6 -0
- package/error/index.mjs +6 -0
- package/error/locatedError.d.ts +20 -0
- package/error/locatedError.js +21 -0
- package/error/locatedError.mjs +20 -0
- package/error/syntaxError.d.ts +15 -0
- package/error/syntaxError.js +16 -0
- package/error/syntaxError.mjs +15 -0
- package/execution/collectFields.js +6 -0
- package/execution/collectFields.mjs +6 -0
- package/execution/execute.d.ts +211 -12
- package/execution/execute.js +214 -23
- package/execution/execute.mjs +213 -23
- package/execution/index.d.ts +6 -0
- package/execution/index.mjs +6 -0
- package/execution/mapAsyncIterator.d.ts +2 -0
- package/execution/mapAsyncIterator.js +2 -0
- package/execution/mapAsyncIterator.mjs +2 -0
- package/execution/subscribe.d.ts +195 -5
- package/execution/subscribe.js +154 -11
- package/execution/subscribe.mjs +153 -11
- package/execution/values.d.ts +167 -10
- package/execution/values.js +149 -5
- package/execution/values.mjs +148 -5
- package/graphql.d.ts +163 -41
- package/graphql.js +126 -4
- package/graphql.mjs +131 -41
- package/index.d.ts +11 -17
- package/index.mjs +13 -19
- package/jsutils/Maybe.d.ts +5 -1
- package/jsutils/ObjMap.d.ts +4 -0
- package/jsutils/Path.d.ts +30 -0
- package/jsutils/Path.js +29 -0
- package/jsutils/Path.mjs +29 -0
- package/jsutils/PromiseOrValue.d.ts +1 -0
- package/jsutils/devAssert.d.ts +1 -0
- package/jsutils/devAssert.js +1 -0
- package/jsutils/devAssert.mjs +1 -0
- package/jsutils/didYouMean.d.ts +4 -1
- package/jsutils/didYouMean.js +4 -1
- package/jsutils/didYouMean.mjs +4 -1
- package/jsutils/groupBy.d.ts +2 -0
- package/jsutils/groupBy.js +2 -0
- package/jsutils/groupBy.mjs +2 -0
- package/jsutils/identityFunc.d.ts +2 -0
- package/jsutils/identityFunc.js +2 -0
- package/jsutils/identityFunc.mjs +2 -0
- package/jsutils/inspect.d.ts +2 -0
- package/jsutils/inspect.js +2 -0
- package/jsutils/inspect.mjs +2 -0
- package/jsutils/instanceOf.d.ts +2 -0
- package/jsutils/instanceOf.js +2 -0
- package/jsutils/instanceOf.mjs +2 -0
- package/jsutils/invariant.d.ts +1 -0
- package/jsutils/invariant.js +1 -0
- package/jsutils/invariant.mjs +1 -0
- package/jsutils/isAsyncIterable.d.ts +2 -0
- package/jsutils/isAsyncIterable.js +2 -0
- package/jsutils/isAsyncIterable.mjs +2 -0
- package/jsutils/isIterableObject.d.ts +6 -5
- package/jsutils/isIterableObject.js +6 -5
- package/jsutils/isIterableObject.mjs +6 -5
- package/jsutils/isObjectLike.d.ts +2 -0
- package/jsutils/isObjectLike.js +2 -0
- package/jsutils/isObjectLike.mjs +2 -0
- package/jsutils/isPromise.d.ts +2 -0
- package/jsutils/isPromise.js +2 -0
- package/jsutils/isPromise.mjs +2 -0
- package/jsutils/keyMap.d.ts +7 -14
- package/jsutils/keyMap.js +7 -14
- package/jsutils/keyMap.mjs +7 -14
- package/jsutils/keyValMap.d.ts +9 -6
- package/jsutils/keyValMap.js +9 -6
- package/jsutils/keyValMap.mjs +9 -6
- package/jsutils/mapValue.d.ts +2 -0
- package/jsutils/mapValue.js +2 -0
- package/jsutils/mapValue.mjs +2 -0
- package/jsutils/memoize3.d.ts +2 -0
- package/jsutils/memoize3.js +2 -0
- package/jsutils/memoize3.mjs +2 -0
- package/jsutils/naturalCompare.d.ts +2 -0
- package/jsutils/naturalCompare.js +2 -0
- package/jsutils/naturalCompare.mjs +2 -0
- package/jsutils/printPathArray.d.ts +2 -0
- package/jsutils/printPathArray.js +2 -0
- package/jsutils/printPathArray.mjs +2 -0
- package/jsutils/promiseForObject.d.ts +2 -0
- package/jsutils/promiseForObject.js +2 -0
- package/jsutils/promiseForObject.mjs +2 -0
- package/jsutils/promiseReduce.d.ts +2 -0
- package/jsutils/promiseReduce.js +2 -0
- package/jsutils/promiseReduce.mjs +2 -0
- package/jsutils/suggestionList.d.ts +2 -0
- package/jsutils/suggestionList.js +4 -0
- package/jsutils/suggestionList.mjs +4 -0
- package/jsutils/toError.d.ts +2 -0
- package/jsutils/toError.js +2 -0
- package/jsutils/toError.mjs +2 -0
- package/jsutils/toObjMap.d.ts +1 -0
- package/jsutils/toObjMap.js +1 -0
- package/jsutils/toObjMap.mjs +1 -0
- package/language/ast.d.ts +412 -54
- package/language/ast.js +95 -38
- package/language/ast.mjs +95 -38
- package/language/blockString.d.ts +1 -3
- package/language/blockString.js +1 -3
- package/language/blockString.mjs +1 -3
- package/language/directiveLocation.d.ts +28 -8
- package/language/directiveLocation.js +9 -6
- package/language/directiveLocation.mjs +9 -6
- package/language/index.d.ts +6 -0
- package/language/index.mjs +6 -0
- package/language/kinds.d.ts +57 -18
- package/language/kinds.js +9 -6
- package/language/kinds.mjs +9 -6
- package/language/lexer.d.ts +47 -14
- package/language/lexer.js +71 -13
- package/language/lexer.mjs +70 -13
- package/language/location.d.ts +16 -3
- package/language/location.js +14 -3
- package/language/location.mjs +14 -3
- package/language/parser.d.ts +236 -13
- package/language/parser.js +224 -0
- package/language/parser.mjs +224 -3
- package/language/predicates.d.ts +169 -0
- package/language/predicates.js +170 -0
- package/language/predicates.mjs +180 -0
- package/language/printLocation.d.ts +28 -0
- package/language/printLocation.js +29 -0
- package/language/printLocation.mjs +28 -0
- package/language/printString.d.ts +2 -0
- package/language/printString.js +5 -1
- package/language/printString.mjs +5 -1
- package/language/printer.d.ts +12 -0
- package/language/printer.js +19 -0
- package/language/printer.mjs +18 -0
- package/language/schemaCoordinateLexer.d.ts +8 -6
- package/language/schemaCoordinateLexer.js +10 -6
- package/language/schemaCoordinateLexer.mjs +10 -6
- package/language/source.d.ts +28 -0
- package/language/source.js +32 -0
- package/language/source.mjs +31 -0
- package/language/tokenKind.d.ts +30 -3
- package/language/tokenKind.js +8 -3
- package/language/tokenKind.mjs +8 -3
- package/language/visitor.d.ts +200 -72
- package/language/visitor.js +122 -50
- package/language/visitor.mjs +122 -54
- package/package.json +1 -1
- package/subscription/index.d.ts +9 -3
- package/subscription/index.mjs +9 -3
- package/type/assertName.d.ts +18 -1
- package/type/assertName.js +19 -1
- package/type/assertName.mjs +18 -1
- package/type/definition.d.ts +2540 -79
- package/type/definition.js +2214 -61
- package/type/definition.mjs +2241 -60
- package/type/directives.d.ts +193 -18
- package/type/directives.js +196 -19
- package/type/directives.mjs +196 -19
- package/type/index.d.ts +6 -0
- package/type/index.mjs +6 -0
- package/type/introspection.d.ts +36 -0
- package/type/introspection.js +33 -0
- package/type/introspection.mjs +41 -0
- package/type/scalars.d.ts +29 -2
- package/type/scalars.js +37 -2
- package/type/scalars.mjs +36 -2
- package/type/schema.d.ts +490 -28
- package/type/schema.js +484 -26
- package/type/schema.mjs +484 -26
- package/type/validate.d.ts +31 -0
- package/type/validate.js +32 -0
- package/type/validate.mjs +31 -0
- package/utilities/TypeInfo.d.ts +441 -1
- package/utilities/TypeInfo.js +444 -1
- package/utilities/TypeInfo.mjs +443 -1
- package/utilities/assertValidName.d.ts +27 -2
- package/utilities/assertValidName.js +28 -2
- package/utilities/assertValidName.mjs +27 -2
- package/utilities/astFromValue.d.ts +33 -3
- package/utilities/astFromValue.js +36 -3
- package/utilities/astFromValue.mjs +35 -3
- package/utilities/buildASTSchema.d.ts +65 -6
- package/utilities/buildASTSchema.js +65 -6
- package/utilities/buildASTSchema.mjs +65 -6
- package/utilities/buildClientSchema.d.ts +15 -0
- package/utilities/buildClientSchema.js +16 -0
- package/utilities/buildClientSchema.mjs +15 -0
- package/utilities/coerceInputValue.d.ts +46 -0
- package/utilities/coerceInputValue.js +47 -0
- package/utilities/coerceInputValue.mjs +46 -0
- package/utilities/concatAST.d.ts +12 -0
- package/utilities/concatAST.js +13 -0
- package/utilities/concatAST.mjs +12 -0
- package/utilities/extendSchema.d.ts +56 -3
- package/utilities/extendSchema.js +63 -3
- package/utilities/extendSchema.mjs +62 -3
- package/utilities/findBreakingChanges.d.ts +95 -0
- package/utilities/findBreakingChanges.js +68 -0
- package/utilities/findBreakingChanges.mjs +70 -0
- package/utilities/getIntrospectionQuery.d.ts +132 -0
- package/utilities/getIntrospectionQuery.js +41 -0
- package/utilities/getIntrospectionQuery.mjs +41 -0
- package/utilities/getOperationAST.d.ts +15 -0
- package/utilities/getOperationAST.js +16 -0
- package/utilities/getOperationAST.mjs +15 -0
- package/utilities/getOperationRootType.d.ts +18 -1
- package/utilities/getOperationRootType.js +19 -1
- package/utilities/getOperationRootType.mjs +18 -1
- package/utilities/index.d.ts +7 -0
- package/utilities/index.mjs +7 -0
- package/utilities/introspectionFromSchema.d.ts +54 -0
- package/utilities/introspectionFromSchema.js +55 -0
- package/utilities/introspectionFromSchema.mjs +54 -0
- package/utilities/lexicographicSortSchema.d.ts +35 -0
- package/utilities/lexicographicSortSchema.js +36 -0
- package/utilities/lexicographicSortSchema.mjs +35 -0
- package/utilities/printSchema.d.ts +63 -0
- package/utilities/printSchema.js +66 -0
- package/utilities/printSchema.mjs +67 -0
- package/utilities/resolveSchemaCoordinate.d.ts +62 -0
- package/utilities/resolveSchemaCoordinate.js +64 -0
- package/utilities/resolveSchemaCoordinate.mjs +63 -0
- package/utilities/separateOperations.d.ts +30 -0
- package/utilities/separateOperations.js +31 -0
- package/utilities/separateOperations.mjs +30 -0
- package/utilities/stripIgnoredCharacters.d.ts +13 -6
- package/utilities/stripIgnoredCharacters.js +16 -6
- package/utilities/stripIgnoredCharacters.mjs +15 -6
- package/utilities/typeComparators.d.ts +84 -0
- package/utilities/typeComparators.js +85 -0
- package/utilities/typeComparators.mjs +84 -0
- package/utilities/typeFromAST.d.ts +86 -0
- package/utilities/typeFromAST.js +3 -0
- package/utilities/typeFromAST.mjs +3 -0
- package/utilities/typedQueryDocumentNode.d.ts +4 -0
- package/utilities/valueFromAST.d.ts +38 -0
- package/utilities/valueFromAST.js +39 -0
- package/utilities/valueFromAST.mjs +38 -0
- package/utilities/valueFromASTUntyped.d.ts +15 -2
- package/utilities/valueFromASTUntyped.js +16 -2
- package/utilities/valueFromASTUntyped.mjs +15 -2
- package/validation/ValidationContext.d.ts +399 -0
- package/validation/ValidationContext.js +400 -0
- package/validation/ValidationContext.mjs +401 -0
- package/validation/index.d.ts +6 -0
- package/validation/index.mjs +6 -0
- package/validation/rules/ExecutableDefinitionsRule.d.ts +28 -0
- package/validation/rules/ExecutableDefinitionsRule.js +29 -0
- package/validation/rules/ExecutableDefinitionsRule.mjs +28 -0
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +28 -0
- package/validation/rules/FieldsOnCorrectTypeRule.js +33 -0
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +32 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +28 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.js +29 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs +28 -0
- package/validation/rules/KnownArgumentNamesRule.d.ts +29 -3
- package/validation/rules/KnownArgumentNamesRule.js +30 -3
- package/validation/rules/KnownArgumentNamesRule.mjs +29 -3
- package/validation/rules/KnownDirectivesRule.d.ts +28 -0
- package/validation/rules/KnownDirectivesRule.js +29 -0
- package/validation/rules/KnownDirectivesRule.mjs +28 -0
- package/validation/rules/KnownFragmentNamesRule.d.ts +28 -0
- package/validation/rules/KnownFragmentNamesRule.js +29 -0
- package/validation/rules/KnownFragmentNamesRule.mjs +28 -0
- package/validation/rules/KnownTypeNamesRule.d.ts +28 -0
- package/validation/rules/KnownTypeNamesRule.js +29 -0
- package/validation/rules/KnownTypeNamesRule.mjs +28 -0
- package/validation/rules/LoneAnonymousOperationRule.d.ts +28 -0
- package/validation/rules/LoneAnonymousOperationRule.js +29 -0
- package/validation/rules/LoneAnonymousOperationRule.mjs +28 -0
- package/validation/rules/LoneSchemaDefinitionRule.d.ts +21 -0
- package/validation/rules/LoneSchemaDefinitionRule.js +22 -0
- package/validation/rules/LoneSchemaDefinitionRule.mjs +21 -0
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +31 -0
- package/validation/rules/MaxIntrospectionDepthRule.js +33 -0
- package/validation/rules/MaxIntrospectionDepthRule.mjs +34 -0
- package/validation/rules/NoFragmentCyclesRule.d.ts +28 -0
- package/validation/rules/NoFragmentCyclesRule.js +29 -0
- package/validation/rules/NoFragmentCyclesRule.mjs +28 -0
- package/validation/rules/NoUndefinedVariablesRule.d.ts +28 -0
- package/validation/rules/NoUndefinedVariablesRule.js +29 -0
- package/validation/rules/NoUndefinedVariablesRule.mjs +28 -0
- package/validation/rules/NoUnusedFragmentsRule.d.ts +28 -0
- package/validation/rules/NoUnusedFragmentsRule.js +29 -0
- package/validation/rules/NoUnusedFragmentsRule.mjs +28 -0
- package/validation/rules/NoUnusedVariablesRule.d.ts +29 -0
- package/validation/rules/NoUnusedVariablesRule.js +30 -0
- package/validation/rules/NoUnusedVariablesRule.mjs +29 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +33 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +45 -6
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +45 -6
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +36 -0
- package/validation/rules/PossibleFragmentSpreadsRule.js +37 -0
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +36 -0
- package/validation/rules/PossibleTypeExtensionsRule.d.ts +21 -0
- package/validation/rules/PossibleTypeExtensionsRule.js +22 -0
- package/validation/rules/PossibleTypeExtensionsRule.mjs +21 -0
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +29 -3
- package/validation/rules/ProvidedRequiredArgumentsRule.js +30 -3
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +29 -3
- package/validation/rules/ScalarLeafsRule.d.ts +28 -0
- package/validation/rules/ScalarLeafsRule.js +29 -0
- package/validation/rules/ScalarLeafsRule.mjs +28 -0
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +33 -0
- package/validation/rules/SingleFieldSubscriptionsRule.js +34 -0
- package/validation/rules/SingleFieldSubscriptionsRule.mjs +33 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.d.ts +21 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.js +22 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +21 -0
- package/validation/rules/UniqueArgumentNamesRule.d.ts +28 -0
- package/validation/rules/UniqueArgumentNamesRule.js +29 -0
- package/validation/rules/UniqueArgumentNamesRule.mjs +28 -0
- package/validation/rules/UniqueDirectiveNamesRule.d.ts +21 -0
- package/validation/rules/UniqueDirectiveNamesRule.js +22 -0
- package/validation/rules/UniqueDirectiveNamesRule.mjs +21 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +28 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.js +29 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs +28 -0
- package/validation/rules/UniqueEnumValueNamesRule.d.ts +21 -0
- package/validation/rules/UniqueEnumValueNamesRule.js +22 -0
- package/validation/rules/UniqueEnumValueNamesRule.mjs +21 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.d.ts +21 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +22 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +21 -0
- package/validation/rules/UniqueFragmentNamesRule.d.ts +28 -0
- package/validation/rules/UniqueFragmentNamesRule.js +29 -0
- package/validation/rules/UniqueFragmentNamesRule.mjs +28 -0
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +32 -0
- package/validation/rules/UniqueInputFieldNamesRule.js +33 -0
- package/validation/rules/UniqueInputFieldNamesRule.mjs +32 -0
- package/validation/rules/UniqueOperationNamesRule.d.ts +28 -0
- package/validation/rules/UniqueOperationNamesRule.js +29 -0
- package/validation/rules/UniqueOperationNamesRule.mjs +28 -0
- package/validation/rules/UniqueOperationTypesRule.d.ts +21 -0
- package/validation/rules/UniqueOperationTypesRule.js +22 -0
- package/validation/rules/UniqueOperationTypesRule.mjs +21 -0
- package/validation/rules/UniqueTypeNamesRule.d.ts +21 -0
- package/validation/rules/UniqueTypeNamesRule.js +22 -0
- package/validation/rules/UniqueTypeNamesRule.mjs +21 -0
- package/validation/rules/UniqueVariableNamesRule.d.ts +28 -0
- package/validation/rules/UniqueVariableNamesRule.js +29 -0
- package/validation/rules/UniqueVariableNamesRule.mjs +28 -0
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +28 -0
- package/validation/rules/ValuesOfCorrectTypeRule.js +31 -0
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +30 -0
- package/validation/rules/VariablesAreInputTypesRule.d.ts +32 -0
- package/validation/rules/VariablesAreInputTypesRule.js +33 -0
- package/validation/rules/VariablesAreInputTypesRule.mjs +32 -0
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +28 -0
- package/validation/rules/VariablesInAllowedPositionRule.js +35 -1
- package/validation/rules/VariablesInAllowedPositionRule.mjs +34 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +41 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.js +42 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +41 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +28 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +29 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +28 -0
- package/validation/specifiedRules.d.ts +2 -3
- package/validation/specifiedRules.js +2 -3
- package/validation/specifiedRules.mjs +2 -3
- package/validation/validate.d.ts +70 -9
- package/validation/validate.js +63 -7
- package/validation/validate.mjs +63 -7
- package/version.d.ts +3 -6
- package/version.js +6 -8
- package/version.mjs +5 -8
package/type/definition.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @category Types */
|
|
1
2
|
import { devAssert } from '../jsutils/devAssert.mjs';
|
|
2
3
|
import { didYouMean } from '../jsutils/didYouMean.mjs';
|
|
3
4
|
import { identityFunc } from '../jsutils/identityFunc.mjs';
|
|
@@ -14,6 +15,28 @@ import { Kind } from '../language/kinds.mjs';
|
|
|
14
15
|
import { print } from '../language/printer.mjs';
|
|
15
16
|
import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped.mjs';
|
|
16
17
|
import { assertEnumValueName, assertName } from './assertName.mjs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns true when the value is any GraphQL type.
|
|
21
|
+
* @param type - The GraphQL type to inspect.
|
|
22
|
+
* @returns True when the value is any GraphQL type.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
26
|
+
* import { GraphQLList, GraphQLString, isType } from 'graphql/type';
|
|
27
|
+
*
|
|
28
|
+
* const schema = buildSchema(`
|
|
29
|
+
* type Query {
|
|
30
|
+
* name: String
|
|
31
|
+
* }
|
|
32
|
+
* `);
|
|
33
|
+
*
|
|
34
|
+
* isType(GraphQLString); // => true
|
|
35
|
+
* isType(new GraphQLList(GraphQLString)); // => true
|
|
36
|
+
* isType(schema.getType('Query')); // => true
|
|
37
|
+
* isType('String'); // => false
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
17
40
|
export function isType(type) {
|
|
18
41
|
return (
|
|
19
42
|
isScalarType(type) ||
|
|
@@ -26,6 +49,28 @@ export function isType(type) {
|
|
|
26
49
|
isNonNullType(type)
|
|
27
50
|
);
|
|
28
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns the value as a GraphQL type, or throws if it is not one.
|
|
54
|
+
* @param type - The GraphQL type to inspect.
|
|
55
|
+
* @returns The value typed as a GraphQL type.
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
59
|
+
* import { assertType } from 'graphql/type';
|
|
60
|
+
*
|
|
61
|
+
* const schema = buildSchema(`
|
|
62
|
+
* type Query {
|
|
63
|
+
* name: String
|
|
64
|
+
* }
|
|
65
|
+
* `);
|
|
66
|
+
*
|
|
67
|
+
* const queryType = assertType(schema.getType('Query'));
|
|
68
|
+
*
|
|
69
|
+
* queryType.toString(); // => 'Query'
|
|
70
|
+
* assertType('Query'); // throws an error
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
|
|
29
74
|
export function assertType(type) {
|
|
30
75
|
if (!isType(type)) {
|
|
31
76
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL type.`);
|
|
@@ -35,11 +80,53 @@ export function assertType(type) {
|
|
|
35
80
|
}
|
|
36
81
|
/**
|
|
37
82
|
* There are predicates for each kind of GraphQL type.
|
|
83
|
+
* @param type - The GraphQL type to inspect.
|
|
84
|
+
* @returns True when the value is a GraphQLScalarType.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
88
|
+
* import { isScalarType } from 'graphql/type';
|
|
89
|
+
*
|
|
90
|
+
* const schema = buildSchema(`
|
|
91
|
+
* scalar DateTime
|
|
92
|
+
*
|
|
93
|
+
* type Query {
|
|
94
|
+
* createdAt: DateTime
|
|
95
|
+
* }
|
|
96
|
+
* `);
|
|
97
|
+
*
|
|
98
|
+
* isScalarType(schema.getType('DateTime')); // => true
|
|
99
|
+
* isScalarType(schema.getType('Query')); // => false
|
|
100
|
+
* ```
|
|
38
101
|
*/
|
|
39
102
|
|
|
40
103
|
export function isScalarType(type) {
|
|
41
104
|
return instanceOf(type, GraphQLScalarType);
|
|
42
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the value as a GraphQLScalarType, or throws if it is not one.
|
|
108
|
+
* @param type - The GraphQL type to inspect.
|
|
109
|
+
* @returns The value typed as a GraphQLScalarType.
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
113
|
+
* import { assertScalarType } from 'graphql/type';
|
|
114
|
+
*
|
|
115
|
+
* const schema = buildSchema(`
|
|
116
|
+
* scalar DateTime
|
|
117
|
+
*
|
|
118
|
+
* type Query {
|
|
119
|
+
* createdAt: DateTime
|
|
120
|
+
* }
|
|
121
|
+
* `);
|
|
122
|
+
*
|
|
123
|
+
* const dateTimeType = assertScalarType(schema.getType('DateTime'));
|
|
124
|
+
*
|
|
125
|
+
* dateTimeType.name; // => 'DateTime'
|
|
126
|
+
* assertScalarType(schema.getType('Query')); // throws an error
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
|
|
43
130
|
export function assertScalarType(type) {
|
|
44
131
|
if (!isScalarType(type)) {
|
|
45
132
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL Scalar type.`);
|
|
@@ -47,9 +134,67 @@ export function assertScalarType(type) {
|
|
|
47
134
|
|
|
48
135
|
return type;
|
|
49
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Returns true when the value is a GraphQLObjectType.
|
|
139
|
+
* @param type - The GraphQL type to inspect.
|
|
140
|
+
* @returns True when the value is a GraphQLObjectType.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
144
|
+
* import { isObjectType } from 'graphql/type';
|
|
145
|
+
*
|
|
146
|
+
* const schema = buildSchema(`
|
|
147
|
+
* input ReviewInput {
|
|
148
|
+
* stars: Int!
|
|
149
|
+
* }
|
|
150
|
+
*
|
|
151
|
+
* type User {
|
|
152
|
+
* name: String
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* type Query {
|
|
156
|
+
* user: User
|
|
157
|
+
* }
|
|
158
|
+
* `);
|
|
159
|
+
*
|
|
160
|
+
* isObjectType(schema.getType('User')); // => true
|
|
161
|
+
* isObjectType(schema.getType('ReviewInput')); // => false
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
|
|
50
165
|
export function isObjectType(type) {
|
|
51
166
|
return instanceOf(type, GraphQLObjectType);
|
|
52
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns the value as a GraphQLObjectType, or throws if it is not one.
|
|
170
|
+
* @param type - The GraphQL type to inspect.
|
|
171
|
+
* @returns The value typed as a GraphQLObjectType.
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
175
|
+
* import { assertObjectType } from 'graphql/type';
|
|
176
|
+
*
|
|
177
|
+
* const schema = buildSchema(`
|
|
178
|
+
* input ReviewInput {
|
|
179
|
+
* stars: Int!
|
|
180
|
+
* }
|
|
181
|
+
*
|
|
182
|
+
* type User {
|
|
183
|
+
* name: String
|
|
184
|
+
* }
|
|
185
|
+
*
|
|
186
|
+
* type Query {
|
|
187
|
+
* user: User
|
|
188
|
+
* }
|
|
189
|
+
* `);
|
|
190
|
+
*
|
|
191
|
+
* const userType = assertObjectType(schema.getType('User'));
|
|
192
|
+
*
|
|
193
|
+
* Object.keys(userType.getFields()); // => ['name']
|
|
194
|
+
* assertObjectType(schema.getType('ReviewInput')); // throws an error
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
|
|
53
198
|
export function assertObjectType(type) {
|
|
54
199
|
if (!isObjectType(type)) {
|
|
55
200
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL Object type.`);
|
|
@@ -57,9 +202,67 @@ export function assertObjectType(type) {
|
|
|
57
202
|
|
|
58
203
|
return type;
|
|
59
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Returns true when the value is a GraphQLInterfaceType.
|
|
207
|
+
* @param type - The GraphQL type to inspect.
|
|
208
|
+
* @returns True when the value is a GraphQLInterfaceType.
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
212
|
+
* import { isInterfaceType } from 'graphql/type';
|
|
213
|
+
*
|
|
214
|
+
* const schema = buildSchema(`
|
|
215
|
+
* interface Node {
|
|
216
|
+
* id: ID!
|
|
217
|
+
* }
|
|
218
|
+
*
|
|
219
|
+
* type User implements Node {
|
|
220
|
+
* id: ID!
|
|
221
|
+
* }
|
|
222
|
+
*
|
|
223
|
+
* type Query {
|
|
224
|
+
* node: Node
|
|
225
|
+
* }
|
|
226
|
+
* `);
|
|
227
|
+
*
|
|
228
|
+
* isInterfaceType(schema.getType('Node')); // => true
|
|
229
|
+
* isInterfaceType(schema.getType('User')); // => false
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
|
|
60
233
|
export function isInterfaceType(type) {
|
|
61
234
|
return instanceOf(type, GraphQLInterfaceType);
|
|
62
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns the value as a GraphQLInterfaceType, or throws if it is not one.
|
|
238
|
+
* @param type - The GraphQL type to inspect.
|
|
239
|
+
* @returns The value typed as a GraphQLInterfaceType.
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
243
|
+
* import { assertInterfaceType } from 'graphql/type';
|
|
244
|
+
*
|
|
245
|
+
* const schema = buildSchema(`
|
|
246
|
+
* interface Node {
|
|
247
|
+
* id: ID!
|
|
248
|
+
* }
|
|
249
|
+
*
|
|
250
|
+
* type User implements Node {
|
|
251
|
+
* id: ID!
|
|
252
|
+
* }
|
|
253
|
+
*
|
|
254
|
+
* type Query {
|
|
255
|
+
* node: Node
|
|
256
|
+
* }
|
|
257
|
+
* `);
|
|
258
|
+
*
|
|
259
|
+
* const nodeType = assertInterfaceType(schema.getType('Node'));
|
|
260
|
+
*
|
|
261
|
+
* nodeType.name; // => 'Node'
|
|
262
|
+
* assertInterfaceType(schema.getType('User')); // throws an error
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
|
|
63
266
|
export function assertInterfaceType(type) {
|
|
64
267
|
if (!isInterfaceType(type)) {
|
|
65
268
|
throw new Error(
|
|
@@ -69,9 +272,71 @@ export function assertInterfaceType(type) {
|
|
|
69
272
|
|
|
70
273
|
return type;
|
|
71
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Returns true when the value is a GraphQLUnionType.
|
|
277
|
+
* @param type - The GraphQL type to inspect.
|
|
278
|
+
* @returns True when the value is a GraphQLUnionType.
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
282
|
+
* import { isUnionType } from 'graphql/type';
|
|
283
|
+
*
|
|
284
|
+
* const schema = buildSchema(`
|
|
285
|
+
* type Photo {
|
|
286
|
+
* url: String!
|
|
287
|
+
* }
|
|
288
|
+
*
|
|
289
|
+
* type Video {
|
|
290
|
+
* url: String!
|
|
291
|
+
* }
|
|
292
|
+
*
|
|
293
|
+
* union Media = Photo | Video
|
|
294
|
+
*
|
|
295
|
+
* type Query {
|
|
296
|
+
* media: [Media]
|
|
297
|
+
* }
|
|
298
|
+
* `);
|
|
299
|
+
*
|
|
300
|
+
* isUnionType(schema.getType('Media')); // => true
|
|
301
|
+
* isUnionType(schema.getType('Photo')); // => false
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
|
|
72
305
|
export function isUnionType(type) {
|
|
73
306
|
return instanceOf(type, GraphQLUnionType);
|
|
74
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Returns the value as a GraphQLUnionType, or throws if it is not one.
|
|
310
|
+
* @param type - The GraphQL type to inspect.
|
|
311
|
+
* @returns The value typed as a GraphQLUnionType.
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
315
|
+
* import { assertUnionType } from 'graphql/type';
|
|
316
|
+
*
|
|
317
|
+
* const schema = buildSchema(`
|
|
318
|
+
* type Photo {
|
|
319
|
+
* url: String!
|
|
320
|
+
* }
|
|
321
|
+
*
|
|
322
|
+
* type Video {
|
|
323
|
+
* url: String!
|
|
324
|
+
* }
|
|
325
|
+
*
|
|
326
|
+
* union Media = Photo | Video
|
|
327
|
+
*
|
|
328
|
+
* type Query {
|
|
329
|
+
* media: [Media]
|
|
330
|
+
* }
|
|
331
|
+
* `);
|
|
332
|
+
*
|
|
333
|
+
* const mediaType = assertUnionType(schema.getType('Media'));
|
|
334
|
+
*
|
|
335
|
+
* mediaType.getTypes().map((type) => type.name); // => ['Photo', 'Video']
|
|
336
|
+
* assertUnionType(schema.getType('Photo')); // throws an error
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
|
|
75
340
|
export function assertUnionType(type) {
|
|
76
341
|
if (!isUnionType(type)) {
|
|
77
342
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL Union type.`);
|
|
@@ -79,9 +344,61 @@ export function assertUnionType(type) {
|
|
|
79
344
|
|
|
80
345
|
return type;
|
|
81
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Returns true when the value is a GraphQLEnumType.
|
|
349
|
+
* @param type - The GraphQL type to inspect.
|
|
350
|
+
* @returns True when the value is a GraphQLEnumType.
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
354
|
+
* import { isEnumType } from 'graphql/type';
|
|
355
|
+
*
|
|
356
|
+
* const schema = buildSchema(`
|
|
357
|
+
* enum Episode {
|
|
358
|
+
* NEW_HOPE
|
|
359
|
+
* EMPIRE
|
|
360
|
+
* }
|
|
361
|
+
*
|
|
362
|
+
* type Query {
|
|
363
|
+
* favoriteEpisode: Episode
|
|
364
|
+
* }
|
|
365
|
+
* `);
|
|
366
|
+
*
|
|
367
|
+
* isEnumType(schema.getType('Episode')); // => true
|
|
368
|
+
* isEnumType(schema.getType('Query')); // => false
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
|
|
82
372
|
export function isEnumType(type) {
|
|
83
373
|
return instanceOf(type, GraphQLEnumType);
|
|
84
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Returns the value as a GraphQLEnumType, or throws if it is not one.
|
|
377
|
+
* @param type - The GraphQL type to inspect.
|
|
378
|
+
* @returns The value typed as a GraphQLEnumType.
|
|
379
|
+
* @example
|
|
380
|
+
* ```ts
|
|
381
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
382
|
+
* import { assertEnumType } from 'graphql/type';
|
|
383
|
+
*
|
|
384
|
+
* const schema = buildSchema(`
|
|
385
|
+
* enum Episode {
|
|
386
|
+
* NEW_HOPE
|
|
387
|
+
* EMPIRE
|
|
388
|
+
* }
|
|
389
|
+
*
|
|
390
|
+
* type Query {
|
|
391
|
+
* favoriteEpisode: Episode
|
|
392
|
+
* }
|
|
393
|
+
* `);
|
|
394
|
+
*
|
|
395
|
+
* const episodeType = assertEnumType(schema.getType('Episode'));
|
|
396
|
+
*
|
|
397
|
+
* episodeType.getValues().map((value) => value.name); // => ['NEW_HOPE', 'EMPIRE']
|
|
398
|
+
* assertEnumType(schema.getType('Query')); // throws an error
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
|
|
85
402
|
export function assertEnumType(type) {
|
|
86
403
|
if (!isEnumType(type)) {
|
|
87
404
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL Enum type.`);
|
|
@@ -89,9 +406,67 @@ export function assertEnumType(type) {
|
|
|
89
406
|
|
|
90
407
|
return type;
|
|
91
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Returns true when the value is a GraphQLInputObjectType.
|
|
411
|
+
* @param type - The GraphQL type to inspect.
|
|
412
|
+
* @returns True when the value is a GraphQLInputObjectType.
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
416
|
+
* import { isInputObjectType } from 'graphql/type';
|
|
417
|
+
*
|
|
418
|
+
* const schema = buildSchema(`
|
|
419
|
+
* input ReviewInput {
|
|
420
|
+
* stars: Int!
|
|
421
|
+
* }
|
|
422
|
+
*
|
|
423
|
+
* type Review {
|
|
424
|
+
* stars: Int!
|
|
425
|
+
* }
|
|
426
|
+
*
|
|
427
|
+
* type Query {
|
|
428
|
+
* review(input: ReviewInput): Review
|
|
429
|
+
* }
|
|
430
|
+
* `);
|
|
431
|
+
*
|
|
432
|
+
* isInputObjectType(schema.getType('ReviewInput')); // => true
|
|
433
|
+
* isInputObjectType(schema.getType('Review')); // => false
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
|
|
92
437
|
export function isInputObjectType(type) {
|
|
93
438
|
return instanceOf(type, GraphQLInputObjectType);
|
|
94
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Returns the value as a GraphQLInputObjectType, or throws if it is not one.
|
|
442
|
+
* @param type - The GraphQL type to inspect.
|
|
443
|
+
* @returns The value typed as a GraphQLInputObjectType.
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
447
|
+
* import { assertInputObjectType } from 'graphql/type';
|
|
448
|
+
*
|
|
449
|
+
* const schema = buildSchema(`
|
|
450
|
+
* input ReviewInput {
|
|
451
|
+
* stars: Int!
|
|
452
|
+
* }
|
|
453
|
+
*
|
|
454
|
+
* type Review {
|
|
455
|
+
* stars: Int!
|
|
456
|
+
* }
|
|
457
|
+
*
|
|
458
|
+
* type Query {
|
|
459
|
+
* review(input: ReviewInput): Review
|
|
460
|
+
* }
|
|
461
|
+
* `);
|
|
462
|
+
*
|
|
463
|
+
* const inputType = assertInputObjectType(schema.getType('ReviewInput'));
|
|
464
|
+
*
|
|
465
|
+
* Object.keys(inputType.getFields()); // => ['stars']
|
|
466
|
+
* assertInputObjectType(schema.getType('Review')); // throws an error
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
|
|
95
470
|
export function assertInputObjectType(type) {
|
|
96
471
|
if (!isInputObjectType(type)) {
|
|
97
472
|
throw new Error(
|
|
@@ -101,9 +476,48 @@ export function assertInputObjectType(type) {
|
|
|
101
476
|
|
|
102
477
|
return type;
|
|
103
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* Returns true when the value is a GraphQLList.
|
|
481
|
+
* @param type - The GraphQL type to inspect.
|
|
482
|
+
* @returns True when the value is a GraphQLList.
|
|
483
|
+
* @example
|
|
484
|
+
* ```ts
|
|
485
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
486
|
+
* import { GraphQLList, GraphQLString, isListType } from 'graphql/type';
|
|
487
|
+
*
|
|
488
|
+
* const schema = buildSchema(`
|
|
489
|
+
* type Query {
|
|
490
|
+
* tags: [String!]!
|
|
491
|
+
* }
|
|
492
|
+
* `);
|
|
493
|
+
*
|
|
494
|
+
* const tagsField = schema.getQueryType()?.getFields().tags;
|
|
495
|
+
*
|
|
496
|
+
* isListType(new GraphQLList(GraphQLString)); // => true
|
|
497
|
+
* isListType(GraphQLString); // => false
|
|
498
|
+
* isListType(tagsField?.type); // => false
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
|
|
502
|
+
/** @internal */
|
|
104
503
|
export function isListType(type) {
|
|
105
504
|
return instanceOf(type, GraphQLList);
|
|
106
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Returns the value as a GraphQLList, or throws if it is not one.
|
|
508
|
+
* @param type - The GraphQL type to inspect.
|
|
509
|
+
* @returns The value typed as a GraphQLList.
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* import { GraphQLList, GraphQLString, assertListType } from 'graphql/type';
|
|
513
|
+
*
|
|
514
|
+
* const listType = assertListType(new GraphQLList(GraphQLString));
|
|
515
|
+
*
|
|
516
|
+
* listType.ofType; // => GraphQLString
|
|
517
|
+
* assertListType(GraphQLString); // throws an error
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
|
|
107
521
|
export function assertListType(type) {
|
|
108
522
|
if (!isListType(type)) {
|
|
109
523
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL List type.`);
|
|
@@ -111,9 +525,49 @@ export function assertListType(type) {
|
|
|
111
525
|
|
|
112
526
|
return type;
|
|
113
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Returns true when the value is a GraphQLNonNull.
|
|
530
|
+
* @param type - The GraphQL type to inspect.
|
|
531
|
+
* @returns True when the value is a GraphQLNonNull.
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
535
|
+
* import { GraphQLNonNull, GraphQLString, isNonNullType } from 'graphql/type';
|
|
536
|
+
*
|
|
537
|
+
* const schema = buildSchema(`
|
|
538
|
+
* type Query {
|
|
539
|
+
* name: String!
|
|
540
|
+
* nickname: String
|
|
541
|
+
* }
|
|
542
|
+
* `);
|
|
543
|
+
*
|
|
544
|
+
* const fields = schema.getQueryType()?.getFields();
|
|
545
|
+
*
|
|
546
|
+
* isNonNullType(new GraphQLNonNull(GraphQLString)); // => true
|
|
547
|
+
* isNonNullType(fields?.name.type); // => true
|
|
548
|
+
* isNonNullType(fields?.nickname.type); // => false
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
/** @internal */
|
|
114
553
|
export function isNonNullType(type) {
|
|
115
554
|
return instanceOf(type, GraphQLNonNull);
|
|
116
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Returns the value as a GraphQLNonNull, or throws if it is not one.
|
|
558
|
+
* @param type - The GraphQL type to inspect.
|
|
559
|
+
* @returns The value typed as a GraphQLNonNull.
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* import { GraphQLNonNull, GraphQLString, assertNonNullType } from 'graphql/type';
|
|
563
|
+
*
|
|
564
|
+
* const nonNullType = assertNonNullType(new GraphQLNonNull(GraphQLString));
|
|
565
|
+
*
|
|
566
|
+
* nonNullType.ofType; // => GraphQLString
|
|
567
|
+
* assertNonNullType(GraphQLString); // throws an error
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
|
|
117
571
|
export function assertNonNullType(type) {
|
|
118
572
|
if (!isNonNullType(type)) {
|
|
119
573
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL Non-Null type.`);
|
|
@@ -121,10 +575,35 @@ export function assertNonNullType(type) {
|
|
|
121
575
|
|
|
122
576
|
return type;
|
|
123
577
|
}
|
|
578
|
+
/** These types may be used as input types for arguments and directives. */
|
|
579
|
+
|
|
124
580
|
/**
|
|
125
|
-
*
|
|
581
|
+
* Returns true when the value can be used as a GraphQL input type.
|
|
582
|
+
* @param type - The GraphQL type to inspect.
|
|
583
|
+
* @returns True when the value can be used as a GraphQL input type.
|
|
584
|
+
* @example
|
|
585
|
+
* ```ts
|
|
586
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
587
|
+
* import { isInputType } from 'graphql/type';
|
|
588
|
+
*
|
|
589
|
+
* const schema = buildSchema(`
|
|
590
|
+
* input ReviewInput {
|
|
591
|
+
* stars: Int!
|
|
592
|
+
* }
|
|
593
|
+
*
|
|
594
|
+
* type Review {
|
|
595
|
+
* stars: Int!
|
|
596
|
+
* }
|
|
597
|
+
*
|
|
598
|
+
* type Query {
|
|
599
|
+
* review(input: ReviewInput): Review
|
|
600
|
+
* }
|
|
601
|
+
* `);
|
|
602
|
+
*
|
|
603
|
+
* isInputType(schema.getType('ReviewInput')); // => true
|
|
604
|
+
* isInputType(schema.getType('Review')); // => false
|
|
605
|
+
* ```
|
|
126
606
|
*/
|
|
127
|
-
|
|
128
607
|
export function isInputType(type) {
|
|
129
608
|
return (
|
|
130
609
|
isScalarType(type) ||
|
|
@@ -133,6 +612,36 @@ export function isInputType(type) {
|
|
|
133
612
|
(isWrappingType(type) && isInputType(type.ofType))
|
|
134
613
|
);
|
|
135
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* Returns the value as a GraphQL input type, or throws if it is not one.
|
|
617
|
+
* @param type - The GraphQL type to inspect.
|
|
618
|
+
* @returns The value typed as a GraphQL input type.
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
622
|
+
* import { assertInputType } from 'graphql/type';
|
|
623
|
+
*
|
|
624
|
+
* const schema = buildSchema(`
|
|
625
|
+
* input ReviewInput {
|
|
626
|
+
* stars: Int!
|
|
627
|
+
* }
|
|
628
|
+
*
|
|
629
|
+
* type Review {
|
|
630
|
+
* stars: Int!
|
|
631
|
+
* }
|
|
632
|
+
*
|
|
633
|
+
* type Query {
|
|
634
|
+
* review(input: ReviewInput): Review
|
|
635
|
+
* }
|
|
636
|
+
* `);
|
|
637
|
+
*
|
|
638
|
+
* const inputType = assertInputType(schema.getType('ReviewInput'));
|
|
639
|
+
*
|
|
640
|
+
* inputType.toString(); // => 'ReviewInput'
|
|
641
|
+
* assertInputType(schema.getType('Review')); // throws an error
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
|
|
136
645
|
export function assertInputType(type) {
|
|
137
646
|
if (!isInputType(type)) {
|
|
138
647
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL input type.`);
|
|
@@ -140,10 +649,35 @@ export function assertInputType(type) {
|
|
|
140
649
|
|
|
141
650
|
return type;
|
|
142
651
|
}
|
|
652
|
+
/** These types may be used as output types as the result of fields. */
|
|
653
|
+
|
|
143
654
|
/**
|
|
144
|
-
*
|
|
655
|
+
* Returns true when the value can be used as a GraphQL output type.
|
|
656
|
+
* @param type - The GraphQL type to inspect.
|
|
657
|
+
* @returns True when the value can be used as a GraphQL output type.
|
|
658
|
+
* @example
|
|
659
|
+
* ```ts
|
|
660
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
661
|
+
* import { isOutputType } from 'graphql/type';
|
|
662
|
+
*
|
|
663
|
+
* const schema = buildSchema(`
|
|
664
|
+
* input ReviewInput {
|
|
665
|
+
* stars: Int!
|
|
666
|
+
* }
|
|
667
|
+
*
|
|
668
|
+
* type Review {
|
|
669
|
+
* stars: Int!
|
|
670
|
+
* }
|
|
671
|
+
*
|
|
672
|
+
* type Query {
|
|
673
|
+
* review(input: ReviewInput): Review
|
|
674
|
+
* }
|
|
675
|
+
* `);
|
|
676
|
+
*
|
|
677
|
+
* isOutputType(schema.getType('Review')); // => true
|
|
678
|
+
* isOutputType(schema.getType('ReviewInput')); // => false
|
|
679
|
+
* ```
|
|
145
680
|
*/
|
|
146
|
-
|
|
147
681
|
export function isOutputType(type) {
|
|
148
682
|
return (
|
|
149
683
|
isScalarType(type) ||
|
|
@@ -154,6 +688,36 @@ export function isOutputType(type) {
|
|
|
154
688
|
(isWrappingType(type) && isOutputType(type.ofType))
|
|
155
689
|
);
|
|
156
690
|
}
|
|
691
|
+
/**
|
|
692
|
+
* Returns the value as a GraphQL output type, or throws if it is not one.
|
|
693
|
+
* @param type - The GraphQL type to inspect.
|
|
694
|
+
* @returns The value typed as a GraphQL output type.
|
|
695
|
+
* @example
|
|
696
|
+
* ```ts
|
|
697
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
698
|
+
* import { assertOutputType } from 'graphql/type';
|
|
699
|
+
*
|
|
700
|
+
* const schema = buildSchema(`
|
|
701
|
+
* input ReviewInput {
|
|
702
|
+
* stars: Int!
|
|
703
|
+
* }
|
|
704
|
+
*
|
|
705
|
+
* type Review {
|
|
706
|
+
* stars: Int!
|
|
707
|
+
* }
|
|
708
|
+
*
|
|
709
|
+
* type Query {
|
|
710
|
+
* review(input: ReviewInput): Review
|
|
711
|
+
* }
|
|
712
|
+
* `);
|
|
713
|
+
*
|
|
714
|
+
* const outputType = assertOutputType(schema.getType('Review'));
|
|
715
|
+
*
|
|
716
|
+
* outputType.toString(); // => 'Review'
|
|
717
|
+
* assertOutputType(schema.getType('ReviewInput')); // throws an error
|
|
718
|
+
* ```
|
|
719
|
+
*/
|
|
720
|
+
|
|
157
721
|
export function assertOutputType(type) {
|
|
158
722
|
if (!isOutputType(type)) {
|
|
159
723
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL output type.`);
|
|
@@ -161,13 +725,71 @@ export function assertOutputType(type) {
|
|
|
161
725
|
|
|
162
726
|
return type;
|
|
163
727
|
}
|
|
728
|
+
/** These types may describe types which may be leaf values. */
|
|
729
|
+
|
|
164
730
|
/**
|
|
165
|
-
*
|
|
731
|
+
* Returns true when the value is a GraphQL scalar or enum type.
|
|
732
|
+
* @param type - The GraphQL type to inspect.
|
|
733
|
+
* @returns True when the value is a GraphQL scalar or enum type.
|
|
734
|
+
* @example
|
|
735
|
+
* ```ts
|
|
736
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
737
|
+
* import { isLeafType } from 'graphql/type';
|
|
738
|
+
*
|
|
739
|
+
* const schema = buildSchema(`
|
|
740
|
+
* enum Episode {
|
|
741
|
+
* NEW_HOPE
|
|
742
|
+
* }
|
|
743
|
+
*
|
|
744
|
+
* type Review {
|
|
745
|
+
* stars: Int!
|
|
746
|
+
* }
|
|
747
|
+
*
|
|
748
|
+
* type Query {
|
|
749
|
+
* episode: Episode
|
|
750
|
+
* review: Review
|
|
751
|
+
* }
|
|
752
|
+
* `);
|
|
753
|
+
*
|
|
754
|
+
* isLeafType(schema.getType('Episode')); // => true
|
|
755
|
+
* isLeafType(schema.getType('String')); // => true
|
|
756
|
+
* isLeafType(schema.getType('Review')); // => false
|
|
757
|
+
* ```
|
|
166
758
|
*/
|
|
167
|
-
|
|
168
759
|
export function isLeafType(type) {
|
|
169
760
|
return isScalarType(type) || isEnumType(type);
|
|
170
761
|
}
|
|
762
|
+
/**
|
|
763
|
+
* Returns the value as a GraphQL leaf type, or throws if it is not one.
|
|
764
|
+
* @param type - The GraphQL type to inspect.
|
|
765
|
+
* @returns The value typed as a GraphQL leaf type.
|
|
766
|
+
* @example
|
|
767
|
+
* ```ts
|
|
768
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
769
|
+
* import { assertLeafType } from 'graphql/type';
|
|
770
|
+
*
|
|
771
|
+
* const schema = buildSchema(`
|
|
772
|
+
* enum Episode {
|
|
773
|
+
* NEW_HOPE
|
|
774
|
+
* }
|
|
775
|
+
*
|
|
776
|
+
* type Review {
|
|
777
|
+
* stars: Int!
|
|
778
|
+
* }
|
|
779
|
+
*
|
|
780
|
+
* type Query {
|
|
781
|
+
* episode: Episode
|
|
782
|
+
* review: Review
|
|
783
|
+
* }
|
|
784
|
+
* `);
|
|
785
|
+
*
|
|
786
|
+
* const episodeType = assertLeafType(schema.getType('Episode'));
|
|
787
|
+
*
|
|
788
|
+
* episodeType.toString(); // => 'Episode'
|
|
789
|
+
* assertLeafType(schema.getType('Review')); // throws an error
|
|
790
|
+
* ```
|
|
791
|
+
*/
|
|
792
|
+
|
|
171
793
|
export function assertLeafType(type) {
|
|
172
794
|
if (!isLeafType(type)) {
|
|
173
795
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL leaf type.`);
|
|
@@ -175,13 +797,73 @@ export function assertLeafType(type) {
|
|
|
175
797
|
|
|
176
798
|
return type;
|
|
177
799
|
}
|
|
800
|
+
/** These types may describe the parent context of a selection set. */
|
|
801
|
+
|
|
178
802
|
/**
|
|
179
|
-
*
|
|
803
|
+
* Returns true when the value is a GraphQL object, interface, or union type.
|
|
804
|
+
* @param type - The GraphQL type to inspect.
|
|
805
|
+
* @returns True when the value is a GraphQL object, interface, or union type.
|
|
806
|
+
* @example
|
|
807
|
+
* ```ts
|
|
808
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
809
|
+
* import { isCompositeType } from 'graphql/type';
|
|
810
|
+
*
|
|
811
|
+
* const schema = buildSchema(`
|
|
812
|
+
* interface Node {
|
|
813
|
+
* id: ID!
|
|
814
|
+
* }
|
|
815
|
+
*
|
|
816
|
+
* type User implements Node {
|
|
817
|
+
* id: ID!
|
|
818
|
+
* }
|
|
819
|
+
*
|
|
820
|
+
* union SearchResult = User
|
|
821
|
+
*
|
|
822
|
+
* type Query {
|
|
823
|
+
* node: Node
|
|
824
|
+
* search: [SearchResult]
|
|
825
|
+
* }
|
|
826
|
+
* `);
|
|
827
|
+
*
|
|
828
|
+
* isCompositeType(schema.getType('User')); // => true
|
|
829
|
+
* isCompositeType(schema.getType('Node')); // => true
|
|
830
|
+
* isCompositeType(schema.getType('SearchResult')); // => true
|
|
831
|
+
* isCompositeType(schema.getType('String')); // => false
|
|
832
|
+
* ```
|
|
180
833
|
*/
|
|
181
|
-
|
|
182
834
|
export function isCompositeType(type) {
|
|
183
835
|
return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
|
|
184
836
|
}
|
|
837
|
+
/**
|
|
838
|
+
* Returns the value as a GraphQL composite type, or throws if it is not one.
|
|
839
|
+
* @param type - The GraphQL type to inspect.
|
|
840
|
+
* @returns The value typed as a GraphQL composite type.
|
|
841
|
+
* @example
|
|
842
|
+
* ```ts
|
|
843
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
844
|
+
* import { assertCompositeType } from 'graphql/type';
|
|
845
|
+
*
|
|
846
|
+
* const schema = buildSchema(`
|
|
847
|
+
* interface Node {
|
|
848
|
+
* id: ID!
|
|
849
|
+
* }
|
|
850
|
+
*
|
|
851
|
+
* type User implements Node {
|
|
852
|
+
* id: ID!
|
|
853
|
+
* }
|
|
854
|
+
*
|
|
855
|
+
* type Query {
|
|
856
|
+
* node: Node
|
|
857
|
+
* }
|
|
858
|
+
* `);
|
|
859
|
+
*
|
|
860
|
+
* const userType = assertCompositeType(schema.getType('User'));
|
|
861
|
+
*
|
|
862
|
+
* userType.toString(); // => 'User'
|
|
863
|
+
* assertCompositeType(schema.getType('String')); // throws an error
|
|
864
|
+
* ```
|
|
865
|
+
*/
|
|
866
|
+
|
|
185
867
|
export function assertCompositeType(type) {
|
|
186
868
|
if (!isCompositeType(type)) {
|
|
187
869
|
throw new Error(
|
|
@@ -191,13 +873,72 @@ export function assertCompositeType(type) {
|
|
|
191
873
|
|
|
192
874
|
return type;
|
|
193
875
|
}
|
|
876
|
+
/** These types may describe the parent context of a selection set. */
|
|
877
|
+
|
|
194
878
|
/**
|
|
195
|
-
*
|
|
879
|
+
* Returns true when the value is a GraphQL interface or union type.
|
|
880
|
+
* @param type - The GraphQL type to inspect.
|
|
881
|
+
* @returns True when the value is a GraphQL interface or union type.
|
|
882
|
+
* @example
|
|
883
|
+
* ```ts
|
|
884
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
885
|
+
* import { isAbstractType } from 'graphql/type';
|
|
886
|
+
*
|
|
887
|
+
* const schema = buildSchema(`
|
|
888
|
+
* interface Node {
|
|
889
|
+
* id: ID!
|
|
890
|
+
* }
|
|
891
|
+
*
|
|
892
|
+
* type User implements Node {
|
|
893
|
+
* id: ID!
|
|
894
|
+
* }
|
|
895
|
+
*
|
|
896
|
+
* union SearchResult = User
|
|
897
|
+
*
|
|
898
|
+
* type Query {
|
|
899
|
+
* node: Node
|
|
900
|
+
* search: [SearchResult]
|
|
901
|
+
* }
|
|
902
|
+
* `);
|
|
903
|
+
*
|
|
904
|
+
* isAbstractType(schema.getType('Node')); // => true
|
|
905
|
+
* isAbstractType(schema.getType('SearchResult')); // => true
|
|
906
|
+
* isAbstractType(schema.getType('User')); // => false
|
|
907
|
+
* ```
|
|
196
908
|
*/
|
|
197
|
-
|
|
198
909
|
export function isAbstractType(type) {
|
|
199
910
|
return isInterfaceType(type) || isUnionType(type);
|
|
200
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Returns the value as a GraphQL abstract type, or throws if it is not one.
|
|
914
|
+
* @param type - The GraphQL type to inspect.
|
|
915
|
+
* @returns The value typed as a GraphQL abstract type.
|
|
916
|
+
* @example
|
|
917
|
+
* ```ts
|
|
918
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
919
|
+
* import { assertAbstractType } from 'graphql/type';
|
|
920
|
+
*
|
|
921
|
+
* const schema = buildSchema(`
|
|
922
|
+
* interface Node {
|
|
923
|
+
* id: ID!
|
|
924
|
+
* }
|
|
925
|
+
*
|
|
926
|
+
* type User implements Node {
|
|
927
|
+
* id: ID!
|
|
928
|
+
* }
|
|
929
|
+
*
|
|
930
|
+
* type Query {
|
|
931
|
+
* node: Node
|
|
932
|
+
* }
|
|
933
|
+
* `);
|
|
934
|
+
*
|
|
935
|
+
* const nodeType = assertAbstractType(schema.getType('Node'));
|
|
936
|
+
*
|
|
937
|
+
* nodeType.toString(); // => 'Node'
|
|
938
|
+
* assertAbstractType(schema.getType('User')); // throws an error
|
|
939
|
+
* ```
|
|
940
|
+
*/
|
|
941
|
+
|
|
201
942
|
export function assertAbstractType(type) {
|
|
202
943
|
if (!isAbstractType(type)) {
|
|
203
944
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL abstract type.`);
|
|
@@ -211,9 +952,8 @@ export function assertAbstractType(type) {
|
|
|
211
952
|
* A list is a wrapping type which points to another type.
|
|
212
953
|
* Lists are often created within the context of defining the fields of
|
|
213
954
|
* an object type.
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
955
|
+
* @typeParam T - The GraphQL type wrapped by this list type.
|
|
956
|
+
* @example
|
|
217
957
|
* ```ts
|
|
218
958
|
* const PersonType = new GraphQLObjectType({
|
|
219
959
|
* name: 'Person',
|
|
@@ -226,19 +966,65 @@ export function assertAbstractType(type) {
|
|
|
226
966
|
*/
|
|
227
967
|
|
|
228
968
|
export class GraphQLList {
|
|
969
|
+
/** The type wrapped by this list or non-null type. */
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Creates a GraphQLList instance.
|
|
973
|
+
* @param ofType - The type to wrap.
|
|
974
|
+
* @example
|
|
975
|
+
* ```ts
|
|
976
|
+
* import { GraphQLList, GraphQLString } from 'graphql/type';
|
|
977
|
+
*
|
|
978
|
+
* const stringList = new GraphQLList(GraphQLString);
|
|
979
|
+
*
|
|
980
|
+
* stringList.ofType; // => GraphQLString
|
|
981
|
+
* String(stringList); // => '[String]'
|
|
982
|
+
* ```
|
|
983
|
+
*/
|
|
229
984
|
constructor(ofType) {
|
|
230
985
|
isType(ofType) ||
|
|
231
986
|
devAssert(false, `Expected ${inspect(ofType)} to be a GraphQL type.`);
|
|
232
987
|
this.ofType = ofType;
|
|
233
988
|
}
|
|
989
|
+
/**
|
|
990
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
991
|
+
* @returns The built-in string tag for this object.
|
|
992
|
+
*/
|
|
234
993
|
|
|
235
994
|
get [Symbol.toStringTag]() {
|
|
236
995
|
return 'GraphQLList';
|
|
237
996
|
}
|
|
997
|
+
/**
|
|
998
|
+
* Returns this wrapping type as a GraphQL type-reference string.
|
|
999
|
+
* @returns The GraphQL type-reference string.
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
1003
|
+
*
|
|
1004
|
+
* const stringList = new GraphQLList(GraphQLString);
|
|
1005
|
+
* const requiredStringList = new GraphQLList(new GraphQLNonNull(GraphQLString));
|
|
1006
|
+
*
|
|
1007
|
+
* stringList.toString(); // => '[String]'
|
|
1008
|
+
* requiredStringList.toString(); // => '[String!]'
|
|
1009
|
+
* ```
|
|
1010
|
+
*/
|
|
238
1011
|
|
|
239
1012
|
toString() {
|
|
240
1013
|
return '[' + String(this.ofType) + ']';
|
|
241
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Returns the JSON representation used when this object is serialized.
|
|
1017
|
+
* @returns The JSON-serializable representation.
|
|
1018
|
+
* @example
|
|
1019
|
+
* ```ts
|
|
1020
|
+
* import { GraphQLList, GraphQLString } from 'graphql/type';
|
|
1021
|
+
*
|
|
1022
|
+
* const stringList = new GraphQLList(GraphQLString);
|
|
1023
|
+
*
|
|
1024
|
+
* stringList.toJSON(); // => '[String]'
|
|
1025
|
+
* JSON.stringify({ type: stringList }); // => '{"type":"[String]"}'
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
242
1028
|
|
|
243
1029
|
toJSON() {
|
|
244
1030
|
return this.toString();
|
|
@@ -252,9 +1038,8 @@ export class GraphQLList {
|
|
|
252
1038
|
* an error is raised if this ever occurs during a request. It is useful for
|
|
253
1039
|
* fields which you can make a strong guarantee on non-nullability, for example
|
|
254
1040
|
* usually the id field of a database row will never be null.
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
1041
|
+
* @typeParam T - The nullable GraphQL type wrapped by this non-null type.
|
|
1042
|
+
* @example
|
|
258
1043
|
* ```ts
|
|
259
1044
|
* const RowType = new GraphQLObjectType({
|
|
260
1045
|
* name: 'Row',
|
|
@@ -263,10 +1048,26 @@ export class GraphQLList {
|
|
|
263
1048
|
* })
|
|
264
1049
|
* })
|
|
265
1050
|
* ```
|
|
1051
|
+
*
|
|
266
1052
|
* Note: the enforcement of non-nullability occurs within the executor.
|
|
267
1053
|
*/
|
|
268
1054
|
|
|
269
1055
|
export class GraphQLNonNull {
|
|
1056
|
+
/** The type wrapped by this list or non-null type. */
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* Creates a GraphQLNonNull instance.
|
|
1060
|
+
* @param ofType - The type to wrap.
|
|
1061
|
+
* @example
|
|
1062
|
+
* ```ts
|
|
1063
|
+
* import { GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
1064
|
+
*
|
|
1065
|
+
* const requiredString = new GraphQLNonNull(GraphQLString);
|
|
1066
|
+
*
|
|
1067
|
+
* requiredString.ofType; // => GraphQLString
|
|
1068
|
+
* String(requiredString); // => 'String!'
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
270
1071
|
constructor(ofType) {
|
|
271
1072
|
isNullableType(ofType) ||
|
|
272
1073
|
devAssert(
|
|
@@ -275,26 +1076,90 @@ export class GraphQLNonNull {
|
|
|
275
1076
|
);
|
|
276
1077
|
this.ofType = ofType;
|
|
277
1078
|
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
1081
|
+
* @returns The built-in string tag for this object.
|
|
1082
|
+
*/
|
|
278
1083
|
|
|
279
1084
|
get [Symbol.toStringTag]() {
|
|
280
1085
|
return 'GraphQLNonNull';
|
|
281
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Returns this wrapping type as a GraphQL type-reference string.
|
|
1089
|
+
* @returns The GraphQL type-reference string.
|
|
1090
|
+
* @example
|
|
1091
|
+
* ```ts
|
|
1092
|
+
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
1093
|
+
*
|
|
1094
|
+
* const requiredString = new GraphQLNonNull(GraphQLString);
|
|
1095
|
+
* const requiredStringList = new GraphQLNonNull(
|
|
1096
|
+
* new GraphQLList(GraphQLString),
|
|
1097
|
+
* );
|
|
1098
|
+
*
|
|
1099
|
+
* requiredString.toString(); // => 'String!'
|
|
1100
|
+
* requiredStringList.toString(); // => '[String]!'
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
282
1103
|
|
|
283
1104
|
toString() {
|
|
284
1105
|
return String(this.ofType) + '!';
|
|
285
1106
|
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns the JSON representation used when this object is serialized.
|
|
1109
|
+
* @returns The JSON-serializable representation.
|
|
1110
|
+
* @example
|
|
1111
|
+
* ```ts
|
|
1112
|
+
* import { GraphQLNonNull, GraphQLString } from 'graphql/type';
|
|
1113
|
+
*
|
|
1114
|
+
* const requiredString = new GraphQLNonNull(GraphQLString);
|
|
1115
|
+
*
|
|
1116
|
+
* requiredString.toJSON(); // => 'String!'
|
|
1117
|
+
* JSON.stringify({ type: requiredString }); // => '{"type":"String!"}'
|
|
1118
|
+
* ```
|
|
1119
|
+
*/
|
|
286
1120
|
|
|
287
1121
|
toJSON() {
|
|
288
1122
|
return this.toString();
|
|
289
1123
|
}
|
|
290
1124
|
}
|
|
1125
|
+
/** These types wrap and modify other types */
|
|
1126
|
+
|
|
291
1127
|
/**
|
|
292
|
-
*
|
|
1128
|
+
* Returns true when the value is a GraphQL list or non-null wrapper type.
|
|
1129
|
+
* @param type - The GraphQL type to inspect.
|
|
1130
|
+
* @returns True when the value is a GraphQL list or non-null wrapper type.
|
|
1131
|
+
* @example
|
|
1132
|
+
* ```ts
|
|
1133
|
+
* import {
|
|
1134
|
+
* GraphQLList,
|
|
1135
|
+
* GraphQLNonNull,
|
|
1136
|
+
* GraphQLString,
|
|
1137
|
+
* isWrappingType,
|
|
1138
|
+
* } from 'graphql/type';
|
|
1139
|
+
*
|
|
1140
|
+
* isWrappingType(new GraphQLList(GraphQLString)); // => true
|
|
1141
|
+
* isWrappingType(new GraphQLNonNull(GraphQLString)); // => true
|
|
1142
|
+
* isWrappingType(GraphQLString); // => false
|
|
1143
|
+
* ```
|
|
293
1144
|
*/
|
|
294
|
-
|
|
295
1145
|
export function isWrappingType(type) {
|
|
296
1146
|
return isListType(type) || isNonNullType(type);
|
|
297
1147
|
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Returns the value as a GraphQL wrapping type, or throws if it is not one.
|
|
1150
|
+
* @param type - The GraphQL type to inspect.
|
|
1151
|
+
* @returns The value typed as a GraphQL wrapping type.
|
|
1152
|
+
* @example
|
|
1153
|
+
* ```ts
|
|
1154
|
+
* import { GraphQLList, GraphQLString, assertWrappingType } from 'graphql/type';
|
|
1155
|
+
*
|
|
1156
|
+
* const wrappingType = assertWrappingType(new GraphQLList(GraphQLString));
|
|
1157
|
+
*
|
|
1158
|
+
* wrappingType.toString(); // => '[String]'
|
|
1159
|
+
* assertWrappingType(GraphQLString); // throws an error
|
|
1160
|
+
* ```
|
|
1161
|
+
*/
|
|
1162
|
+
|
|
298
1163
|
export function assertWrappingType(type) {
|
|
299
1164
|
if (!isWrappingType(type)) {
|
|
300
1165
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL wrapping type.`);
|
|
@@ -302,13 +1167,43 @@ export function assertWrappingType(type) {
|
|
|
302
1167
|
|
|
303
1168
|
return type;
|
|
304
1169
|
}
|
|
1170
|
+
/** These types can all accept null as a value. */
|
|
1171
|
+
|
|
305
1172
|
/**
|
|
306
|
-
*
|
|
1173
|
+
* Returns true when the value is a GraphQL type that can accept null.
|
|
1174
|
+
* @param type - The GraphQL type to inspect.
|
|
1175
|
+
* @returns True when the value is a GraphQL type that can accept null.
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```ts
|
|
1178
|
+
* import { GraphQLNonNull, GraphQLString, isNullableType } from 'graphql/type';
|
|
1179
|
+
*
|
|
1180
|
+
* isNullableType(GraphQLString); // => true
|
|
1181
|
+
* isNullableType(new GraphQLNonNull(GraphQLString)); // => false
|
|
1182
|
+
* isNullableType(null); // => false
|
|
1183
|
+
* ```
|
|
307
1184
|
*/
|
|
308
|
-
|
|
309
1185
|
export function isNullableType(type) {
|
|
310
1186
|
return isType(type) && !isNonNullType(type);
|
|
311
1187
|
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Returns the value as a nullable GraphQL type, or throws if it is not one.
|
|
1190
|
+
* @param type - The GraphQL type to inspect.
|
|
1191
|
+
* @returns The value typed as a nullable GraphQL type.
|
|
1192
|
+
* @example
|
|
1193
|
+
* ```ts
|
|
1194
|
+
* import {
|
|
1195
|
+
* GraphQLNonNull,
|
|
1196
|
+
* GraphQLString,
|
|
1197
|
+
* assertNullableType,
|
|
1198
|
+
* } from 'graphql/type';
|
|
1199
|
+
*
|
|
1200
|
+
* const nullableType = assertNullableType(GraphQLString);
|
|
1201
|
+
*
|
|
1202
|
+
* nullableType; // => GraphQLString
|
|
1203
|
+
* assertNullableType(new GraphQLNonNull(GraphQLString)); // throws an error
|
|
1204
|
+
* ```
|
|
1205
|
+
*/
|
|
1206
|
+
|
|
312
1207
|
export function assertNullableType(type) {
|
|
313
1208
|
if (!isNullableType(type)) {
|
|
314
1209
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL nullable type.`);
|
|
@@ -316,15 +1211,40 @@ export function assertNullableType(type) {
|
|
|
316
1211
|
|
|
317
1212
|
return type;
|
|
318
1213
|
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Returns the nullable type.
|
|
1216
|
+
* @param type - The GraphQL type to inspect.
|
|
1217
|
+
* @returns The nullable type after removing one non-null wrapper, if present.
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```ts
|
|
1220
|
+
* import { getNullableType } from 'graphql/type';
|
|
1221
|
+
*
|
|
1222
|
+
* getNullableType(null); // => undefined
|
|
1223
|
+
* getNullableType(undefined); // => undefined
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
1226
|
+
|
|
1227
|
+
/** @internal */
|
|
319
1228
|
export function getNullableType(type) {
|
|
320
1229
|
if (type) {
|
|
321
1230
|
return isNonNullType(type) ? type.ofType : type;
|
|
322
1231
|
}
|
|
323
1232
|
}
|
|
1233
|
+
/** These named types do not include modifiers like List or NonNull. */
|
|
1234
|
+
|
|
324
1235
|
/**
|
|
325
|
-
*
|
|
1236
|
+
* Returns true when the value is a GraphQL named type.
|
|
1237
|
+
* @param type - The GraphQL type to inspect.
|
|
1238
|
+
* @returns True when the value is a GraphQL named type.
|
|
1239
|
+
* @example
|
|
1240
|
+
* ```ts
|
|
1241
|
+
* import { GraphQLList, GraphQLString, isNamedType } from 'graphql/type';
|
|
1242
|
+
*
|
|
1243
|
+
* isNamedType(GraphQLString); // => true
|
|
1244
|
+
* isNamedType(new GraphQLList(GraphQLString)); // => false
|
|
1245
|
+
* isNamedType(null); // => false
|
|
1246
|
+
* ```
|
|
326
1247
|
*/
|
|
327
|
-
|
|
328
1248
|
export function isNamedType(type) {
|
|
329
1249
|
return (
|
|
330
1250
|
isScalarType(type) ||
|
|
@@ -335,6 +1255,21 @@ export function isNamedType(type) {
|
|
|
335
1255
|
isInputObjectType(type)
|
|
336
1256
|
);
|
|
337
1257
|
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Returns the value as a GraphQL named type, or throws if it is not one.
|
|
1260
|
+
* @param type - The GraphQL type to inspect.
|
|
1261
|
+
* @returns The value typed as a GraphQL named type.
|
|
1262
|
+
* @example
|
|
1263
|
+
* ```ts
|
|
1264
|
+
* import { GraphQLList, GraphQLString, assertNamedType } from 'graphql/type';
|
|
1265
|
+
*
|
|
1266
|
+
* const namedType = assertNamedType(GraphQLString);
|
|
1267
|
+
*
|
|
1268
|
+
* namedType.name; // => 'String'
|
|
1269
|
+
* assertNamedType(new GraphQLList(GraphQLString)); // throws an error
|
|
1270
|
+
* ```
|
|
1271
|
+
*/
|
|
1272
|
+
|
|
338
1273
|
export function assertNamedType(type) {
|
|
339
1274
|
if (!isNamedType(type)) {
|
|
340
1275
|
throw new Error(`Expected ${inspect(type)} to be a GraphQL named type.`);
|
|
@@ -342,6 +1277,20 @@ export function assertNamedType(type) {
|
|
|
342
1277
|
|
|
343
1278
|
return type;
|
|
344
1279
|
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Returns the named type.
|
|
1282
|
+
* @param type - The GraphQL type to inspect.
|
|
1283
|
+
* @returns The named type after unwrapping all list and non-null wrappers.
|
|
1284
|
+
* @example
|
|
1285
|
+
* ```ts
|
|
1286
|
+
* import { getNamedType } from 'graphql/type';
|
|
1287
|
+
*
|
|
1288
|
+
* getNamedType(null); // => undefined
|
|
1289
|
+
* getNamedType(undefined); // => undefined
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1292
|
+
|
|
1293
|
+
/** @internal */
|
|
345
1294
|
export function getNamedType(type) {
|
|
346
1295
|
if (type) {
|
|
347
1296
|
let unwrappedType = type;
|
|
@@ -356,17 +1305,50 @@ export function getNamedType(type) {
|
|
|
356
1305
|
/**
|
|
357
1306
|
* Used while defining GraphQL types to allow for circular references in
|
|
358
1307
|
* otherwise immutable type definitions.
|
|
1308
|
+
* @typeParam T - The element type returned by the thunk or array.
|
|
359
1309
|
*/
|
|
360
1310
|
|
|
1311
|
+
/**
|
|
1312
|
+
* Resolves a thunked readonly array.
|
|
1313
|
+
* @param thunk - The thunk or value to resolve.
|
|
1314
|
+
* @returns The resolved readonly array.
|
|
1315
|
+
* @typeParam T - The element type resolved from the thunk or array.
|
|
1316
|
+
* @example
|
|
1317
|
+
* ```ts
|
|
1318
|
+
* import { GraphQLString, resolveReadonlyArrayThunk } from 'graphql/type';
|
|
1319
|
+
*
|
|
1320
|
+
* const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]);
|
|
1321
|
+
* const fields = resolveReadonlyArrayThunk([GraphQLString]);
|
|
1322
|
+
*
|
|
1323
|
+
* lazyFields; // => [GraphQLString]
|
|
1324
|
+
* fields; // => [GraphQLString]
|
|
1325
|
+
* ```
|
|
1326
|
+
*/
|
|
361
1327
|
export function resolveReadonlyArrayThunk(thunk) {
|
|
362
1328
|
return typeof thunk === 'function' ? thunk() : thunk;
|
|
363
1329
|
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Resolves a thunked object map.
|
|
1332
|
+
* @param thunk - The thunk or value to resolve.
|
|
1333
|
+
* @returns The resolved object map.
|
|
1334
|
+
* @typeParam T - The object-map value type resolved from the thunk or map.
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```ts
|
|
1337
|
+
* import { GraphQLString, resolveObjMapThunk } from 'graphql/type';
|
|
1338
|
+
*
|
|
1339
|
+
* const lazyFields = resolveObjMapThunk(() => ({ name: GraphQLString }));
|
|
1340
|
+
* const fields = resolveObjMapThunk({ name: GraphQLString });
|
|
1341
|
+
*
|
|
1342
|
+
* lazyFields.name; // => GraphQLString
|
|
1343
|
+
* fields.name; // => GraphQLString
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1346
|
+
|
|
364
1347
|
export function resolveObjMapThunk(thunk) {
|
|
365
1348
|
return typeof thunk === 'function' ? thunk() : thunk;
|
|
366
1349
|
}
|
|
367
1350
|
/**
|
|
368
1351
|
* Custom extensions
|
|
369
|
-
*
|
|
370
1352
|
* @remarks
|
|
371
1353
|
* Use a unique identifier name for your extension, for example the name of
|
|
372
1354
|
* your library or project. Do not use a shortened identifier as this increases
|
|
@@ -377,20 +1359,22 @@ export function resolveObjMapThunk(thunk) {
|
|
|
377
1359
|
/**
|
|
378
1360
|
* Scalar Type Definition
|
|
379
1361
|
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
1362
|
+
* Scalar types define the leaf values of a GraphQL response and the input
|
|
1363
|
+
* values accepted by arguments and input object fields. A scalar type has a
|
|
1364
|
+
* name and coercion functions that validate and convert runtime values and
|
|
1365
|
+
* GraphQL literals.
|
|
383
1366
|
*
|
|
384
1367
|
* If a type's serialize function returns `null` or does not return a value
|
|
385
1368
|
* (i.e. it returns `undefined`) then an error will be raised and a `null`
|
|
386
|
-
* value will be returned in the response.
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
1369
|
+
* value will be returned in the response. Prefer validating inputs before
|
|
1370
|
+
* execution so clients receive input diagnostics before result coercion fails.
|
|
1371
|
+
* @typeParam TInternal - The internal runtime representation accepted by this scalar.
|
|
1372
|
+
* @typeParam TExternal - The serialized representation exposed in GraphQL results.
|
|
1373
|
+
* @example
|
|
390
1374
|
* ```ts
|
|
391
1375
|
* const OddType = new GraphQLScalarType({
|
|
392
1376
|
* name: 'Odd',
|
|
393
|
-
* serialize(value) {
|
|
1377
|
+
* serialize: (value) => {
|
|
394
1378
|
* if (!Number.isFinite(value)) {
|
|
395
1379
|
* throw new Error(
|
|
396
1380
|
* `Scalar "Odd" cannot represent "${value}" since it is not a finite number.`,
|
|
@@ -406,6 +1390,77 @@ export function resolveObjMapThunk(thunk) {
|
|
|
406
1390
|
* ```
|
|
407
1391
|
*/
|
|
408
1392
|
export class GraphQLScalarType {
|
|
1393
|
+
/** The GraphQL name for this schema element. */
|
|
1394
|
+
|
|
1395
|
+
/** Human-readable description for this schema element, if provided. */
|
|
1396
|
+
|
|
1397
|
+
/** URL identifying the behavior specified for this custom scalar. */
|
|
1398
|
+
|
|
1399
|
+
/** Function that converts internal values to externally visible scalar values. */
|
|
1400
|
+
|
|
1401
|
+
/** Function that converts variable input into this scalar's internal value. */
|
|
1402
|
+
|
|
1403
|
+
/** Function that converts AST input literals into this scalar's internal value. */
|
|
1404
|
+
|
|
1405
|
+
/** Extension fields to include in the formatted result. */
|
|
1406
|
+
|
|
1407
|
+
/** AST node from which this schema element was built, if available. */
|
|
1408
|
+
|
|
1409
|
+
/** AST extension nodes applied to this schema element. */
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* Creates a GraphQLScalarType instance.
|
|
1413
|
+
* @param config - Configuration describing this object.
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* import { Kind, parse } from 'graphql/language';
|
|
1417
|
+
* import { GraphQLScalarType } from 'graphql/type';
|
|
1418
|
+
*
|
|
1419
|
+
* const document = parse(`
|
|
1420
|
+
* "Odd integer values."
|
|
1421
|
+
* scalar Odd @specifiedBy(url: "https://example.com/odd")
|
|
1422
|
+
*
|
|
1423
|
+
* extend scalar Odd @specifiedBy(url: "https://example.com/odd-v2")
|
|
1424
|
+
* `);
|
|
1425
|
+
*
|
|
1426
|
+
* const Odd = new GraphQLScalarType({
|
|
1427
|
+
* name: 'Odd',
|
|
1428
|
+
* description: 'Odd integer values.',
|
|
1429
|
+
* specifiedByURL: 'https://example.com/odd',
|
|
1430
|
+
* serialize: (value) => {
|
|
1431
|
+
* if (typeof value !== 'number' || value % 2 === 0) {
|
|
1432
|
+
* throw new TypeError('Odd can only serialize odd numbers.');
|
|
1433
|
+
* }
|
|
1434
|
+
* return value;
|
|
1435
|
+
* },
|
|
1436
|
+
* parseValue: (value) => {
|
|
1437
|
+
* if (typeof value !== 'number' || value % 2 === 0) {
|
|
1438
|
+
* throw new TypeError('Odd can only parse odd numbers.');
|
|
1439
|
+
* }
|
|
1440
|
+
* return value;
|
|
1441
|
+
* },
|
|
1442
|
+
* parseLiteral: (ast) => {
|
|
1443
|
+
* if (ast.kind !== Kind.INT) {
|
|
1444
|
+
* throw new TypeError('Odd can only parse integer literals.');
|
|
1445
|
+
* }
|
|
1446
|
+
* const value = Number(ast.value);
|
|
1447
|
+
* if (value % 2 === 0) {
|
|
1448
|
+
* throw new TypeError('Odd can only parse odd integer literals.');
|
|
1449
|
+
* }
|
|
1450
|
+
* return value;
|
|
1451
|
+
* },
|
|
1452
|
+
* extensions: { numeric: true },
|
|
1453
|
+
* astNode: document.definitions[0],
|
|
1454
|
+
* extensionASTNodes: [ document.definitions[1] ],
|
|
1455
|
+
* });
|
|
1456
|
+
*
|
|
1457
|
+
* Odd.description; // => 'Odd integer values.'
|
|
1458
|
+
* Odd.specifiedByURL; // => 'https://example.com/odd'
|
|
1459
|
+
* Odd.serialize(3); // => 3
|
|
1460
|
+
* Odd.parseValue(5); // => 5
|
|
1461
|
+
* Odd.extensions; // => { numeric: true }
|
|
1462
|
+
* ```
|
|
1463
|
+
*/
|
|
409
1464
|
constructor(config) {
|
|
410
1465
|
var _config$parseValue,
|
|
411
1466
|
_config$serialize,
|
|
@@ -461,10 +1516,35 @@ export class GraphQLScalarType {
|
|
|
461
1516
|
);
|
|
462
1517
|
}
|
|
463
1518
|
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
1521
|
+
* @returns The built-in string tag for this object.
|
|
1522
|
+
*/
|
|
464
1523
|
|
|
465
1524
|
get [Symbol.toStringTag]() {
|
|
466
1525
|
return 'GraphQLScalarType';
|
|
467
1526
|
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Returns a normalized configuration object for this object.
|
|
1529
|
+
* @returns A configuration object that can be used to recreate this object.
|
|
1530
|
+
* @example
|
|
1531
|
+
* ```ts
|
|
1532
|
+
* import { GraphQLScalarType } from 'graphql/type';
|
|
1533
|
+
*
|
|
1534
|
+
* const Url = new GraphQLScalarType({
|
|
1535
|
+
* name: 'Url',
|
|
1536
|
+
* description: 'An absolute URL string.',
|
|
1537
|
+
* specifiedByURL: 'https://url.spec.whatwg.org/',
|
|
1538
|
+
* });
|
|
1539
|
+
*
|
|
1540
|
+
* const config = Url.toConfig();
|
|
1541
|
+
* const UrlCopy = new GraphQLScalarType(config);
|
|
1542
|
+
*
|
|
1543
|
+
* config.name; // => 'Url'
|
|
1544
|
+
* config.specifiedByURL; // => 'https://url.spec.whatwg.org/'
|
|
1545
|
+
* UrlCopy.name; // => Url.name
|
|
1546
|
+
* ```
|
|
1547
|
+
*/
|
|
468
1548
|
|
|
469
1549
|
toConfig() {
|
|
470
1550
|
return {
|
|
@@ -479,24 +1559,54 @@ export class GraphQLScalarType {
|
|
|
479
1559
|
extensionASTNodes: this.extensionASTNodes,
|
|
480
1560
|
};
|
|
481
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Returns the schema coordinate identifying this scalar type.
|
|
1564
|
+
* @returns The schema coordinate for this scalar type.
|
|
1565
|
+
* @example
|
|
1566
|
+
* ```ts
|
|
1567
|
+
* import { GraphQLScalarType } from 'graphql/type';
|
|
1568
|
+
*
|
|
1569
|
+
* const DateTime = new GraphQLScalarType({ name: 'DateTime' });
|
|
1570
|
+
*
|
|
1571
|
+
* DateTime.toString(); // => 'DateTime'
|
|
1572
|
+
* String(DateTime); // => 'DateTime'
|
|
1573
|
+
* ```
|
|
1574
|
+
*/
|
|
482
1575
|
|
|
483
1576
|
toString() {
|
|
484
1577
|
return this.name;
|
|
485
1578
|
}
|
|
1579
|
+
/**
|
|
1580
|
+
* Returns the JSON representation used when this object is serialized.
|
|
1581
|
+
* @returns The JSON-serializable representation.
|
|
1582
|
+
* @example
|
|
1583
|
+
* ```ts
|
|
1584
|
+
* import { GraphQLScalarType } from 'graphql/type';
|
|
1585
|
+
*
|
|
1586
|
+
* const DateTime = new GraphQLScalarType({ name: 'DateTime' });
|
|
1587
|
+
*
|
|
1588
|
+
* DateTime.toJSON(); // => 'DateTime'
|
|
1589
|
+
* JSON.stringify({ type: DateTime }); // => '{"type":"DateTime"}'
|
|
1590
|
+
* ```
|
|
1591
|
+
*/
|
|
486
1592
|
|
|
487
1593
|
toJSON() {
|
|
488
1594
|
return this.toString();
|
|
489
1595
|
}
|
|
490
1596
|
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Serializes a runtime value as a scalar output value.
|
|
1599
|
+
* @typeParam TExternal - The serialized representation returned for GraphQL results.
|
|
1600
|
+
*/
|
|
491
1601
|
|
|
492
1602
|
/**
|
|
493
1603
|
* Object Type Definition
|
|
494
1604
|
*
|
|
495
1605
|
* Almost all of the GraphQL types you define will be object types. Object types
|
|
496
1606
|
* have a name, but most importantly describe their fields.
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
1607
|
+
* @typeParam TSource - Source object type passed to resolvers.
|
|
1608
|
+
* @typeParam TContext - Context object type passed to resolvers.
|
|
1609
|
+
* @example
|
|
500
1610
|
* ```ts
|
|
501
1611
|
* const AddressType = new GraphQLObjectType({
|
|
502
1612
|
* name: 'Address',
|
|
@@ -505,20 +1615,18 @@ export class GraphQLScalarType {
|
|
|
505
1615
|
* number: { type: GraphQLInt },
|
|
506
1616
|
* formatted: {
|
|
507
1617
|
* type: GraphQLString,
|
|
508
|
-
* resolve(obj) {
|
|
1618
|
+
* resolve: (obj) => {
|
|
509
1619
|
* return obj.number + ' ' + obj.street
|
|
510
1620
|
* }
|
|
511
1621
|
* }
|
|
512
1622
|
* }
|
|
513
1623
|
* });
|
|
514
1624
|
* ```
|
|
515
|
-
*
|
|
1625
|
+
* @example
|
|
516
1626
|
* When two types need to refer to each other, or a type needs to refer to
|
|
517
1627
|
* itself in a field, you can use a function expression (aka a closure or a
|
|
518
1628
|
* thunk) to supply the fields lazily.
|
|
519
1629
|
*
|
|
520
|
-
* Example:
|
|
521
|
-
*
|
|
522
1630
|
* ```ts
|
|
523
1631
|
* const PersonType = new GraphQLObjectType({
|
|
524
1632
|
* name: 'Person',
|
|
@@ -530,6 +1638,118 @@ export class GraphQLScalarType {
|
|
|
530
1638
|
* ```
|
|
531
1639
|
*/
|
|
532
1640
|
export class GraphQLObjectType {
|
|
1641
|
+
/** The GraphQL name for this schema element. */
|
|
1642
|
+
|
|
1643
|
+
/** Human-readable description for this schema element, if provided. */
|
|
1644
|
+
|
|
1645
|
+
/** Predicate used to determine whether a runtime value belongs to this object type. */
|
|
1646
|
+
|
|
1647
|
+
/** Extension fields to include in the formatted result. */
|
|
1648
|
+
|
|
1649
|
+
/** AST node from which this schema element was built, if available. */
|
|
1650
|
+
|
|
1651
|
+
/** AST extension nodes applied to this schema element. */
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* Creates a GraphQLObjectType instance.
|
|
1655
|
+
* @param config - Configuration describing this object.
|
|
1656
|
+
* @example
|
|
1657
|
+
* ```ts
|
|
1658
|
+
* // Configure an object type with interfaces, fields, arguments, and metadata.
|
|
1659
|
+
* import { parse } from 'graphql/language';
|
|
1660
|
+
* import {
|
|
1661
|
+
* GraphQLID,
|
|
1662
|
+
* GraphQLInterfaceType,
|
|
1663
|
+
* GraphQLNonNull,
|
|
1664
|
+
* GraphQLObjectType,
|
|
1665
|
+
* GraphQLString,
|
|
1666
|
+
* } from 'graphql/type';
|
|
1667
|
+
*
|
|
1668
|
+
* const document = parse(`
|
|
1669
|
+
* type User implements Node {
|
|
1670
|
+
* id: ID!
|
|
1671
|
+
* name(format: String = "short"): String
|
|
1672
|
+
* }
|
|
1673
|
+
*
|
|
1674
|
+
* extend type User {
|
|
1675
|
+
* displayName: String
|
|
1676
|
+
* }
|
|
1677
|
+
* `);
|
|
1678
|
+
* const definition = document.definitions[0];
|
|
1679
|
+
* const nameField = definition.fields[1];
|
|
1680
|
+
* const formatArg = nameField.arguments[0];
|
|
1681
|
+
*
|
|
1682
|
+
* const Node = new GraphQLInterfaceType({
|
|
1683
|
+
* name: 'Node',
|
|
1684
|
+
* fields: {
|
|
1685
|
+
* id: { type: new GraphQLNonNull(GraphQLID) },
|
|
1686
|
+
* },
|
|
1687
|
+
* });
|
|
1688
|
+
*
|
|
1689
|
+
* const User = new GraphQLObjectType({
|
|
1690
|
+
* name: 'User',
|
|
1691
|
+
* description: 'A registered user.',
|
|
1692
|
+
* interfaces: [Node],
|
|
1693
|
+
* fields: {
|
|
1694
|
+
* id: { type: new GraphQLNonNull(GraphQLID) },
|
|
1695
|
+
* name: {
|
|
1696
|
+
* description: 'The formatted user name.',
|
|
1697
|
+
* type: GraphQLString,
|
|
1698
|
+
* args: {
|
|
1699
|
+
* format: {
|
|
1700
|
+
* description: 'Controls the name format.',
|
|
1701
|
+
* type: GraphQLString,
|
|
1702
|
+
* defaultValue: 'short',
|
|
1703
|
+
* deprecationReason: 'Use locale instead.',
|
|
1704
|
+
* extensions: { public: true },
|
|
1705
|
+
* astNode: formatArg,
|
|
1706
|
+
* },
|
|
1707
|
+
* },
|
|
1708
|
+
* resolve: (user, { format }) => {
|
|
1709
|
+
* return format === 'long' ? user.fullName : user.name;
|
|
1710
|
+
* },
|
|
1711
|
+
* deprecationReason: 'Use displayName.',
|
|
1712
|
+
* extensions: { cacheSeconds: 60 },
|
|
1713
|
+
* astNode: nameField,
|
|
1714
|
+
* },
|
|
1715
|
+
* },
|
|
1716
|
+
* isTypeOf: (value) => {
|
|
1717
|
+
* return typeof value === 'object' && value != null && 'id' in value;
|
|
1718
|
+
* },
|
|
1719
|
+
* extensions: { entity: 'User' },
|
|
1720
|
+
* astNode: definition,
|
|
1721
|
+
* extensionASTNodes: [ document.definitions[1] ],
|
|
1722
|
+
* });
|
|
1723
|
+
*
|
|
1724
|
+
* User.name; // => 'User'
|
|
1725
|
+
* User.getInterfaces(); // => [Node]
|
|
1726
|
+
* Object.keys(User.getFields()); // => ['id', 'name']
|
|
1727
|
+
* User.getFields().name.args[0].defaultValue; // => 'short'
|
|
1728
|
+
* User.extensions; // => { entity: 'User' }
|
|
1729
|
+
* ```
|
|
1730
|
+
* @example
|
|
1731
|
+
* ```ts
|
|
1732
|
+
* // This variant configures a subscription field with subscribe and resolve functions.
|
|
1733
|
+
* import { GraphQLObjectType, GraphQLString } from 'graphql/type';
|
|
1734
|
+
*
|
|
1735
|
+
* const Subscription = new GraphQLObjectType({
|
|
1736
|
+
* name: 'Subscription',
|
|
1737
|
+
* fields: {
|
|
1738
|
+
* greeting: {
|
|
1739
|
+
* type: GraphQLString,
|
|
1740
|
+
* subscribe: async function* () {
|
|
1741
|
+
* yield { greeting: 'Hello!' };
|
|
1742
|
+
* },
|
|
1743
|
+
* resolve: (event) => {
|
|
1744
|
+
* return event.greeting;
|
|
1745
|
+
* },
|
|
1746
|
+
* },
|
|
1747
|
+
* },
|
|
1748
|
+
* });
|
|
1749
|
+
*
|
|
1750
|
+
* typeof Subscription.getFields().greeting.subscribe; // => 'function'
|
|
1751
|
+
* ```
|
|
1752
|
+
*/
|
|
533
1753
|
constructor(config) {
|
|
534
1754
|
var _config$extensionASTN2;
|
|
535
1755
|
|
|
@@ -556,10 +1776,40 @@ export class GraphQLObjectType {
|
|
|
556
1776
|
`but got: ${inspect(config.isTypeOf)}.`,
|
|
557
1777
|
);
|
|
558
1778
|
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
1781
|
+
* @returns The built-in string tag for this object.
|
|
1782
|
+
*/
|
|
559
1783
|
|
|
560
1784
|
get [Symbol.toStringTag]() {
|
|
561
1785
|
return 'GraphQLObjectType';
|
|
562
1786
|
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Returns the fields defined by this type.
|
|
1789
|
+
* @returns The fields keyed by field name.
|
|
1790
|
+
* @example
|
|
1791
|
+
* ```ts
|
|
1792
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
1793
|
+
* import { assertObjectType } from 'graphql/type';
|
|
1794
|
+
*
|
|
1795
|
+
* const schema = buildSchema(`
|
|
1796
|
+
* type User {
|
|
1797
|
+
* id: ID!
|
|
1798
|
+
* name: String
|
|
1799
|
+
* }
|
|
1800
|
+
*
|
|
1801
|
+
* type Query {
|
|
1802
|
+
* viewer: User
|
|
1803
|
+
* }
|
|
1804
|
+
* `);
|
|
1805
|
+
*
|
|
1806
|
+
* const User = assertObjectType(schema.getType('User'));
|
|
1807
|
+
* const fields = User.getFields();
|
|
1808
|
+
*
|
|
1809
|
+
* Object.keys(fields); // => ['id', 'name']
|
|
1810
|
+
* String(fields.id.type); // => 'ID!'
|
|
1811
|
+
* ```
|
|
1812
|
+
*/
|
|
563
1813
|
|
|
564
1814
|
getFields() {
|
|
565
1815
|
if (typeof this._fields === 'function') {
|
|
@@ -568,6 +1818,33 @@ export class GraphQLObjectType {
|
|
|
568
1818
|
|
|
569
1819
|
return this._fields;
|
|
570
1820
|
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Returns the interfaces implemented by this type.
|
|
1823
|
+
* @returns The implemented interfaces.
|
|
1824
|
+
* @example
|
|
1825
|
+
* ```ts
|
|
1826
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
1827
|
+
* import { assertObjectType } from 'graphql/type';
|
|
1828
|
+
*
|
|
1829
|
+
* const schema = buildSchema(`
|
|
1830
|
+
* interface Node {
|
|
1831
|
+
* id: ID!
|
|
1832
|
+
* }
|
|
1833
|
+
*
|
|
1834
|
+
* type User implements Node {
|
|
1835
|
+
* id: ID!
|
|
1836
|
+
* }
|
|
1837
|
+
*
|
|
1838
|
+
* type Query {
|
|
1839
|
+
* viewer: User
|
|
1840
|
+
* }
|
|
1841
|
+
* `);
|
|
1842
|
+
*
|
|
1843
|
+
* const User = assertObjectType(schema.getType('User'));
|
|
1844
|
+
*
|
|
1845
|
+
* User.getInterfaces().map((type) => type.name); // => ['Node']
|
|
1846
|
+
* ```
|
|
1847
|
+
*/
|
|
571
1848
|
|
|
572
1849
|
getInterfaces() {
|
|
573
1850
|
if (typeof this._interfaces === 'function') {
|
|
@@ -576,6 +1853,27 @@ export class GraphQLObjectType {
|
|
|
576
1853
|
|
|
577
1854
|
return this._interfaces;
|
|
578
1855
|
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Returns a normalized configuration object for this object.
|
|
1858
|
+
* @returns A configuration object that can be used to recreate this object.
|
|
1859
|
+
* @example
|
|
1860
|
+
* ```ts
|
|
1861
|
+
* import { GraphQLObjectType, GraphQLString } from 'graphql/type';
|
|
1862
|
+
*
|
|
1863
|
+
* const User = new GraphQLObjectType({
|
|
1864
|
+
* name: 'User',
|
|
1865
|
+
* fields: {
|
|
1866
|
+
* name: { type: GraphQLString },
|
|
1867
|
+
* },
|
|
1868
|
+
* });
|
|
1869
|
+
*
|
|
1870
|
+
* const config = User.toConfig();
|
|
1871
|
+
* const UserCopy = new GraphQLObjectType(config);
|
|
1872
|
+
*
|
|
1873
|
+
* config.fields.name.type; // => GraphQLString
|
|
1874
|
+
* UserCopy.getFields().name.type; // => GraphQLString
|
|
1875
|
+
* ```
|
|
1876
|
+
*/
|
|
579
1877
|
|
|
580
1878
|
toConfig() {
|
|
581
1879
|
return {
|
|
@@ -589,10 +1887,49 @@ export class GraphQLObjectType {
|
|
|
589
1887
|
extensionASTNodes: this.extensionASTNodes,
|
|
590
1888
|
};
|
|
591
1889
|
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Returns the schema coordinate identifying this object type.
|
|
1892
|
+
* @returns The schema coordinate for this object type.
|
|
1893
|
+
* @example
|
|
1894
|
+
* ```ts
|
|
1895
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
1896
|
+
* import { assertObjectType } from 'graphql/type';
|
|
1897
|
+
*
|
|
1898
|
+
* const schema = buildSchema(`
|
|
1899
|
+
* type User {
|
|
1900
|
+
* name: String
|
|
1901
|
+
* }
|
|
1902
|
+
*
|
|
1903
|
+
* type Query {
|
|
1904
|
+
* viewer: User
|
|
1905
|
+
* }
|
|
1906
|
+
* `);
|
|
1907
|
+
*
|
|
1908
|
+
* const User = assertObjectType(schema.getType('User'));
|
|
1909
|
+
*
|
|
1910
|
+
* User.toString(); // => 'User'
|
|
1911
|
+
* ```
|
|
1912
|
+
*/
|
|
592
1913
|
|
|
593
1914
|
toString() {
|
|
594
1915
|
return this.name;
|
|
595
1916
|
}
|
|
1917
|
+
/**
|
|
1918
|
+
* Returns the JSON representation used when this object is serialized.
|
|
1919
|
+
* @returns The JSON-serializable representation.
|
|
1920
|
+
* @example
|
|
1921
|
+
* ```ts
|
|
1922
|
+
* import { GraphQLObjectType, GraphQLString } from 'graphql/type';
|
|
1923
|
+
*
|
|
1924
|
+
* const User = new GraphQLObjectType({
|
|
1925
|
+
* name: 'User',
|
|
1926
|
+
* fields: { name: { type: GraphQLString } },
|
|
1927
|
+
* });
|
|
1928
|
+
*
|
|
1929
|
+
* User.toJSON(); // => 'User'
|
|
1930
|
+
* JSON.stringify({ type: User }); // => '{"type":"User"}'
|
|
1931
|
+
* ```
|
|
1932
|
+
*/
|
|
596
1933
|
|
|
597
1934
|
toJSON() {
|
|
598
1935
|
return this.toString();
|
|
@@ -661,6 +1998,7 @@ function defineFieldMap(config) {
|
|
|
661
1998
|
};
|
|
662
1999
|
});
|
|
663
2000
|
}
|
|
2001
|
+
/** @internal */
|
|
664
2002
|
|
|
665
2003
|
export function defineArguments(config) {
|
|
666
2004
|
return Object.entries(config).map(([argName, argConfig]) => ({
|
|
@@ -690,9 +2028,7 @@ function fieldsToFieldsConfig(fields) {
|
|
|
690
2028
|
astNode: field.astNode,
|
|
691
2029
|
}));
|
|
692
2030
|
}
|
|
693
|
-
/**
|
|
694
|
-
* @internal
|
|
695
|
-
*/
|
|
2031
|
+
/** @internal */
|
|
696
2032
|
|
|
697
2033
|
export function argsToArgsConfig(args) {
|
|
698
2034
|
return keyValMap(
|
|
@@ -708,9 +2044,46 @@ export function argsToArgsConfig(args) {
|
|
|
708
2044
|
}),
|
|
709
2045
|
);
|
|
710
2046
|
}
|
|
2047
|
+
/**
|
|
2048
|
+
* Configuration used to construct a GraphQLObjectType.
|
|
2049
|
+
* @typeParam TSource - Source object type passed to resolvers.
|
|
2050
|
+
* @typeParam TContext - Context object type passed to resolvers.
|
|
2051
|
+
*/
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* Returns true when the argument is non-null and has no default value.
|
|
2055
|
+
* @param arg - The argument definition to inspect.
|
|
2056
|
+
* @returns True when the argument is non-null and has no default value.
|
|
2057
|
+
* @example
|
|
2058
|
+
* ```ts
|
|
2059
|
+
* import {
|
|
2060
|
+
* GraphQLInt,
|
|
2061
|
+
* GraphQLNonNull,
|
|
2062
|
+
* GraphQLString,
|
|
2063
|
+
* isRequiredArgument,
|
|
2064
|
+
* } from 'graphql/type';
|
|
2065
|
+
*
|
|
2066
|
+
* const requiredArgument = { name: 'id', type: new GraphQLNonNull(GraphQLInt) };
|
|
2067
|
+
* const optionalArgument = { name: 'name', type: GraphQLString };
|
|
2068
|
+
* const argumentWithDefault = {
|
|
2069
|
+
* name: 'limit',
|
|
2070
|
+
* type: new GraphQLNonNull(GraphQLInt),
|
|
2071
|
+
* defaultValue: 10,
|
|
2072
|
+
* };
|
|
2073
|
+
*
|
|
2074
|
+
* isRequiredArgument(requiredArgument); // => true
|
|
2075
|
+
* isRequiredArgument(optionalArgument); // => false
|
|
2076
|
+
* isRequiredArgument(argumentWithDefault); // => false
|
|
2077
|
+
* ```
|
|
2078
|
+
*/
|
|
711
2079
|
export function isRequiredArgument(arg) {
|
|
712
2080
|
return isNonNullType(arg.type) && arg.defaultValue === undefined;
|
|
713
2081
|
}
|
|
2082
|
+
/**
|
|
2083
|
+
* A map of field names to resolved field definitions.
|
|
2084
|
+
* @typeParam TSource - Source object type passed to resolvers.
|
|
2085
|
+
* @typeParam TContext - Context object type passed to resolvers.
|
|
2086
|
+
*/
|
|
714
2087
|
|
|
715
2088
|
/**
|
|
716
2089
|
* Interface Type Definition
|
|
@@ -719,9 +2092,7 @@ export function isRequiredArgument(arg) {
|
|
|
719
2092
|
* is used to describe what types are possible, what fields are in common across
|
|
720
2093
|
* all types, as well as a function to determine which type is actually used
|
|
721
2094
|
* when the field is resolved.
|
|
722
|
-
*
|
|
723
|
-
* Example:
|
|
724
|
-
*
|
|
2095
|
+
* @example
|
|
725
2096
|
* ```ts
|
|
726
2097
|
* const EntityType = new GraphQLInterfaceType({
|
|
727
2098
|
* name: 'Entity',
|
|
@@ -732,6 +2103,70 @@ export function isRequiredArgument(arg) {
|
|
|
732
2103
|
* ```
|
|
733
2104
|
*/
|
|
734
2105
|
export class GraphQLInterfaceType {
|
|
2106
|
+
/** The GraphQL name for this schema element. */
|
|
2107
|
+
|
|
2108
|
+
/** Human-readable description for this schema element, if provided. */
|
|
2109
|
+
|
|
2110
|
+
/** Function that resolves the concrete object type for this abstract type. */
|
|
2111
|
+
|
|
2112
|
+
/** Extension fields to include in the formatted result. */
|
|
2113
|
+
|
|
2114
|
+
/** AST node from which this schema element was built, if available. */
|
|
2115
|
+
|
|
2116
|
+
/** AST extension nodes applied to this schema element. */
|
|
2117
|
+
|
|
2118
|
+
/**
|
|
2119
|
+
* Creates a GraphQLInterfaceType instance.
|
|
2120
|
+
* @param config - Configuration describing this object.
|
|
2121
|
+
* @example
|
|
2122
|
+
* ```ts
|
|
2123
|
+
* import { parse } from 'graphql/language';
|
|
2124
|
+
* import { GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from 'graphql/type';
|
|
2125
|
+
*
|
|
2126
|
+
* const document = parse(`
|
|
2127
|
+
* interface Node {
|
|
2128
|
+
* id: ID!
|
|
2129
|
+
* }
|
|
2130
|
+
*
|
|
2131
|
+
* interface Resource implements Node {
|
|
2132
|
+
* id: ID!
|
|
2133
|
+
* }
|
|
2134
|
+
*
|
|
2135
|
+
* extend interface Resource {
|
|
2136
|
+
* url: String
|
|
2137
|
+
* }
|
|
2138
|
+
* `);
|
|
2139
|
+
*
|
|
2140
|
+
* const Node = new GraphQLInterfaceType({
|
|
2141
|
+
* name: 'Node',
|
|
2142
|
+
* fields: {
|
|
2143
|
+
* id: { type: new GraphQLNonNull(GraphQLID) },
|
|
2144
|
+
* },
|
|
2145
|
+
* });
|
|
2146
|
+
*
|
|
2147
|
+
* const Resource = new GraphQLInterfaceType({
|
|
2148
|
+
* name: 'Resource',
|
|
2149
|
+
* description: 'An addressable resource.',
|
|
2150
|
+
* interfaces: [Node],
|
|
2151
|
+
* fields: {
|
|
2152
|
+
* id: { type: new GraphQLNonNull(GraphQLID) },
|
|
2153
|
+
* },
|
|
2154
|
+
* resolveType: (value) => {
|
|
2155
|
+
* return typeof value === 'object' && value != null && 'url' in value
|
|
2156
|
+
* ? 'WebPage'
|
|
2157
|
+
* : null;
|
|
2158
|
+
* },
|
|
2159
|
+
* extensions: { abstract: true },
|
|
2160
|
+
* astNode: document.definitions[1],
|
|
2161
|
+
* extensionASTNodes: [ document.definitions[2] ],
|
|
2162
|
+
* });
|
|
2163
|
+
*
|
|
2164
|
+
* Resource.name; // => 'Resource'
|
|
2165
|
+
* Resource.getInterfaces(); // => [Node]
|
|
2166
|
+
* Object.keys(Resource.getFields()); // => ['id']
|
|
2167
|
+
* Resource.extensions; // => { abstract: true }
|
|
2168
|
+
* ```
|
|
2169
|
+
*/
|
|
735
2170
|
constructor(config) {
|
|
736
2171
|
var _config$extensionASTN3;
|
|
737
2172
|
|
|
@@ -755,10 +2190,43 @@ export class GraphQLInterfaceType {
|
|
|
755
2190
|
`but got: ${inspect(config.resolveType)}.`,
|
|
756
2191
|
);
|
|
757
2192
|
}
|
|
2193
|
+
/**
|
|
2194
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
2195
|
+
* @returns The built-in string tag for this object.
|
|
2196
|
+
*/
|
|
758
2197
|
|
|
759
2198
|
get [Symbol.toStringTag]() {
|
|
760
2199
|
return 'GraphQLInterfaceType';
|
|
761
2200
|
}
|
|
2201
|
+
/**
|
|
2202
|
+
* Returns the fields defined by this type.
|
|
2203
|
+
* @returns The fields keyed by field name.
|
|
2204
|
+
* @example
|
|
2205
|
+
* ```ts
|
|
2206
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2207
|
+
* import { assertInterfaceType } from 'graphql/type';
|
|
2208
|
+
*
|
|
2209
|
+
* const schema = buildSchema(`
|
|
2210
|
+
* interface Node {
|
|
2211
|
+
* id: ID!
|
|
2212
|
+
* }
|
|
2213
|
+
*
|
|
2214
|
+
* type User implements Node {
|
|
2215
|
+
* id: ID!
|
|
2216
|
+
* }
|
|
2217
|
+
*
|
|
2218
|
+
* type Query {
|
|
2219
|
+
* node: Node
|
|
2220
|
+
* }
|
|
2221
|
+
* `);
|
|
2222
|
+
*
|
|
2223
|
+
* const Node = assertInterfaceType(schema.getType('Node'));
|
|
2224
|
+
* const fields = Node.getFields();
|
|
2225
|
+
*
|
|
2226
|
+
* Object.keys(fields); // => ['id']
|
|
2227
|
+
* String(fields.id.type); // => 'ID!'
|
|
2228
|
+
* ```
|
|
2229
|
+
*/
|
|
762
2230
|
|
|
763
2231
|
getFields() {
|
|
764
2232
|
if (typeof this._fields === 'function') {
|
|
@@ -767,6 +2235,39 @@ export class GraphQLInterfaceType {
|
|
|
767
2235
|
|
|
768
2236
|
return this._fields;
|
|
769
2237
|
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Returns the interfaces implemented by this type.
|
|
2240
|
+
* @returns The implemented interfaces.
|
|
2241
|
+
* @example
|
|
2242
|
+
* ```ts
|
|
2243
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2244
|
+
* import { assertInterfaceType } from 'graphql/type';
|
|
2245
|
+
*
|
|
2246
|
+
* const schema = buildSchema(`
|
|
2247
|
+
* interface Resource {
|
|
2248
|
+
* url: String!
|
|
2249
|
+
* }
|
|
2250
|
+
*
|
|
2251
|
+
* interface Image implements Resource {
|
|
2252
|
+
* url: String!
|
|
2253
|
+
* width: Int
|
|
2254
|
+
* }
|
|
2255
|
+
*
|
|
2256
|
+
* type Photo implements Resource & Image {
|
|
2257
|
+
* url: String!
|
|
2258
|
+
* width: Int
|
|
2259
|
+
* }
|
|
2260
|
+
*
|
|
2261
|
+
* type Query {
|
|
2262
|
+
* image: Image
|
|
2263
|
+
* }
|
|
2264
|
+
* `);
|
|
2265
|
+
*
|
|
2266
|
+
* const Image = assertInterfaceType(schema.getType('Image'));
|
|
2267
|
+
*
|
|
2268
|
+
* Image.getInterfaces().map((type) => type.name); // => ['Resource']
|
|
2269
|
+
* ```
|
|
2270
|
+
*/
|
|
770
2271
|
|
|
771
2272
|
getInterfaces() {
|
|
772
2273
|
if (typeof this._interfaces === 'function') {
|
|
@@ -775,6 +2276,27 @@ export class GraphQLInterfaceType {
|
|
|
775
2276
|
|
|
776
2277
|
return this._interfaces;
|
|
777
2278
|
}
|
|
2279
|
+
/**
|
|
2280
|
+
* Returns a normalized configuration object for this object.
|
|
2281
|
+
* @returns A configuration object that can be used to recreate this object.
|
|
2282
|
+
* @example
|
|
2283
|
+
* ```ts
|
|
2284
|
+
* import { GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from 'graphql/type';
|
|
2285
|
+
*
|
|
2286
|
+
* const Node = new GraphQLInterfaceType({
|
|
2287
|
+
* name: 'Node',
|
|
2288
|
+
* fields: {
|
|
2289
|
+
* id: { type: new GraphQLNonNull(GraphQLID) },
|
|
2290
|
+
* },
|
|
2291
|
+
* });
|
|
2292
|
+
*
|
|
2293
|
+
* const config = Node.toConfig();
|
|
2294
|
+
* const NodeCopy = new GraphQLInterfaceType(config);
|
|
2295
|
+
*
|
|
2296
|
+
* String(config.fields.id.type); // => 'ID!'
|
|
2297
|
+
* String(NodeCopy.getFields().id.type); // => 'ID!'
|
|
2298
|
+
* ```
|
|
2299
|
+
*/
|
|
778
2300
|
|
|
779
2301
|
toConfig() {
|
|
780
2302
|
return {
|
|
@@ -788,15 +2310,63 @@ export class GraphQLInterfaceType {
|
|
|
788
2310
|
extensionASTNodes: this.extensionASTNodes,
|
|
789
2311
|
};
|
|
790
2312
|
}
|
|
2313
|
+
/**
|
|
2314
|
+
* Returns the schema coordinate identifying this interface type.
|
|
2315
|
+
* @returns The schema coordinate for this interface type.
|
|
2316
|
+
* @example
|
|
2317
|
+
* ```ts
|
|
2318
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2319
|
+
* import { assertInterfaceType } from 'graphql/type';
|
|
2320
|
+
*
|
|
2321
|
+
* const schema = buildSchema(`
|
|
2322
|
+
* interface Node {
|
|
2323
|
+
* id: ID!
|
|
2324
|
+
* }
|
|
2325
|
+
*
|
|
2326
|
+
* type User implements Node {
|
|
2327
|
+
* id: ID!
|
|
2328
|
+
* }
|
|
2329
|
+
*
|
|
2330
|
+
* type Query {
|
|
2331
|
+
* node: Node
|
|
2332
|
+
* }
|
|
2333
|
+
* `);
|
|
2334
|
+
*
|
|
2335
|
+
* const Node = assertInterfaceType(schema.getType('Node'));
|
|
2336
|
+
*
|
|
2337
|
+
* Node.toString(); // => 'Node'
|
|
2338
|
+
* ```
|
|
2339
|
+
*/
|
|
791
2340
|
|
|
792
2341
|
toString() {
|
|
793
2342
|
return this.name;
|
|
794
2343
|
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Returns the JSON representation used when this object is serialized.
|
|
2346
|
+
* @returns The JSON-serializable representation.
|
|
2347
|
+
* @example
|
|
2348
|
+
* ```ts
|
|
2349
|
+
* import { GraphQLInterfaceType, GraphQLString } from 'graphql/type';
|
|
2350
|
+
*
|
|
2351
|
+
* const Named = new GraphQLInterfaceType({
|
|
2352
|
+
* name: 'Named',
|
|
2353
|
+
* fields: { name: { type: GraphQLString } },
|
|
2354
|
+
* });
|
|
2355
|
+
*
|
|
2356
|
+
* Named.toJSON(); // => 'Named'
|
|
2357
|
+
* JSON.stringify({ type: Named }); // => '{"type":"Named"}'
|
|
2358
|
+
* ```
|
|
2359
|
+
*/
|
|
795
2360
|
|
|
796
2361
|
toJSON() {
|
|
797
2362
|
return this.toString();
|
|
798
2363
|
}
|
|
799
2364
|
}
|
|
2365
|
+
/**
|
|
2366
|
+
* Configuration used to construct a GraphQLInterfaceType.
|
|
2367
|
+
* @typeParam TSource - Source object type passed to resolvers.
|
|
2368
|
+
* @typeParam TContext - Context object type passed to resolvers.
|
|
2369
|
+
*/
|
|
800
2370
|
|
|
801
2371
|
/**
|
|
802
2372
|
* Union Type Definition
|
|
@@ -804,14 +2374,12 @@ export class GraphQLInterfaceType {
|
|
|
804
2374
|
* When a field can return one of a heterogeneous set of types, a Union type
|
|
805
2375
|
* is used to describe what types are possible as well as providing a function
|
|
806
2376
|
* to determine which type is actually used when the field is resolved.
|
|
807
|
-
*
|
|
808
|
-
* Example:
|
|
809
|
-
*
|
|
2377
|
+
* @example
|
|
810
2378
|
* ```ts
|
|
811
2379
|
* const PetType = new GraphQLUnionType({
|
|
812
2380
|
* name: 'Pet',
|
|
813
|
-
* types: [
|
|
814
|
-
* resolveType(value) {
|
|
2381
|
+
* types: [DogType, CatType],
|
|
2382
|
+
* resolveType: (value) => {
|
|
815
2383
|
* if (value instanceof Dog) {
|
|
816
2384
|
* return DogType;
|
|
817
2385
|
* }
|
|
@@ -823,6 +2391,60 @@ export class GraphQLInterfaceType {
|
|
|
823
2391
|
* ```
|
|
824
2392
|
*/
|
|
825
2393
|
export class GraphQLUnionType {
|
|
2394
|
+
/** The GraphQL name for this schema element. */
|
|
2395
|
+
|
|
2396
|
+
/** Human-readable description for this schema element, if provided. */
|
|
2397
|
+
|
|
2398
|
+
/** Function that resolves the concrete object type for this abstract type. */
|
|
2399
|
+
|
|
2400
|
+
/** Extension fields to include in the formatted result. */
|
|
2401
|
+
|
|
2402
|
+
/** AST node from which this schema element was built, if available. */
|
|
2403
|
+
|
|
2404
|
+
/** AST extension nodes applied to this schema element. */
|
|
2405
|
+
|
|
2406
|
+
/**
|
|
2407
|
+
* Creates a GraphQLUnionType instance.
|
|
2408
|
+
* @param config - Configuration describing this object.
|
|
2409
|
+
* @example
|
|
2410
|
+
* ```ts
|
|
2411
|
+
* import { parse } from 'graphql/language';
|
|
2412
|
+
* import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
|
|
2413
|
+
*
|
|
2414
|
+
* const document = parse(`
|
|
2415
|
+
* union Media = Photo | Video
|
|
2416
|
+
*
|
|
2417
|
+
* extend union Media = Audio
|
|
2418
|
+
* `);
|
|
2419
|
+
*
|
|
2420
|
+
* const Photo = new GraphQLObjectType({
|
|
2421
|
+
* name: 'Photo',
|
|
2422
|
+
* fields: { url: { type: GraphQLString } },
|
|
2423
|
+
* });
|
|
2424
|
+
* const Video = new GraphQLObjectType({
|
|
2425
|
+
* name: 'Video',
|
|
2426
|
+
* fields: { url: { type: GraphQLString } },
|
|
2427
|
+
* });
|
|
2428
|
+
*
|
|
2429
|
+
* const Media = new GraphQLUnionType({
|
|
2430
|
+
* name: 'Media',
|
|
2431
|
+
* description: 'Media that can appear in a search result.',
|
|
2432
|
+
* types: [Photo, Video],
|
|
2433
|
+
* resolveType: (value) => {
|
|
2434
|
+
* return typeof value === 'object' && value != null && 'duration' in value
|
|
2435
|
+
* ? 'Video'
|
|
2436
|
+
* : 'Photo';
|
|
2437
|
+
* },
|
|
2438
|
+
* extensions: { searchable: true },
|
|
2439
|
+
* astNode: document.definitions[0],
|
|
2440
|
+
* extensionASTNodes: [ document.definitions[1] ],
|
|
2441
|
+
* });
|
|
2442
|
+
*
|
|
2443
|
+
* Media.description; // => 'Media that can appear in a search result.'
|
|
2444
|
+
* Media.getTypes().map((type) => type.name); // => ['Photo', 'Video']
|
|
2445
|
+
* Media.extensions; // => { searchable: true }
|
|
2446
|
+
* ```
|
|
2447
|
+
*/
|
|
826
2448
|
constructor(config) {
|
|
827
2449
|
var _config$extensionASTN4;
|
|
828
2450
|
|
|
@@ -845,10 +2467,43 @@ export class GraphQLUnionType {
|
|
|
845
2467
|
`but got: ${inspect(config.resolveType)}.`,
|
|
846
2468
|
);
|
|
847
2469
|
}
|
|
2470
|
+
/**
|
|
2471
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
2472
|
+
* @returns The built-in string tag for this object.
|
|
2473
|
+
*/
|
|
848
2474
|
|
|
849
2475
|
get [Symbol.toStringTag]() {
|
|
850
2476
|
return 'GraphQLUnionType';
|
|
851
2477
|
}
|
|
2478
|
+
/**
|
|
2479
|
+
* Returns the object types included in this union.
|
|
2480
|
+
* @returns The union member object types.
|
|
2481
|
+
* @example
|
|
2482
|
+
* ```ts
|
|
2483
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2484
|
+
* import { assertUnionType } from 'graphql/type';
|
|
2485
|
+
*
|
|
2486
|
+
* const schema = buildSchema(`
|
|
2487
|
+
* type Photo {
|
|
2488
|
+
* url: String!
|
|
2489
|
+
* }
|
|
2490
|
+
*
|
|
2491
|
+
* type Video {
|
|
2492
|
+
* url: String!
|
|
2493
|
+
* }
|
|
2494
|
+
*
|
|
2495
|
+
* union Media = Photo | Video
|
|
2496
|
+
*
|
|
2497
|
+
* type Query {
|
|
2498
|
+
* media: [Media]
|
|
2499
|
+
* }
|
|
2500
|
+
* `);
|
|
2501
|
+
*
|
|
2502
|
+
* const Media = assertUnionType(schema.getType('Media'));
|
|
2503
|
+
*
|
|
2504
|
+
* Media.getTypes().map((type) => type.name); // => ['Photo', 'Video']
|
|
2505
|
+
* ```
|
|
2506
|
+
*/
|
|
852
2507
|
|
|
853
2508
|
getTypes() {
|
|
854
2509
|
if (typeof this._types === 'function') {
|
|
@@ -857,6 +2512,32 @@ export class GraphQLUnionType {
|
|
|
857
2512
|
|
|
858
2513
|
return this._types;
|
|
859
2514
|
}
|
|
2515
|
+
/**
|
|
2516
|
+
* Returns a normalized configuration object for this object.
|
|
2517
|
+
* @returns A configuration object that can be used to recreate this object.
|
|
2518
|
+
* @example
|
|
2519
|
+
* ```ts
|
|
2520
|
+
* import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
|
|
2521
|
+
*
|
|
2522
|
+
* const Photo = new GraphQLObjectType({
|
|
2523
|
+
* name: 'Photo',
|
|
2524
|
+
* fields: { url: { type: GraphQLString } },
|
|
2525
|
+
* });
|
|
2526
|
+
* const Video = new GraphQLObjectType({
|
|
2527
|
+
* name: 'Video',
|
|
2528
|
+
* fields: { url: { type: GraphQLString } },
|
|
2529
|
+
* });
|
|
2530
|
+
* const Media = new GraphQLUnionType({
|
|
2531
|
+
* name: 'Media',
|
|
2532
|
+
* types: [Photo, Video],
|
|
2533
|
+
* });
|
|
2534
|
+
*
|
|
2535
|
+
* const config = Media.toConfig();
|
|
2536
|
+
* const MediaCopy = new GraphQLUnionType(config);
|
|
2537
|
+
*
|
|
2538
|
+
* MediaCopy.getTypes().map((type) => type.name); // => ['Photo', 'Video']
|
|
2539
|
+
* ```
|
|
2540
|
+
*/
|
|
860
2541
|
|
|
861
2542
|
toConfig() {
|
|
862
2543
|
return {
|
|
@@ -869,10 +2550,55 @@ export class GraphQLUnionType {
|
|
|
869
2550
|
extensionASTNodes: this.extensionASTNodes,
|
|
870
2551
|
};
|
|
871
2552
|
}
|
|
2553
|
+
/**
|
|
2554
|
+
* Returns the schema coordinate identifying this union type.
|
|
2555
|
+
* @returns The schema coordinate for this union type.
|
|
2556
|
+
* @example
|
|
2557
|
+
* ```ts
|
|
2558
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2559
|
+
* import { assertUnionType } from 'graphql/type';
|
|
2560
|
+
*
|
|
2561
|
+
* const schema = buildSchema(`
|
|
2562
|
+
* type Photo {
|
|
2563
|
+
* url: String!
|
|
2564
|
+
* }
|
|
2565
|
+
*
|
|
2566
|
+
* union SearchResult = Photo
|
|
2567
|
+
*
|
|
2568
|
+
* type Query {
|
|
2569
|
+
* search: [SearchResult]
|
|
2570
|
+
* }
|
|
2571
|
+
* `);
|
|
2572
|
+
*
|
|
2573
|
+
* const SearchResult = assertUnionType(schema.getType('SearchResult'));
|
|
2574
|
+
*
|
|
2575
|
+
* SearchResult.toString(); // => 'SearchResult'
|
|
2576
|
+
* ```
|
|
2577
|
+
*/
|
|
872
2578
|
|
|
873
2579
|
toString() {
|
|
874
2580
|
return this.name;
|
|
875
2581
|
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Returns the JSON representation used when this object is serialized.
|
|
2584
|
+
* @returns The JSON-serializable representation.
|
|
2585
|
+
* @example
|
|
2586
|
+
* ```ts
|
|
2587
|
+
* import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
|
|
2588
|
+
*
|
|
2589
|
+
* const Photo = new GraphQLObjectType({
|
|
2590
|
+
* name: 'Photo',
|
|
2591
|
+
* fields: { url: { type: GraphQLString } },
|
|
2592
|
+
* });
|
|
2593
|
+
* const SearchResult = new GraphQLUnionType({
|
|
2594
|
+
* name: 'SearchResult',
|
|
2595
|
+
* types: [Photo],
|
|
2596
|
+
* });
|
|
2597
|
+
*
|
|
2598
|
+
* SearchResult.toJSON(); // => 'SearchResult'
|
|
2599
|
+
* JSON.stringify({ type: SearchResult }); // => '{"type":"SearchResult"}'
|
|
2600
|
+
* ```
|
|
2601
|
+
*/
|
|
876
2602
|
|
|
877
2603
|
toJSON() {
|
|
878
2604
|
return this.toString();
|
|
@@ -888,25 +2614,32 @@ function defineTypes(config) {
|
|
|
888
2614
|
);
|
|
889
2615
|
return types;
|
|
890
2616
|
}
|
|
2617
|
+
/**
|
|
2618
|
+
* Configuration used to construct a GraphQLUnionType.
|
|
2619
|
+
* @typeParam TSource - Source object type passed to resolvers.
|
|
2620
|
+
* @typeParam TContext - Context object type passed to resolvers.
|
|
2621
|
+
*/
|
|
891
2622
|
|
|
892
2623
|
/**
|
|
893
2624
|
* Enum Type Definition
|
|
894
2625
|
*
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
* Example:
|
|
900
|
-
*
|
|
2626
|
+
* Enum types define leaf values whose serialized form is one of a fixed set
|
|
2627
|
+
* of GraphQL enum names. Internally, enum values can map to any runtime value,
|
|
2628
|
+
* often integers.
|
|
2629
|
+
* @example
|
|
901
2630
|
* ```ts
|
|
2631
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
2632
|
+
*
|
|
902
2633
|
* const RGBType = new GraphQLEnumType({
|
|
903
2634
|
* name: 'RGB',
|
|
904
2635
|
* values: {
|
|
905
2636
|
* RED: { value: 0 },
|
|
906
2637
|
* GREEN: { value: 1 },
|
|
907
|
-
* BLUE: { value: 2 }
|
|
908
|
-
* }
|
|
2638
|
+
* BLUE: { value: 2 },
|
|
2639
|
+
* },
|
|
909
2640
|
* });
|
|
2641
|
+
*
|
|
2642
|
+
* RGBType.getValue('GREEN')?.value; // => 1
|
|
910
2643
|
* ```
|
|
911
2644
|
*
|
|
912
2645
|
* Note: If a value is not provided in a definition, the name of the enum value
|
|
@@ -914,6 +2647,66 @@ function defineTypes(config) {
|
|
|
914
2647
|
*/
|
|
915
2648
|
export class GraphQLEnumType {
|
|
916
2649
|
/* <T> */
|
|
2650
|
+
/** The GraphQL name for this schema element. */
|
|
2651
|
+
|
|
2652
|
+
/** Human-readable description for this schema element, if provided. */
|
|
2653
|
+
|
|
2654
|
+
/** Extension fields to include in the formatted result. */
|
|
2655
|
+
|
|
2656
|
+
/** AST node from which this schema element was built, if available. */
|
|
2657
|
+
|
|
2658
|
+
/** AST extension nodes applied to this schema element. */
|
|
2659
|
+
|
|
2660
|
+
/**
|
|
2661
|
+
* Creates a GraphQLEnumType instance.
|
|
2662
|
+
* @param config - Configuration describing this object.
|
|
2663
|
+
* @example
|
|
2664
|
+
* ```ts
|
|
2665
|
+
* import { parse } from 'graphql/language';
|
|
2666
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
2667
|
+
*
|
|
2668
|
+
* const document = parse(`
|
|
2669
|
+
* enum Episode {
|
|
2670
|
+
* NEW_HOPE
|
|
2671
|
+
* EMPIRE
|
|
2672
|
+
* JEDI
|
|
2673
|
+
* }
|
|
2674
|
+
*
|
|
2675
|
+
* extend enum Episode {
|
|
2676
|
+
* FORCE_AWAKENS
|
|
2677
|
+
* }
|
|
2678
|
+
* `);
|
|
2679
|
+
* const definition = document.definitions[0];
|
|
2680
|
+
*
|
|
2681
|
+
* const Episode = new GraphQLEnumType({
|
|
2682
|
+
* name: 'Episode',
|
|
2683
|
+
* description: 'A Star Wars film episode.',
|
|
2684
|
+
* values: {
|
|
2685
|
+
* NEW_HOPE: {
|
|
2686
|
+
* value: 4,
|
|
2687
|
+
* description: 'Released in 1977.',
|
|
2688
|
+
* extensions: { trilogy: 'original' },
|
|
2689
|
+
* astNode: definition.values[0],
|
|
2690
|
+
* },
|
|
2691
|
+
* EMPIRE: { value: 5, astNode: definition.values[1] },
|
|
2692
|
+
* JEDI: {
|
|
2693
|
+
* value: 6,
|
|
2694
|
+
* deprecationReason: 'Use RETURN_OF_THE_JEDI.',
|
|
2695
|
+
* astNode: definition.values[2],
|
|
2696
|
+
* },
|
|
2697
|
+
* },
|
|
2698
|
+
* extensions: { catalog: 'films' },
|
|
2699
|
+
* astNode: definition,
|
|
2700
|
+
* extensionASTNodes: [ document.definitions[1] ],
|
|
2701
|
+
* });
|
|
2702
|
+
*
|
|
2703
|
+
* Episode.description; // => 'A Star Wars film episode.'
|
|
2704
|
+
* Episode.serialize(5); // => 'EMPIRE'
|
|
2705
|
+
* Episode.parseValue('JEDI'); // => 6
|
|
2706
|
+
* Episode.getValue('JEDI').deprecationReason; // => 'Use RETURN_OF_THE_JEDI.'
|
|
2707
|
+
* Episode.extensions; // => { catalog: 'films' }
|
|
2708
|
+
* ```
|
|
2709
|
+
*/
|
|
917
2710
|
constructor(config) {
|
|
918
2711
|
var _config$extensionASTN5;
|
|
919
2712
|
|
|
@@ -933,10 +2726,39 @@ export class GraphQLEnumType {
|
|
|
933
2726
|
this._valueLookup = null;
|
|
934
2727
|
this._nameLookup = null;
|
|
935
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
2731
|
+
* @returns The built-in string tag for this object.
|
|
2732
|
+
*/
|
|
936
2733
|
|
|
937
2734
|
get [Symbol.toStringTag]() {
|
|
938
2735
|
return 'GraphQLEnumType';
|
|
939
2736
|
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Returns the values defined by this enum type.
|
|
2739
|
+
* @returns Enum value definitions in schema order.
|
|
2740
|
+
* @example
|
|
2741
|
+
* ```ts
|
|
2742
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2743
|
+
* import { assertEnumType } from 'graphql/type';
|
|
2744
|
+
*
|
|
2745
|
+
* const schema = buildSchema(`
|
|
2746
|
+
* enum Episode {
|
|
2747
|
+
* NEW_HOPE
|
|
2748
|
+
* EMPIRE
|
|
2749
|
+
* JEDI
|
|
2750
|
+
* }
|
|
2751
|
+
*
|
|
2752
|
+
* type Query {
|
|
2753
|
+
* episode: Episode
|
|
2754
|
+
* }
|
|
2755
|
+
* `);
|
|
2756
|
+
*
|
|
2757
|
+
* const Episode = assertEnumType(schema.getType('Episode'));
|
|
2758
|
+
*
|
|
2759
|
+
* Episode.getValues().map((value) => value.name); // => ['NEW_HOPE', 'EMPIRE', 'JEDI']
|
|
2760
|
+
* ```
|
|
2761
|
+
*/
|
|
940
2762
|
|
|
941
2763
|
getValues() {
|
|
942
2764
|
if (typeof this._values === 'function') {
|
|
@@ -945,6 +2767,32 @@ export class GraphQLEnumType {
|
|
|
945
2767
|
|
|
946
2768
|
return this._values;
|
|
947
2769
|
}
|
|
2770
|
+
/**
|
|
2771
|
+
* Returns the enum value definition for a value name.
|
|
2772
|
+
* @param name - The GraphQL name to look up.
|
|
2773
|
+
* @returns The matching enum value definition, if it exists.
|
|
2774
|
+
* @example
|
|
2775
|
+
* ```ts
|
|
2776
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2777
|
+
* import { assertEnumType } from 'graphql/type';
|
|
2778
|
+
*
|
|
2779
|
+
* const schema = buildSchema(`
|
|
2780
|
+
* enum Episode {
|
|
2781
|
+
* NEW_HOPE
|
|
2782
|
+
* EMPIRE
|
|
2783
|
+
* }
|
|
2784
|
+
*
|
|
2785
|
+
* type Query {
|
|
2786
|
+
* episode: Episode
|
|
2787
|
+
* }
|
|
2788
|
+
* `);
|
|
2789
|
+
*
|
|
2790
|
+
* const Episode = assertEnumType(schema.getType('Episode'));
|
|
2791
|
+
*
|
|
2792
|
+
* Episode.getValue('EMPIRE')?.name; // => 'EMPIRE'
|
|
2793
|
+
* Episode.getValue('JEDI'); // => undefined
|
|
2794
|
+
* ```
|
|
2795
|
+
*/
|
|
948
2796
|
|
|
949
2797
|
getValue(name) {
|
|
950
2798
|
if (this._nameLookup === null) {
|
|
@@ -953,6 +2801,27 @@ export class GraphQLEnumType {
|
|
|
953
2801
|
|
|
954
2802
|
return this._nameLookup[name];
|
|
955
2803
|
}
|
|
2804
|
+
/**
|
|
2805
|
+
* Serializes a runtime enum value as a GraphQL enum name.
|
|
2806
|
+
* @param outputValue - Runtime enum value to serialize.
|
|
2807
|
+
* @returns The GraphQL enum name for the runtime value.
|
|
2808
|
+
* @example
|
|
2809
|
+
* ```ts
|
|
2810
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
2811
|
+
*
|
|
2812
|
+
* const RGB = new GraphQLEnumType({
|
|
2813
|
+
* name: 'RGB',
|
|
2814
|
+
* values: {
|
|
2815
|
+
* RED: { value: 0 },
|
|
2816
|
+
* GREEN: { value: 1 },
|
|
2817
|
+
* BLUE: { value: 2 },
|
|
2818
|
+
* },
|
|
2819
|
+
* });
|
|
2820
|
+
*
|
|
2821
|
+
* RGB.serialize(1); // => 'GREEN'
|
|
2822
|
+
* RGB.serialize(3); // throws an error
|
|
2823
|
+
* ```
|
|
2824
|
+
*/
|
|
956
2825
|
|
|
957
2826
|
serialize(outputValue) {
|
|
958
2827
|
if (this._valueLookup === null) {
|
|
@@ -971,6 +2840,28 @@ export class GraphQLEnumType {
|
|
|
971
2840
|
|
|
972
2841
|
return enumValue.name;
|
|
973
2842
|
}
|
|
2843
|
+
/**
|
|
2844
|
+
* Parses a GraphQL enum name from variable input.
|
|
2845
|
+
* @param inputValue - Runtime input value to parse.
|
|
2846
|
+
* @returns The internal enum value represented by the input name.
|
|
2847
|
+
* @example
|
|
2848
|
+
* ```ts
|
|
2849
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
2850
|
+
*
|
|
2851
|
+
* const RGB = new GraphQLEnumType({
|
|
2852
|
+
* name: 'RGB',
|
|
2853
|
+
* values: {
|
|
2854
|
+
* RED: { value: 0 },
|
|
2855
|
+
* GREEN: { value: 1 },
|
|
2856
|
+
* BLUE: { value: 2 },
|
|
2857
|
+
* },
|
|
2858
|
+
* });
|
|
2859
|
+
*
|
|
2860
|
+
* RGB.parseValue('BLUE'); // => 2
|
|
2861
|
+
* RGB.parseValue('PURPLE'); // throws an error
|
|
2862
|
+
* RGB.parseValue(2); // throws an error
|
|
2863
|
+
* ```
|
|
2864
|
+
*/
|
|
974
2865
|
|
|
975
2866
|
parseValue(inputValue) /* T */
|
|
976
2867
|
{
|
|
@@ -993,6 +2884,29 @@ export class GraphQLEnumType {
|
|
|
993
2884
|
|
|
994
2885
|
return enumValue.value;
|
|
995
2886
|
}
|
|
2887
|
+
/**
|
|
2888
|
+
* Parses a GraphQL enum name from an AST value literal.
|
|
2889
|
+
* @param valueNode - AST value literal to parse.
|
|
2890
|
+
* @param _variables - Runtime variable values; ignored because enum literals cannot contain variables.
|
|
2891
|
+
* @returns The internal enum value represented by the literal.
|
|
2892
|
+
* @example
|
|
2893
|
+
* ```ts
|
|
2894
|
+
* import { parseValue } from 'graphql/language';
|
|
2895
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
2896
|
+
*
|
|
2897
|
+
* const RGB = new GraphQLEnumType({
|
|
2898
|
+
* name: 'RGB',
|
|
2899
|
+
* values: {
|
|
2900
|
+
* RED: { value: 0 },
|
|
2901
|
+
* GREEN: { value: 1 },
|
|
2902
|
+
* BLUE: { value: 2 },
|
|
2903
|
+
* },
|
|
2904
|
+
* });
|
|
2905
|
+
*
|
|
2906
|
+
* RGB.parseLiteral(parseValue('RED')); // => 0
|
|
2907
|
+
* RGB.parseLiteral(parseValue('"RED"')); // throws an error
|
|
2908
|
+
* ```
|
|
2909
|
+
*/
|
|
996
2910
|
|
|
997
2911
|
parseLiteral(valueNode, _variables) /* T */
|
|
998
2912
|
{
|
|
@@ -1023,6 +2937,29 @@ export class GraphQLEnumType {
|
|
|
1023
2937
|
|
|
1024
2938
|
return enumValue.value;
|
|
1025
2939
|
}
|
|
2940
|
+
/**
|
|
2941
|
+
* Returns a normalized configuration object for this object.
|
|
2942
|
+
* @returns A configuration object that can be used to recreate this object.
|
|
2943
|
+
* @example
|
|
2944
|
+
* ```ts
|
|
2945
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
2946
|
+
*
|
|
2947
|
+
* const RGB = new GraphQLEnumType({
|
|
2948
|
+
* name: 'RGB',
|
|
2949
|
+
* values: {
|
|
2950
|
+
* RED: { value: 0 },
|
|
2951
|
+
* GREEN: { value: 1 },
|
|
2952
|
+
* BLUE: { value: 2 },
|
|
2953
|
+
* },
|
|
2954
|
+
* });
|
|
2955
|
+
*
|
|
2956
|
+
* const config = RGB.toConfig();
|
|
2957
|
+
* const RGBCopy = new GraphQLEnumType(config);
|
|
2958
|
+
*
|
|
2959
|
+
* config.values.GREEN.value; // => 1
|
|
2960
|
+
* RGBCopy.serialize(2); // => 'BLUE'
|
|
2961
|
+
* ```
|
|
2962
|
+
*/
|
|
1026
2963
|
|
|
1027
2964
|
toConfig() {
|
|
1028
2965
|
const values = keyValMap(
|
|
@@ -1045,10 +2982,51 @@ export class GraphQLEnumType {
|
|
|
1045
2982
|
extensionASTNodes: this.extensionASTNodes,
|
|
1046
2983
|
};
|
|
1047
2984
|
}
|
|
2985
|
+
/**
|
|
2986
|
+
* Returns the schema coordinate identifying this enum type.
|
|
2987
|
+
* @returns The schema coordinate for this enum type.
|
|
2988
|
+
* @example
|
|
2989
|
+
* ```ts
|
|
2990
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
2991
|
+
* import { assertEnumType } from 'graphql/type';
|
|
2992
|
+
*
|
|
2993
|
+
* const schema = buildSchema(`
|
|
2994
|
+
* enum Episode {
|
|
2995
|
+
* NEW_HOPE
|
|
2996
|
+
* }
|
|
2997
|
+
*
|
|
2998
|
+
* type Query {
|
|
2999
|
+
* episode: Episode
|
|
3000
|
+
* }
|
|
3001
|
+
* `);
|
|
3002
|
+
*
|
|
3003
|
+
* const Episode = assertEnumType(schema.getType('Episode'));
|
|
3004
|
+
*
|
|
3005
|
+
* Episode.toString(); // => 'Episode'
|
|
3006
|
+
* ```
|
|
3007
|
+
*/
|
|
1048
3008
|
|
|
1049
3009
|
toString() {
|
|
1050
3010
|
return this.name;
|
|
1051
3011
|
}
|
|
3012
|
+
/**
|
|
3013
|
+
* Returns the JSON representation used when this object is serialized.
|
|
3014
|
+
* @returns The JSON-serializable representation.
|
|
3015
|
+
* @example
|
|
3016
|
+
* ```ts
|
|
3017
|
+
* import { GraphQLEnumType } from 'graphql/type';
|
|
3018
|
+
*
|
|
3019
|
+
* const Episode = new GraphQLEnumType({
|
|
3020
|
+
* name: 'Episode',
|
|
3021
|
+
* values: {
|
|
3022
|
+
* NEW_HOPE: {},
|
|
3023
|
+
* },
|
|
3024
|
+
* });
|
|
3025
|
+
*
|
|
3026
|
+
* Episode.toJSON(); // => 'Episode'
|
|
3027
|
+
* JSON.stringify({ type: Episode }); // => '{"type":"Episode"}'
|
|
3028
|
+
* ```
|
|
3029
|
+
*/
|
|
1052
3030
|
|
|
1053
3031
|
toJSON() {
|
|
1054
3032
|
return this.toString();
|
|
@@ -1084,6 +3062,7 @@ function defineEnumValues(typeName, valueMap) {
|
|
|
1084
3062
|
};
|
|
1085
3063
|
});
|
|
1086
3064
|
}
|
|
3065
|
+
/** Configuration used to construct a GraphQLEnumType. */
|
|
1087
3066
|
|
|
1088
3067
|
/**
|
|
1089
3068
|
* Input Object Type Definition
|
|
@@ -1092,9 +3071,7 @@ function defineEnumValues(typeName, valueMap) {
|
|
|
1092
3071
|
* supplied to a field argument.
|
|
1093
3072
|
*
|
|
1094
3073
|
* Using `NonNull` will ensure that a value must be provided by the query
|
|
1095
|
-
*
|
|
1096
|
-
* Example:
|
|
1097
|
-
*
|
|
3074
|
+
* @example
|
|
1098
3075
|
* ```ts
|
|
1099
3076
|
* const GeoPoint = new GraphQLInputObjectType({
|
|
1100
3077
|
* name: 'GeoPoint',
|
|
@@ -1107,6 +3084,86 @@ function defineEnumValues(typeName, valueMap) {
|
|
|
1107
3084
|
* ```
|
|
1108
3085
|
*/
|
|
1109
3086
|
export class GraphQLInputObjectType {
|
|
3087
|
+
/** The GraphQL name for this schema element. */
|
|
3088
|
+
|
|
3089
|
+
/** Human-readable description for this schema element, if provided. */
|
|
3090
|
+
|
|
3091
|
+
/** Extension fields to include in the formatted result. */
|
|
3092
|
+
|
|
3093
|
+
/** AST node from which this schema element was built, if available. */
|
|
3094
|
+
|
|
3095
|
+
/** AST extension nodes applied to this schema element. */
|
|
3096
|
+
|
|
3097
|
+
/** Whether this input object uses the experimental OneOf input object semantics. */
|
|
3098
|
+
|
|
3099
|
+
/**
|
|
3100
|
+
* Creates a GraphQLInputObjectType instance.
|
|
3101
|
+
* @param config - Configuration describing this object.
|
|
3102
|
+
* @example
|
|
3103
|
+
* ```ts
|
|
3104
|
+
* import { parse } from 'graphql/language';
|
|
3105
|
+
* import {
|
|
3106
|
+
* GraphQLID,
|
|
3107
|
+
* GraphQLInputObjectType,
|
|
3108
|
+
* GraphQLInt,
|
|
3109
|
+
* GraphQLNonNull,
|
|
3110
|
+
* GraphQLString,
|
|
3111
|
+
* } from 'graphql/type';
|
|
3112
|
+
*
|
|
3113
|
+
* const document = parse(`
|
|
3114
|
+
* input ReviewInput {
|
|
3115
|
+
* stars: Int!
|
|
3116
|
+
* commentary: String
|
|
3117
|
+
* }
|
|
3118
|
+
*
|
|
3119
|
+
* extend input ReviewInput {
|
|
3120
|
+
* body: String
|
|
3121
|
+
* }
|
|
3122
|
+
* `);
|
|
3123
|
+
* const definition = document.definitions[0];
|
|
3124
|
+
*
|
|
3125
|
+
* const ReviewInput = new GraphQLInputObjectType({
|
|
3126
|
+
* name: 'ReviewInput',
|
|
3127
|
+
* description: 'Input collected when reviewing a product.',
|
|
3128
|
+
* fields: {
|
|
3129
|
+
* stars: {
|
|
3130
|
+
* description: 'Star rating from one to five.',
|
|
3131
|
+
* type: new GraphQLNonNull(GraphQLInt),
|
|
3132
|
+
* extensions: { min: 1, max: 5 },
|
|
3133
|
+
* astNode: definition.fields[0],
|
|
3134
|
+
* },
|
|
3135
|
+
* commentary: {
|
|
3136
|
+
* type: GraphQLString,
|
|
3137
|
+
* defaultValue: '',
|
|
3138
|
+
* deprecationReason: 'Use body.',
|
|
3139
|
+
* astNode: definition.fields[1],
|
|
3140
|
+
* },
|
|
3141
|
+
* },
|
|
3142
|
+
* extensions: { form: 'review' },
|
|
3143
|
+
* astNode: definition,
|
|
3144
|
+
* extensionASTNodes: [ document.definitions[1] ],
|
|
3145
|
+
* isOneOf: false,
|
|
3146
|
+
* });
|
|
3147
|
+
* const SearchBy = new GraphQLInputObjectType({
|
|
3148
|
+
* name: 'SearchBy',
|
|
3149
|
+
* fields: {
|
|
3150
|
+
* id: { type: GraphQLID },
|
|
3151
|
+
* slug: { type: GraphQLString },
|
|
3152
|
+
* },
|
|
3153
|
+
* isOneOf: true,
|
|
3154
|
+
* });
|
|
3155
|
+
*
|
|
3156
|
+
* const fields = ReviewInput.getFields();
|
|
3157
|
+
*
|
|
3158
|
+
* ReviewInput.description; // => 'Input collected when reviewing a product.'
|
|
3159
|
+
* String(fields.stars.type); // => 'Int!'
|
|
3160
|
+
* fields.stars.extensions; // => { min: 1, max: 5 }
|
|
3161
|
+
* fields.commentary.defaultValue; // => ''
|
|
3162
|
+
* fields.commentary.deprecationReason; // => 'Use body.'
|
|
3163
|
+
* ReviewInput.isOneOf; // => false
|
|
3164
|
+
* SearchBy.isOneOf; // => true
|
|
3165
|
+
* ```
|
|
3166
|
+
*/
|
|
1110
3167
|
constructor(config) {
|
|
1111
3168
|
var _config$extensionASTN6, _config$isOneOf;
|
|
1112
3169
|
|
|
@@ -1125,10 +3182,40 @@ export class GraphQLInputObjectType {
|
|
|
1125
3182
|
: false;
|
|
1126
3183
|
this._fields = defineInputFieldMap.bind(undefined, config);
|
|
1127
3184
|
}
|
|
3185
|
+
/**
|
|
3186
|
+
* Returns the value used by `Object.prototype.toString`.
|
|
3187
|
+
* @returns The built-in string tag for this object.
|
|
3188
|
+
*/
|
|
1128
3189
|
|
|
1129
3190
|
get [Symbol.toStringTag]() {
|
|
1130
3191
|
return 'GraphQLInputObjectType';
|
|
1131
3192
|
}
|
|
3193
|
+
/**
|
|
3194
|
+
* Returns the fields defined by this type.
|
|
3195
|
+
* @returns The fields keyed by field name.
|
|
3196
|
+
* @example
|
|
3197
|
+
* ```ts
|
|
3198
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
3199
|
+
* import { assertInputObjectType } from 'graphql/type';
|
|
3200
|
+
*
|
|
3201
|
+
* const schema = buildSchema(`
|
|
3202
|
+
* input ReviewInput {
|
|
3203
|
+
* stars: Int!
|
|
3204
|
+
* commentary: String = ""
|
|
3205
|
+
* }
|
|
3206
|
+
*
|
|
3207
|
+
* type Query {
|
|
3208
|
+
* reviews(filter: ReviewInput): [String]
|
|
3209
|
+
* }
|
|
3210
|
+
* `);
|
|
3211
|
+
*
|
|
3212
|
+
* const ReviewInput = assertInputObjectType(schema.getType('ReviewInput'));
|
|
3213
|
+
* const fields = ReviewInput.getFields();
|
|
3214
|
+
*
|
|
3215
|
+
* Object.keys(fields); // => ['stars', 'commentary']
|
|
3216
|
+
* fields.commentary.defaultValue; // => ''
|
|
3217
|
+
* ```
|
|
3218
|
+
*/
|
|
1132
3219
|
|
|
1133
3220
|
getFields() {
|
|
1134
3221
|
if (typeof this._fields === 'function') {
|
|
@@ -1137,6 +3224,31 @@ export class GraphQLInputObjectType {
|
|
|
1137
3224
|
|
|
1138
3225
|
return this._fields;
|
|
1139
3226
|
}
|
|
3227
|
+
/**
|
|
3228
|
+
* Returns a normalized configuration object for this object.
|
|
3229
|
+
* @returns A configuration object that can be used to recreate this object.
|
|
3230
|
+
* @example
|
|
3231
|
+
* ```ts
|
|
3232
|
+
* import {
|
|
3233
|
+
* GraphQLInputObjectType,
|
|
3234
|
+
* GraphQLInt,
|
|
3235
|
+
* GraphQLNonNull,
|
|
3236
|
+
* } from 'graphql/type';
|
|
3237
|
+
*
|
|
3238
|
+
* const ReviewInput = new GraphQLInputObjectType({
|
|
3239
|
+
* name: 'ReviewInput',
|
|
3240
|
+
* fields: {
|
|
3241
|
+
* stars: { type: new GraphQLNonNull(GraphQLInt) },
|
|
3242
|
+
* },
|
|
3243
|
+
* });
|
|
3244
|
+
*
|
|
3245
|
+
* const config = ReviewInput.toConfig();
|
|
3246
|
+
* const ReviewInputCopy = new GraphQLInputObjectType(config);
|
|
3247
|
+
*
|
|
3248
|
+
* String(config.fields.stars.type); // => 'Int!'
|
|
3249
|
+
* String(ReviewInputCopy.getFields().stars.type); // => 'Int!'
|
|
3250
|
+
* ```
|
|
3251
|
+
*/
|
|
1140
3252
|
|
|
1141
3253
|
toConfig() {
|
|
1142
3254
|
const fields = mapValue(this.getFields(), (field) => ({
|
|
@@ -1157,10 +3269,51 @@ export class GraphQLInputObjectType {
|
|
|
1157
3269
|
isOneOf: this.isOneOf,
|
|
1158
3270
|
};
|
|
1159
3271
|
}
|
|
3272
|
+
/**
|
|
3273
|
+
* Returns the schema coordinate identifying this input object type.
|
|
3274
|
+
* @returns The schema coordinate for this input object type.
|
|
3275
|
+
* @example
|
|
3276
|
+
* ```ts
|
|
3277
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
3278
|
+
* import { assertInputObjectType } from 'graphql/type';
|
|
3279
|
+
*
|
|
3280
|
+
* const schema = buildSchema(`
|
|
3281
|
+
* input ReviewInput {
|
|
3282
|
+
* stars: Int!
|
|
3283
|
+
* }
|
|
3284
|
+
*
|
|
3285
|
+
* type Query {
|
|
3286
|
+
* reviews(filter: ReviewInput): [String]
|
|
3287
|
+
* }
|
|
3288
|
+
* `);
|
|
3289
|
+
*
|
|
3290
|
+
* const ReviewInput = assertInputObjectType(schema.getType('ReviewInput'));
|
|
3291
|
+
*
|
|
3292
|
+
* ReviewInput.toString(); // => 'ReviewInput'
|
|
3293
|
+
* ```
|
|
3294
|
+
*/
|
|
1160
3295
|
|
|
1161
3296
|
toString() {
|
|
1162
3297
|
return this.name;
|
|
1163
3298
|
}
|
|
3299
|
+
/**
|
|
3300
|
+
* Returns the JSON representation used when this object is serialized.
|
|
3301
|
+
* @returns The JSON-serializable representation.
|
|
3302
|
+
* @example
|
|
3303
|
+
* ```ts
|
|
3304
|
+
* import { GraphQLInputObjectType, GraphQLString } from 'graphql/type';
|
|
3305
|
+
*
|
|
3306
|
+
* const ReviewInput = new GraphQLInputObjectType({
|
|
3307
|
+
* name: 'ReviewInput',
|
|
3308
|
+
* fields: {
|
|
3309
|
+
* commentary: { type: GraphQLString },
|
|
3310
|
+
* },
|
|
3311
|
+
* });
|
|
3312
|
+
*
|
|
3313
|
+
* ReviewInput.toJSON(); // => 'ReviewInput'
|
|
3314
|
+
* JSON.stringify({ type: ReviewInput }); // => '{"type":"ReviewInput"}'
|
|
3315
|
+
* ```
|
|
3316
|
+
*/
|
|
1164
3317
|
|
|
1165
3318
|
toJSON() {
|
|
1166
3319
|
return this.toString();
|
|
@@ -1191,7 +3344,35 @@ function defineInputFieldMap(config) {
|
|
|
1191
3344
|
};
|
|
1192
3345
|
});
|
|
1193
3346
|
}
|
|
3347
|
+
/** Configuration used to construct a GraphQLInputObjectType. */
|
|
1194
3348
|
|
|
3349
|
+
/**
|
|
3350
|
+
* Returns true when the input field is non-null and has no default value.
|
|
3351
|
+
* @param field - The input field definition to inspect.
|
|
3352
|
+
* @returns True when the input field is non-null and has no default value.
|
|
3353
|
+
* @example
|
|
3354
|
+
* ```ts
|
|
3355
|
+
* import {
|
|
3356
|
+
* GraphQLInt,
|
|
3357
|
+
* GraphQLNonNull,
|
|
3358
|
+
* GraphQLString,
|
|
3359
|
+
* isRequiredInputField,
|
|
3360
|
+
* } from 'graphql/type';
|
|
3361
|
+
*
|
|
3362
|
+
* const requiredField = { name: 'id', type: new GraphQLNonNull(GraphQLInt) };
|
|
3363
|
+
* const optionalField = { name: 'name', type: GraphQLString };
|
|
3364
|
+
* const fieldWithDefault = {
|
|
3365
|
+
* name: 'limit',
|
|
3366
|
+
* type: new GraphQLNonNull(GraphQLInt),
|
|
3367
|
+
* defaultValue: 10,
|
|
3368
|
+
* };
|
|
3369
|
+
*
|
|
3370
|
+
* isRequiredInputField(requiredField); // => true
|
|
3371
|
+
* isRequiredInputField(optionalField); // => false
|
|
3372
|
+
* isRequiredInputField(fieldWithDefault); // => false
|
|
3373
|
+
* ```
|
|
3374
|
+
*/
|
|
1195
3375
|
export function isRequiredInputField(field) {
|
|
1196
3376
|
return isNonNullType(field.type) && field.defaultValue === undefined;
|
|
1197
3377
|
}
|
|
3378
|
+
/** A map of input field names to resolved input field definitions. */
|