graphql 14.0.0 → 14.1.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/README.md +4 -4
- package/error/GraphQLError.js +1 -1
- package/error/GraphQLError.js.flow +3 -3
- package/error/GraphQLError.mjs +1 -1
- package/error/formatError.js +1 -1
- package/error/formatError.mjs +1 -1
- package/error/index.mjs +1 -1
- package/error/locatedError.js +1 -1
- package/error/locatedError.mjs +1 -1
- package/error/printError.js +1 -1
- package/error/printError.mjs +1 -1
- package/error/syntaxError.js +1 -1
- package/error/syntaxError.mjs +1 -1
- package/execution/execute.js +4 -4
- package/execution/execute.js.flow +4 -6
- package/execution/execute.mjs +5 -5
- package/execution/index.mjs +1 -1
- package/execution/values.js +4 -4
- package/execution/values.js.flow +3 -3
- package/execution/values.mjs +3 -3
- package/graphql.js +1 -1
- package/graphql.mjs +1 -1
- package/index.js +12 -0
- package/index.js.flow +4 -0
- package/index.mjs +4 -4
- package/jsutils/dedent.js +2 -2
- package/jsutils/dedent.js.flow +1 -1
- package/jsutils/dedent.mjs +2 -2
- package/jsutils/defineToJSON.js +17 -6
- package/jsutils/defineToJSON.js.flow +14 -5
- package/jsutils/defineToJSON.mjs +14 -6
- package/jsutils/defineToStringTag.js +5 -5
- package/jsutils/defineToStringTag.js.flow +3 -3
- package/jsutils/defineToStringTag.mjs +4 -4
- package/jsutils/inspect.js +46 -12
- package/jsutils/inspect.js.flow +42 -15
- package/jsutils/inspect.mjs +45 -5
- package/jsutils/instanceOf.js +1 -1
- package/jsutils/instanceOf.mjs +1 -1
- package/jsutils/invariant.js +1 -1
- package/jsutils/invariant.mjs +1 -1
- package/jsutils/isInvalid.js +1 -1
- package/jsutils/isInvalid.mjs +1 -1
- package/jsutils/isNullish.js +1 -1
- package/jsutils/isNullish.mjs +1 -1
- package/jsutils/isPromise.js +1 -1
- package/jsutils/isPromise.mjs +1 -1
- package/jsutils/keyMap.js +1 -1
- package/jsutils/keyMap.mjs +1 -1
- package/jsutils/keyValMap.js +1 -1
- package/jsutils/keyValMap.mjs +1 -1
- package/jsutils/mapValue.js +54 -0
- package/jsutils/mapValue.js.flow +27 -0
- package/jsutils/mapValue.mjs +44 -0
- package/jsutils/memoize3.js +1 -1
- package/jsutils/memoize3.mjs +1 -1
- package/jsutils/nodejsCustomInspectSymbol.js +18 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
- package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
- package/jsutils/orList.js +17 -4
- package/jsutils/orList.js.flow +13 -7
- package/jsutils/orList.mjs +14 -4
- package/jsutils/promiseForObject.js +1 -1
- package/jsutils/promiseForObject.mjs +1 -1
- package/jsutils/promiseReduce.js +1 -1
- package/jsutils/promiseReduce.mjs +1 -1
- package/jsutils/quotedOrList.js +1 -1
- package/jsutils/quotedOrList.mjs +1 -1
- package/jsutils/suggestionList.js +1 -1
- package/jsutils/suggestionList.mjs +1 -1
- package/language/blockStringValue.js +2 -2
- package/language/blockStringValue.js.flow +1 -1
- package/language/blockStringValue.mjs +2 -2
- package/language/directiveLocation.js +1 -1
- package/language/directiveLocation.mjs +1 -1
- package/language/index.mjs +1 -1
- package/language/kinds.js +1 -1
- package/language/kinds.mjs +1 -1
- package/language/lexer.js +29 -13
- package/language/lexer.js.flow +34 -20
- package/language/lexer.mjs +28 -13
- package/language/location.js +1 -1
- package/language/location.mjs +1 -1
- package/language/parser.js +31 -38
- package/language/parser.js.flow +32 -48
- package/language/parser.mjs +30 -38
- package/language/predicates.js +1 -1
- package/language/predicates.mjs +1 -1
- package/language/printer.js +13 -7
- package/language/printer.js.flow +19 -9
- package/language/printer.mjs +13 -7
- package/language/source.js +8 -7
- package/language/source.mjs +1 -9
- package/language/visitor.js +11 -20
- package/language/visitor.js.flow +4 -5
- package/language/visitor.mjs +8 -20
- package/package.json +10 -3
- package/polyfills/find.js +31 -0
- package/polyfills/find.js.flow +29 -0
- package/polyfills/find.mjs +23 -0
- package/{jsutils → polyfills}/isFinite.js +1 -1
- package/{jsutils → polyfills}/isFinite.js.flow +0 -0
- package/{jsutils → polyfills}/isFinite.mjs +1 -1
- package/{jsutils → polyfills}/isInteger.js +1 -1
- package/{jsutils → polyfills}/isInteger.js.flow +0 -0
- package/{jsutils → polyfills}/isInteger.mjs +1 -1
- package/polyfills/objectEntries.js +26 -0
- package/polyfills/objectEntries.js.flow +19 -0
- package/polyfills/objectEntries.mjs +18 -0
- package/{jsutils → polyfills}/objectValues.js +1 -1
- package/{jsutils → polyfills}/objectValues.js.flow +1 -1
- package/{jsutils → polyfills}/objectValues.mjs +1 -1
- package/subscription/asyncIteratorReject.mjs +1 -1
- package/subscription/index.mjs +1 -1
- package/subscription/mapAsyncIterator.mjs +1 -1
- package/subscription/subscribe.js +1 -1
- package/subscription/subscribe.js.flow +1 -1
- package/subscription/subscribe.mjs +2 -2
- package/type/definition.js +31 -130
- package/type/definition.js.flow +35 -47
- package/type/definition.mjs +30 -131
- package/type/directives.js +25 -29
- package/type/directives.js.flow +24 -20
- package/type/directives.mjs +22 -30
- package/type/index.js +12 -0
- package/type/index.js.flow +4 -0
- package/type/index.mjs +5 -3
- package/type/introspection.js +3 -3
- package/type/introspection.js.flow +1 -1
- package/type/introspection.mjs +2 -2
- package/type/scalars.js +45 -34
- package/type/scalars.js.flow +40 -26
- package/type/scalars.mjs +44 -26
- package/type/schema.js +82 -87
- package/type/schema.js.flow +17 -9
- package/type/schema.mjs +79 -86
- package/type/validate.js +168 -175
- package/type/validate.js.flow +8 -49
- package/type/validate.mjs +159 -175
- package/utilities/TypeInfo.js +10 -23
- package/utilities/TypeInfo.js.flow +1 -1
- package/utilities/TypeInfo.mjs +2 -24
- package/utilities/assertValidName.js +1 -1
- package/utilities/assertValidName.mjs +1 -1
- package/utilities/astFromValue.js +2 -2
- package/utilities/astFromValue.js.flow +1 -1
- package/utilities/astFromValue.mjs +2 -2
- package/utilities/buildASTSchema.js +169 -152
- package/utilities/buildASTSchema.js.flow +117 -113
- package/utilities/buildASTSchema.mjs +160 -152
- package/utilities/buildClientSchema.js +24 -14
- package/utilities/buildClientSchema.js.flow +24 -14
- package/utilities/buildClientSchema.mjs +23 -14
- package/utilities/coerceValue.js +38 -19
- package/utilities/coerceValue.js.flow +41 -47
- package/utilities/coerceValue.mjs +38 -20
- package/utilities/concatAST.js +1 -1
- package/utilities/concatAST.mjs +1 -1
- package/utilities/extendSchema.js +228 -312
- package/utilities/extendSchema.js.flow +27 -152
- package/utilities/extendSchema.mjs +229 -312
- package/utilities/findBreakingChanges.js +7 -5
- package/utilities/findBreakingChanges.js.flow +3 -2
- package/utilities/findBreakingChanges.mjs +6 -5
- package/utilities/findDeprecatedUsages.js +1 -1
- package/utilities/findDeprecatedUsages.mjs +1 -1
- package/utilities/getOperationAST.js +1 -1
- package/utilities/getOperationAST.mjs +1 -1
- package/utilities/getOperationRootType.js +1 -1
- package/utilities/getOperationRootType.mjs +1 -1
- package/utilities/index.mjs +1 -1
- package/utilities/introspectionFromSchema.js +1 -1
- package/utilities/introspectionFromSchema.mjs +1 -1
- package/utilities/introspectionQuery.js +1 -1
- package/utilities/introspectionQuery.mjs +1 -1
- package/utilities/isValidJSValue.js +1 -1
- package/utilities/isValidJSValue.mjs +1 -1
- package/utilities/isValidLiteralValue.js +1 -1
- package/utilities/isValidLiteralValue.mjs +1 -1
- package/utilities/lexicographicSortSchema.js +2 -2
- package/utilities/lexicographicSortSchema.js.flow +1 -1
- package/utilities/lexicographicSortSchema.mjs +2 -2
- package/utilities/schemaPrinter.js +3 -3
- package/utilities/schemaPrinter.js.flow +1 -1
- package/utilities/schemaPrinter.mjs +2 -2
- package/utilities/separateOperations.js +1 -1
- package/utilities/separateOperations.mjs +1 -1
- package/utilities/typeComparators.js +1 -1
- package/utilities/typeComparators.mjs +1 -1
- package/utilities/typeFromAST.js +1 -1
- package/utilities/typeFromAST.mjs +1 -1
- package/utilities/valueFromAST.js +3 -3
- package/utilities/valueFromAST.js.flow +1 -1
- package/utilities/valueFromAST.mjs +2 -2
- package/utilities/valueFromASTUntyped.js +1 -1
- package/utilities/valueFromASTUntyped.mjs +1 -1
- package/validation/ValidationContext.js +57 -82
- package/validation/ValidationContext.js.flow +52 -49
- package/validation/ValidationContext.mjs +52 -77
- package/validation/index.js.flow +1 -0
- package/validation/index.mjs +1 -1
- package/validation/rules/ExecutableDefinitions.js +1 -1
- package/validation/rules/ExecutableDefinitions.js.flow +1 -1
- package/validation/rules/ExecutableDefinitions.mjs +1 -1
- package/validation/rules/FieldsOnCorrectType.js +1 -1
- package/validation/rules/FieldsOnCorrectType.mjs +1 -1
- package/validation/rules/FragmentsOnCompositeTypes.js +1 -1
- package/validation/rules/FragmentsOnCompositeTypes.mjs +1 -1
- package/validation/rules/KnownArgumentNames.mjs +1 -1
- package/validation/rules/KnownDirectives.js +1 -1
- package/validation/rules/KnownDirectives.mjs +1 -1
- package/validation/rules/KnownFragmentNames.js +1 -1
- package/validation/rules/KnownFragmentNames.mjs +1 -1
- package/validation/rules/KnownTypeNames.js +59 -21
- package/validation/rules/KnownTypeNames.js.flow +54 -20
- package/validation/rules/KnownTypeNames.mjs +56 -21
- package/validation/rules/LoneAnonymousOperation.js +1 -1
- package/validation/rules/LoneAnonymousOperation.mjs +1 -1
- package/validation/rules/LoneSchemaDefinition.js +1 -1
- package/validation/rules/LoneSchemaDefinition.mjs +1 -1
- package/validation/rules/NoFragmentCycles.js +1 -1
- package/validation/rules/NoFragmentCycles.js.flow +2 -2
- package/validation/rules/NoFragmentCycles.mjs +1 -1
- package/validation/rules/NoUndefinedVariables.js +1 -1
- package/validation/rules/NoUndefinedVariables.mjs +1 -1
- package/validation/rules/NoUnusedFragments.js +1 -1
- package/validation/rules/NoUnusedFragments.js.flow +2 -2
- package/validation/rules/NoUnusedFragments.mjs +1 -1
- package/validation/rules/NoUnusedVariables.js +1 -1
- package/validation/rules/NoUnusedVariables.mjs +1 -1
- package/validation/rules/OverlappingFieldsCanBeMerged.js +57 -33
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +5 -6
- package/validation/rules/OverlappingFieldsCanBeMerged.mjs +48 -33
- package/validation/rules/PossibleFragmentSpreads.js +1 -1
- package/validation/rules/PossibleFragmentSpreads.mjs +1 -1
- package/validation/rules/PossibleTypeExtensions.js +158 -0
- package/validation/rules/PossibleTypeExtensions.js.flow +160 -0
- package/validation/rules/PossibleTypeExtensions.mjs +146 -0
- package/validation/rules/ProvidedRequiredArguments.mjs +1 -1
- package/validation/rules/ScalarLeafs.js +1 -1
- package/validation/rules/ScalarLeafs.mjs +1 -1
- package/validation/rules/SingleFieldSubscriptions.js +1 -1
- package/validation/rules/SingleFieldSubscriptions.mjs +1 -1
- package/validation/rules/UniqueArgumentNames.js +1 -1
- package/validation/rules/UniqueArgumentNames.mjs +1 -1
- package/validation/rules/UniqueDirectiveNames.js +55 -0
- package/validation/rules/UniqueDirectiveNames.js.flow +64 -0
- package/validation/rules/UniqueDirectiveNames.mjs +43 -0
- package/validation/rules/UniqueDirectivesPerLocation.js +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.mjs +1 -1
- package/validation/rules/UniqueEnumValueNames.js +94 -0
- package/validation/rules/UniqueEnumValueNames.js.flow +87 -0
- package/validation/rules/UniqueEnumValueNames.mjs +81 -0
- package/validation/rules/UniqueFieldDefinitionNames.js +105 -0
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +101 -0
- package/validation/rules/UniqueFieldDefinitionNames.mjs +92 -0
- package/validation/rules/UniqueFragmentNames.js +1 -1
- package/validation/rules/UniqueFragmentNames.mjs +1 -1
- package/validation/rules/UniqueInputFieldNames.js +1 -1
- package/validation/rules/UniqueInputFieldNames.mjs +1 -1
- package/validation/rules/UniqueOperationNames.js +1 -1
- package/validation/rules/UniqueOperationNames.mjs +1 -1
- package/validation/rules/UniqueOperationTypes.js +85 -0
- package/validation/rules/UniqueOperationTypes.js.flow +76 -0
- package/validation/rules/UniqueOperationTypes.mjs +73 -0
- package/validation/rules/UniqueTypeNames.js +62 -0
- package/validation/rules/UniqueTypeNames.js.flow +67 -0
- package/validation/rules/UniqueTypeNames.mjs +50 -0
- package/validation/rules/UniqueVariableNames.js +1 -1
- package/validation/rules/UniqueVariableNames.mjs +1 -1
- package/validation/rules/ValuesOfCorrectType.js +29 -13
- package/validation/rules/ValuesOfCorrectType.js.flow +4 -5
- package/validation/rules/ValuesOfCorrectType.mjs +28 -13
- package/validation/rules/VariablesAreInputTypes.js +1 -1
- package/validation/rules/VariablesAreInputTypes.mjs +1 -1
- package/validation/rules/VariablesInAllowedPosition.js +4 -4
- package/validation/rules/VariablesInAllowedPosition.mjs +4 -4
- package/validation/specifiedRules.js +14 -2
- package/validation/specifiedRules.js.flow +13 -0
- package/validation/specifiedRules.mjs +8 -2
- package/validation/validate.js +1 -1
- package/validation/validate.mjs +1 -1
- package/jsutils/find.js +0 -22
- package/jsutils/find.js.flow +0 -19
- package/jsutils/find.mjs +0 -15
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import objectValues from '../polyfills/objectValues';
|
|
10
11
|
import invariant from '../jsutils/invariant';
|
|
11
12
|
import keyMap from '../jsutils/keyMap';
|
|
12
13
|
import keyValMap from '../jsutils/keyValMap';
|
|
@@ -23,6 +24,7 @@ import { Kind } from '../language/kinds';
|
|
|
23
24
|
|
|
24
25
|
import type {
|
|
25
26
|
DocumentNode,
|
|
27
|
+
NameNode,
|
|
26
28
|
TypeNode,
|
|
27
29
|
NamedTypeNode,
|
|
28
30
|
SchemaDefinitionNode,
|
|
@@ -48,8 +50,9 @@ import type {
|
|
|
48
50
|
GraphQLType,
|
|
49
51
|
GraphQLNamedType,
|
|
50
52
|
GraphQLFieldConfig,
|
|
53
|
+
GraphQLArgumentConfig,
|
|
51
54
|
GraphQLEnumValueConfig,
|
|
52
|
-
|
|
55
|
+
GraphQLInputFieldConfig,
|
|
53
56
|
} from '../type/definition';
|
|
54
57
|
|
|
55
58
|
import {
|
|
@@ -128,21 +131,14 @@ export function buildASTSchema(
|
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
let schemaDef: ?SchemaDefinitionNode;
|
|
131
|
-
|
|
132
|
-
const typeDefs: Array<TypeDefinitionNode> = [];
|
|
133
134
|
const nodeMap: ObjMap<TypeDefinitionNode> = Object.create(null);
|
|
134
135
|
const directiveDefs: Array<DirectiveDefinitionNode> = [];
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
|
|
137
|
+
for (const def of documentAST.definitions) {
|
|
137
138
|
if (def.kind === Kind.SCHEMA_DEFINITION) {
|
|
138
139
|
schemaDef = def;
|
|
139
140
|
} else if (isTypeDefinitionNode(def)) {
|
|
140
|
-
|
|
141
|
-
if (nodeMap[typeName]) {
|
|
142
|
-
throw new Error(`Type "${typeName}" was defined more than once.`);
|
|
143
|
-
}
|
|
144
|
-
typeDefs.push(def);
|
|
145
|
-
nodeMap[typeName] = def;
|
|
141
|
+
nodeMap[def.name.value] = def;
|
|
146
142
|
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
|
147
143
|
directiveDefs.push(def);
|
|
148
144
|
}
|
|
@@ -159,8 +155,8 @@ export function buildASTSchema(
|
|
|
159
155
|
const definitionBuilder = new ASTDefinitionBuilder(
|
|
160
156
|
nodeMap,
|
|
161
157
|
options,
|
|
162
|
-
|
|
163
|
-
throw new Error(`Type "${
|
|
158
|
+
typeName => {
|
|
159
|
+
throw new Error(`Type "${typeName}" not found in document.`);
|
|
164
160
|
},
|
|
165
161
|
);
|
|
166
162
|
|
|
@@ -194,7 +190,7 @@ export function buildASTSchema(
|
|
|
194
190
|
subscription: operationTypes.subscription
|
|
195
191
|
? (definitionBuilder.buildType(operationTypes.subscription): any)
|
|
196
192
|
: null,
|
|
197
|
-
types:
|
|
193
|
+
types: objectValues(nodeMap).map(node => definitionBuilder.buildType(node)),
|
|
198
194
|
directives,
|
|
199
195
|
astNode: schemaDef,
|
|
200
196
|
assumeValid: options && options.assumeValid,
|
|
@@ -204,24 +200,14 @@ export function buildASTSchema(
|
|
|
204
200
|
function getOperationTypes(schema: SchemaDefinitionNode) {
|
|
205
201
|
const opTypes = {};
|
|
206
202
|
for (const operationType of schema.operationTypes) {
|
|
207
|
-
|
|
208
|
-
const operation = operationType.operation;
|
|
209
|
-
if (opTypes[operation]) {
|
|
210
|
-
throw new Error(`Must provide only one ${operation} type in schema.`);
|
|
211
|
-
}
|
|
212
|
-
if (!nodeMap[typeName]) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`Specified ${operation} type "${typeName}" not found in document.`,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
opTypes[operation] = operationType.type;
|
|
203
|
+
opTypes[operationType.operation] = operationType.type;
|
|
218
204
|
}
|
|
219
205
|
return opTypes;
|
|
220
206
|
}
|
|
221
207
|
}
|
|
222
208
|
|
|
223
209
|
type TypeDefinitionsMap = ObjMap<TypeDefinitionNode>;
|
|
224
|
-
type TypeResolver = (
|
|
210
|
+
type TypeResolver = (typeName: string) => GraphQLNamedType;
|
|
225
211
|
|
|
226
212
|
export class ASTDefinitionBuilder {
|
|
227
213
|
_typeDefinitionsMap: TypeDefinitionsMap;
|
|
@@ -251,7 +237,7 @@ export class ASTDefinitionBuilder {
|
|
|
251
237
|
const defNode = this._typeDefinitionsMap[typeName];
|
|
252
238
|
this._cache[typeName] = defNode
|
|
253
239
|
? this._makeSchemaDef(defNode)
|
|
254
|
-
: this._resolveType(node);
|
|
240
|
+
: this._resolveType(node.name.value);
|
|
255
241
|
} else {
|
|
256
242
|
this._cache[typeName] = this._makeSchemaDef(node);
|
|
257
243
|
}
|
|
@@ -272,40 +258,52 @@ export class ASTDefinitionBuilder {
|
|
|
272
258
|
return this.buildType(typeNode);
|
|
273
259
|
}
|
|
274
260
|
|
|
275
|
-
buildDirective(
|
|
261
|
+
buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective {
|
|
262
|
+
const locations = directive.locations.map(
|
|
263
|
+
({ value }) => ((value: any): DirectiveLocationEnum),
|
|
264
|
+
);
|
|
265
|
+
|
|
276
266
|
return new GraphQLDirective({
|
|
277
|
-
name:
|
|
278
|
-
description: getDescription(
|
|
279
|
-
locations
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
args:
|
|
283
|
-
directiveNode.arguments &&
|
|
284
|
-
this._makeInputValues(directiveNode.arguments),
|
|
285
|
-
astNode: directiveNode,
|
|
267
|
+
name: directive.name.value,
|
|
268
|
+
description: getDescription(directive, this._options),
|
|
269
|
+
locations,
|
|
270
|
+
args: keyByNameNode(directive.arguments || [], arg => this.buildArg(arg)),
|
|
271
|
+
astNode: directive,
|
|
286
272
|
});
|
|
287
273
|
}
|
|
288
274
|
|
|
289
|
-
buildField(field: FieldDefinitionNode): GraphQLFieldConfig
|
|
275
|
+
buildField(field: FieldDefinitionNode): GraphQLFieldConfig<mixed, mixed> {
|
|
290
276
|
return {
|
|
291
277
|
// Note: While this could make assertions to get the correctly typed
|
|
292
278
|
// value, that would throw immediately while type system validation
|
|
293
279
|
// with validateSchema() will produce more actionable results.
|
|
294
280
|
type: (this._buildWrappedType(field.type): any),
|
|
295
281
|
description: getDescription(field, this._options),
|
|
296
|
-
args: field.arguments
|
|
282
|
+
args: keyByNameNode(field.arguments || [], arg => this.buildArg(arg)),
|
|
297
283
|
deprecationReason: getDeprecationReason(field),
|
|
298
284
|
astNode: field,
|
|
299
285
|
};
|
|
300
286
|
}
|
|
301
287
|
|
|
302
|
-
|
|
288
|
+
buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig {
|
|
289
|
+
// Note: While this could make assertions to get the correctly typed
|
|
290
|
+
// value, that would throw immediately while type system validation
|
|
291
|
+
// with validateSchema() will produce more actionable results.
|
|
292
|
+
const type: any = this._buildWrappedType(value.type);
|
|
293
|
+
return {
|
|
294
|
+
type,
|
|
295
|
+
description: getDescription(value, this._options),
|
|
296
|
+
defaultValue: valueFromAST(value.defaultValue, type),
|
|
297
|
+
astNode: value,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig {
|
|
303
302
|
// Note: While this could make assertions to get the correctly typed
|
|
304
303
|
// value, that would throw immediately while type system validation
|
|
305
304
|
// with validateSchema() will produce more actionable results.
|
|
306
305
|
const type: any = this._buildWrappedType(value.type);
|
|
307
306
|
return {
|
|
308
|
-
name: value.name.value,
|
|
309
307
|
type,
|
|
310
308
|
description: getDescription(value, this._options),
|
|
311
309
|
defaultValue: valueFromAST(value.defaultValue, type),
|
|
@@ -321,121 +319,127 @@ export class ASTDefinitionBuilder {
|
|
|
321
319
|
};
|
|
322
320
|
}
|
|
323
321
|
|
|
324
|
-
_makeSchemaDef(
|
|
325
|
-
switch (
|
|
322
|
+
_makeSchemaDef(astNode: TypeDefinitionNode): GraphQLNamedType {
|
|
323
|
+
switch (astNode.kind) {
|
|
326
324
|
case Kind.OBJECT_TYPE_DEFINITION:
|
|
327
|
-
return this._makeTypeDef(
|
|
325
|
+
return this._makeTypeDef(astNode);
|
|
328
326
|
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
329
|
-
return this._makeInterfaceDef(
|
|
327
|
+
return this._makeInterfaceDef(astNode);
|
|
330
328
|
case Kind.ENUM_TYPE_DEFINITION:
|
|
331
|
-
return this._makeEnumDef(
|
|
329
|
+
return this._makeEnumDef(astNode);
|
|
332
330
|
case Kind.UNION_TYPE_DEFINITION:
|
|
333
|
-
return this._makeUnionDef(
|
|
331
|
+
return this._makeUnionDef(astNode);
|
|
334
332
|
case Kind.SCALAR_TYPE_DEFINITION:
|
|
335
|
-
return this._makeScalarDef(
|
|
333
|
+
return this._makeScalarDef(astNode);
|
|
336
334
|
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
337
|
-
return this._makeInputObjectDef(
|
|
335
|
+
return this._makeInputObjectDef(astNode);
|
|
338
336
|
default:
|
|
339
|
-
throw new Error(`Type kind "${
|
|
337
|
+
throw new Error(`Type kind "${astNode.kind}" not supported.`);
|
|
340
338
|
}
|
|
341
339
|
}
|
|
342
340
|
|
|
343
|
-
_makeTypeDef(
|
|
344
|
-
const
|
|
341
|
+
_makeTypeDef(astNode: ObjectTypeDefinitionNode) {
|
|
342
|
+
const interfaceNodes = astNode.interfaces;
|
|
343
|
+
const fieldNodes = astNode.fields;
|
|
344
|
+
|
|
345
|
+
// Note: While this could make assertions to get the correctly typed
|
|
346
|
+
// values below, that would throw immediately while type system
|
|
347
|
+
// validation with validateSchema() will produce more actionable results.
|
|
348
|
+
const interfaces =
|
|
349
|
+
interfaceNodes && interfaceNodes.length > 0
|
|
350
|
+
? () => interfaceNodes.map(ref => (this.buildType(ref): any))
|
|
351
|
+
: [];
|
|
352
|
+
|
|
353
|
+
const fields =
|
|
354
|
+
fieldNodes && fieldNodes.length > 0
|
|
355
|
+
? () => keyByNameNode(fieldNodes, field => this.buildField(field))
|
|
356
|
+
: Object.create(null);
|
|
357
|
+
|
|
345
358
|
return new GraphQLObjectType({
|
|
346
|
-
name:
|
|
347
|
-
description: getDescription(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
// validation with validateSchema() will produce more actionable results.
|
|
352
|
-
interfaces: interfaces
|
|
353
|
-
? () => interfaces.map(ref => (this.buildType(ref): any))
|
|
354
|
-
: [],
|
|
355
|
-
astNode: def,
|
|
359
|
+
name: astNode.name.value,
|
|
360
|
+
description: getDescription(astNode, this._options),
|
|
361
|
+
interfaces,
|
|
362
|
+
fields,
|
|
363
|
+
astNode,
|
|
356
364
|
});
|
|
357
365
|
}
|
|
358
366
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
) {
|
|
362
|
-
return def.fields
|
|
363
|
-
? keyValMap(
|
|
364
|
-
def.fields,
|
|
365
|
-
field => field.name.value,
|
|
366
|
-
field => this.buildField(field),
|
|
367
|
-
)
|
|
368
|
-
: {};
|
|
369
|
-
}
|
|
367
|
+
_makeInterfaceDef(astNode: InterfaceTypeDefinitionNode) {
|
|
368
|
+
const fieldNodes = astNode.fields;
|
|
370
369
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
value => this.buildInputField(value),
|
|
376
|
-
);
|
|
377
|
-
}
|
|
370
|
+
const fields =
|
|
371
|
+
fieldNodes && fieldNodes.length > 0
|
|
372
|
+
? () => keyByNameNode(fieldNodes, field => this.buildField(field))
|
|
373
|
+
: Object.create(null);
|
|
378
374
|
|
|
379
|
-
_makeInterfaceDef(def: InterfaceTypeDefinitionNode) {
|
|
380
375
|
return new GraphQLInterfaceType({
|
|
381
|
-
name:
|
|
382
|
-
description: getDescription(
|
|
383
|
-
fields
|
|
384
|
-
astNode
|
|
376
|
+
name: astNode.name.value,
|
|
377
|
+
description: getDescription(astNode, this._options),
|
|
378
|
+
fields,
|
|
379
|
+
astNode,
|
|
385
380
|
});
|
|
386
381
|
}
|
|
387
382
|
|
|
388
|
-
_makeEnumDef(
|
|
383
|
+
_makeEnumDef(astNode: EnumTypeDefinitionNode) {
|
|
384
|
+
const valueNodes = astNode.values || [];
|
|
385
|
+
|
|
389
386
|
return new GraphQLEnumType({
|
|
390
|
-
name:
|
|
391
|
-
description: getDescription(
|
|
392
|
-
values: this.
|
|
393
|
-
astNode
|
|
387
|
+
name: astNode.name.value,
|
|
388
|
+
description: getDescription(astNode, this._options),
|
|
389
|
+
values: keyByNameNode(valueNodes, value => this.buildEnumValue(value)),
|
|
390
|
+
astNode,
|
|
394
391
|
});
|
|
395
392
|
}
|
|
396
393
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
394
|
+
_makeUnionDef(astNode: UnionTypeDefinitionNode) {
|
|
395
|
+
const typeNodes = astNode.types;
|
|
396
|
+
|
|
397
|
+
// Note: While this could make assertions to get the correctly typed
|
|
398
|
+
// values below, that would throw immediately while type system
|
|
399
|
+
// validation with validateSchema() will produce more actionable results.
|
|
400
|
+
const types =
|
|
401
|
+
typeNodes && typeNodes.length > 0
|
|
402
|
+
? () => typeNodes.map(ref => (this.buildType(ref): any))
|
|
403
|
+
: [];
|
|
406
404
|
|
|
407
|
-
_makeUnionDef(def: UnionTypeDefinitionNode) {
|
|
408
|
-
const types: ?$ReadOnlyArray<NamedTypeNode> = def.types;
|
|
409
405
|
return new GraphQLUnionType({
|
|
410
|
-
name:
|
|
411
|
-
description: getDescription(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
// validation with validateSchema() will produce more actionable results.
|
|
415
|
-
types: types ? () => types.map(ref => (this.buildType(ref): any)) : [],
|
|
416
|
-
astNode: def,
|
|
406
|
+
name: astNode.name.value,
|
|
407
|
+
description: getDescription(astNode, this._options),
|
|
408
|
+
types,
|
|
409
|
+
astNode,
|
|
417
410
|
});
|
|
418
411
|
}
|
|
419
412
|
|
|
420
|
-
_makeScalarDef(
|
|
413
|
+
_makeScalarDef(astNode: ScalarTypeDefinitionNode) {
|
|
421
414
|
return new GraphQLScalarType({
|
|
422
|
-
name:
|
|
423
|
-
description: getDescription(
|
|
424
|
-
astNode
|
|
415
|
+
name: astNode.name.value,
|
|
416
|
+
description: getDescription(astNode, this._options),
|
|
417
|
+
astNode,
|
|
425
418
|
serialize: value => value,
|
|
426
419
|
});
|
|
427
420
|
}
|
|
428
421
|
|
|
429
422
|
_makeInputObjectDef(def: InputObjectTypeDefinitionNode) {
|
|
423
|
+
const { fields } = def;
|
|
424
|
+
|
|
430
425
|
return new GraphQLInputObjectType({
|
|
431
426
|
name: def.name.value,
|
|
432
427
|
description: getDescription(def, this._options),
|
|
433
|
-
fields:
|
|
428
|
+
fields: fields
|
|
429
|
+
? () => keyByNameNode(fields, field => this.buildInputField(field))
|
|
430
|
+
: Object.create(null),
|
|
434
431
|
astNode: def,
|
|
435
432
|
});
|
|
436
433
|
}
|
|
437
434
|
}
|
|
438
435
|
|
|
436
|
+
function keyByNameNode<T: { +name: NameNode }, V>(
|
|
437
|
+
list: $ReadOnlyArray<T>,
|
|
438
|
+
valFn: (item: T) => V,
|
|
439
|
+
): ObjMap<V> {
|
|
440
|
+
return keyValMap(list, ({ name }) => name.value, valFn);
|
|
441
|
+
}
|
|
442
|
+
|
|
439
443
|
/**
|
|
440
444
|
* Given a field or enum value node, returns the string value for the
|
|
441
445
|
* deprecation reason.
|