graphql 0.13.1 → 0.13.2
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/locatedError.js +1 -0
- package/error/locatedError.js.flow +1 -0
- package/error/locatedError.mjs +1 -0
- package/execution/execute.js +26 -36
- package/execution/execute.js.flow +33 -43
- package/execution/execute.mjs +23 -33
- package/execution/values.js.flow +1 -2
- package/index.js.flow +1 -0
- package/jsutils/MaybePromise.js.flow +1 -1
- package/jsutils/isPromise.js +24 -0
- package/jsutils/isPromise.js.flow +20 -0
- package/jsutils/isPromise.mjs +18 -0
- package/jsutils/promiseReduce.js +5 -10
- package/jsutils/promiseReduce.js.flow +8 -9
- package/jsutils/promiseReduce.mjs +4 -9
- package/package.json +2 -2
- package/subscription/mapAsyncIterator.js +2 -0
- package/subscription/mapAsyncIterator.js.flow +2 -0
- package/subscription/mapAsyncIterator.mjs +2 -0
- package/type/definition.js +74 -4
- package/type/definition.js.flow +80 -1
- package/type/definition.mjs +70 -2
- package/type/directives.js +3 -3
- package/type/directives.js.flow +1 -1
- package/type/directives.mjs +8 -8
- package/type/index.js +2 -5
- package/type/index.js.flow +1 -4
- package/type/index.mjs +2 -4
- package/type/introspection.js +34 -38
- package/type/introspection.js.flow +2 -1
- package/type/introspection.mjs +1 -2
- package/type/schema.js +7 -5
- package/type/schema.js.flow +8 -7
- package/type/schema.mjs +7 -5
- package/type/validate.js +5 -5
- package/type/validate.js.flow +9 -9
- package/type/validate.mjs +5 -5
- package/utilities/buildASTSchema.js +27 -36
- package/utilities/buildASTSchema.js.flow +27 -24
- package/utilities/buildASTSchema.mjs +26 -35
- package/utilities/buildClientSchema.js +10 -14
- package/utilities/buildClientSchema.js.flow +2 -2
- package/utilities/buildClientSchema.mjs +1 -3
- package/utilities/extendSchema.js +33 -41
- package/utilities/extendSchema.js.flow +32 -55
- package/utilities/extendSchema.mjs +22 -31
- package/utilities/index.js.flow +1 -0
- package/utilities/index.mjs +1 -0
- package/utilities/isValidLiteralValue.js +6 -2
- package/utilities/isValidLiteralValue.js.flow +1 -1
- package/utilities/isValidLiteralValue.mjs +1 -1
- package/utilities/lexicographicSortSchema.js +2 -4
- package/utilities/lexicographicSortSchema.js.flow +2 -1
- package/utilities/lexicographicSortSchema.mjs +1 -2
- package/utilities/typeFromAST.js +3 -3
- package/utilities/typeFromAST.js.flow +1 -1
- package/utilities/typeFromAST.mjs +1 -1
- package/utilities/valueFromAST.js.flow +5 -13
- package/validation/ValidationContext.js +184 -0
- package/validation/ValidationContext.js.flow +221 -0
- package/validation/ValidationContext.mjs +177 -0
- package/validation/index.js +12 -7
- package/validation/index.js.flow +5 -1
- package/validation/index.mjs +5 -1
- package/validation/rules/ExecutableDefinitions.js.flow +1 -1
- package/validation/rules/FieldsOnCorrectType.js.flow +1 -1
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +1 -1
- package/validation/rules/KnownArgumentNames.js.flow +1 -1
- package/validation/rules/KnownDirectives.js.flow +1 -1
- package/validation/rules/KnownFragmentNames.js.flow +1 -1
- package/validation/rules/KnownTypeNames.js.flow +1 -1
- package/validation/rules/LoneAnonymousOperation.js.flow +1 -1
- package/validation/rules/NoFragmentCycles.js.flow +1 -1
- package/validation/rules/NoUndefinedVariables.js.flow +1 -1
- package/validation/rules/NoUnusedFragments.js.flow +1 -1
- package/validation/rules/NoUnusedVariables.js.flow +1 -1
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +1 -1
- package/validation/rules/PossibleFragmentSpreads.js.flow +1 -1
- package/validation/rules/ProvidedNonNullArguments.js.flow +1 -1
- package/validation/rules/ScalarLeafs.js.flow +1 -1
- package/validation/rules/SingleFieldSubscriptions.js.flow +1 -1
- package/validation/rules/UniqueArgumentNames.js.flow +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +1 -1
- package/validation/rules/UniqueFragmentNames.js.flow +1 -1
- package/validation/rules/UniqueInputFieldNames.js.flow +1 -1
- package/validation/rules/UniqueOperationNames.js.flow +1 -1
- package/validation/rules/UniqueVariableNames.js.flow +1 -1
- package/validation/rules/ValuesOfCorrectType.js.flow +1 -1
- package/validation/rules/VariablesAreInputTypes.js.flow +1 -1
- package/validation/rules/VariablesDefaultValueAllowed.js.flow +1 -1
- package/validation/rules/VariablesInAllowedPosition.js +8 -10
- package/validation/rules/VariablesInAllowedPosition.js.flow +2 -3
- package/validation/rules/VariablesInAllowedPosition.mjs +1 -2
- package/validation/specifiedRules.js.flow +1 -1
- package/validation/validate.js +15 -172
- package/validation/validate.js.flow +2 -208
- package/validation/validate.mjs +2 -164
- package/jsutils/getPromise.js +0 -27
- package/jsutils/getPromise.js.flow +0 -24
- package/jsutils/getPromise.mjs +0 -20
- package/type/wrappers.js +0 -89
- package/type/wrappers.js.flow +0 -91
- package/type/wrappers.mjs +0 -80
|
@@ -14,6 +14,7 @@ import { valueFromAST } from './valueFromAST';
|
|
|
14
14
|
import blockStringValue from '../language/blockStringValue';
|
|
15
15
|
import { TokenKind } from '../language/lexer';
|
|
16
16
|
import { parse } from '../language/parser';
|
|
17
|
+
import type { ParseOptions } from '../language/parser';
|
|
17
18
|
import type { Source } from '../language/source';
|
|
18
19
|
import { getDirectiveValues } from '../execution/values';
|
|
19
20
|
import { Kind } from '../language/kinds';
|
|
@@ -48,10 +49,10 @@ import {
|
|
|
48
49
|
GraphQLUnionType,
|
|
49
50
|
GraphQLEnumType,
|
|
50
51
|
GraphQLInputObjectType,
|
|
52
|
+
GraphQLList,
|
|
53
|
+
GraphQLNonNull,
|
|
51
54
|
} from '../type/definition';
|
|
52
55
|
|
|
53
|
-
import { GraphQLList, GraphQLNonNull } from '../type/wrappers';
|
|
54
|
-
|
|
55
56
|
import {
|
|
56
57
|
GraphQLDirective,
|
|
57
58
|
GraphQLSkipDirective,
|
|
@@ -72,7 +73,7 @@ import type {
|
|
|
72
73
|
GraphQLFieldConfig,
|
|
73
74
|
} from '../type/definition';
|
|
74
75
|
|
|
75
|
-
type
|
|
76
|
+
export type BuildSchemaOptions = {
|
|
76
77
|
...GraphQLSchemaValidationOptions,
|
|
77
78
|
|
|
78
79
|
/**
|
|
@@ -83,7 +84,7 @@ type Options = {|
|
|
|
83
84
|
* Default: false
|
|
84
85
|
*/
|
|
85
86
|
commentDescriptions?: boolean,
|
|
86
|
-
|
|
87
|
+
};
|
|
87
88
|
|
|
88
89
|
function buildWrappedType(
|
|
89
90
|
innerType: GraphQLType,
|
|
@@ -128,7 +129,7 @@ function getNamedTypeNode(typeNode: TypeNode): NamedTypeNode {
|
|
|
128
129
|
*/
|
|
129
130
|
export function buildASTSchema(
|
|
130
131
|
ast: DocumentNode,
|
|
131
|
-
options?:
|
|
132
|
+
options?: BuildSchemaOptions,
|
|
132
133
|
): GraphQLSchema {
|
|
133
134
|
if (!ast || ast.kind !== Kind.DOCUMENT) {
|
|
134
135
|
throw new Error('Must provide a document ast.');
|
|
@@ -183,8 +184,7 @@ export function buildASTSchema(
|
|
|
183
184
|
},
|
|
184
185
|
);
|
|
185
186
|
|
|
186
|
-
const types =
|
|
187
|
-
|
|
187
|
+
const types = definitionBuilder.buildTypes(typeDefs);
|
|
188
188
|
const directives = directiveDefs.map(def =>
|
|
189
189
|
definitionBuilder.buildDirective(def),
|
|
190
190
|
);
|
|
@@ -246,13 +246,13 @@ type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;
|
|
|
246
246
|
|
|
247
247
|
export class ASTDefinitionBuilder {
|
|
248
248
|
_typeDefinitionsMap: TypeDefinitionsMap;
|
|
249
|
-
_options: ?
|
|
249
|
+
_options: ?BuildSchemaOptions;
|
|
250
250
|
_resolveType: TypeResolver;
|
|
251
251
|
_cache: ObjMap<GraphQLNamedType>;
|
|
252
252
|
|
|
253
253
|
constructor(
|
|
254
254
|
typeDefinitionsMap: TypeDefinitionsMap,
|
|
255
|
-
options: ?
|
|
255
|
+
options: ?BuildSchemaOptions,
|
|
256
256
|
resolveType: TypeResolver,
|
|
257
257
|
) {
|
|
258
258
|
this._typeDefinitionsMap = typeDefinitionsMap;
|
|
@@ -265,6 +265,12 @@ export class ASTDefinitionBuilder {
|
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
buildTypes(
|
|
269
|
+
nodes: $ReadOnlyArray<NamedTypeNode | TypeDefinitionNode>,
|
|
270
|
+
): Array<GraphQLNamedType> {
|
|
271
|
+
return nodes.map(node => this.buildType(node));
|
|
272
|
+
}
|
|
273
|
+
|
|
268
274
|
buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType {
|
|
269
275
|
const typeName = node.name.value;
|
|
270
276
|
if (!this._cache[typeName]) {
|
|
@@ -333,11 +339,15 @@ export class ASTDefinitionBuilder {
|
|
|
333
339
|
|
|
334
340
|
_makeTypeDef(def: ObjectTypeDefinitionNode) {
|
|
335
341
|
const typeName = def.name.value;
|
|
342
|
+
const interfaces = def.interfaces;
|
|
336
343
|
return new GraphQLObjectType({
|
|
337
344
|
name: typeName,
|
|
338
345
|
description: getDescription(def, this._options),
|
|
339
346
|
fields: () => this._makeFieldDefMap(def),
|
|
340
|
-
|
|
347
|
+
// Note: While this could make early assertions to get the correctly
|
|
348
|
+
// typed values, that would throw immediately while type system
|
|
349
|
+
// validation with validateSchema() will produce more actionable results.
|
|
350
|
+
interfaces: interfaces ? () => (this.buildTypes(interfaces): any) : [],
|
|
341
351
|
astNode: def,
|
|
342
352
|
});
|
|
343
353
|
}
|
|
@@ -354,16 +364,6 @@ export class ASTDefinitionBuilder {
|
|
|
354
364
|
: {};
|
|
355
365
|
}
|
|
356
366
|
|
|
357
|
-
_makeImplementedInterfaces(def: ObjectTypeDefinitionNode) {
|
|
358
|
-
return (
|
|
359
|
-
def.interfaces &&
|
|
360
|
-
// Note: While this could make early assertions to get the correctly
|
|
361
|
-
// typed values, that would throw immediately while type system
|
|
362
|
-
// validation with validateSchema() will produce more actionable results.
|
|
363
|
-
def.interfaces.map(iface => (this.buildType(iface): any))
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
367
|
_makeInputValues(values: $ReadOnlyArray<InputValueDefinitionNode>) {
|
|
368
368
|
return keyValMap(
|
|
369
369
|
values,
|
|
@@ -418,7 +418,7 @@ export class ASTDefinitionBuilder {
|
|
|
418
418
|
// Note: While this could make assertions to get the correctly typed
|
|
419
419
|
// values below, that would throw immediately while type system
|
|
420
420
|
// validation with validateSchema() will produce more actionable results.
|
|
421
|
-
types: def.types ?
|
|
421
|
+
types: def.types ? (this.buildTypes(def.types): any) : [],
|
|
422
422
|
astNode: def,
|
|
423
423
|
});
|
|
424
424
|
}
|
|
@@ -464,7 +464,7 @@ function getDeprecationReason(
|
|
|
464
464
|
*/
|
|
465
465
|
export function getDescription(
|
|
466
466
|
node: { +description?: StringValueNode, +loc?: Location },
|
|
467
|
-
options: ?
|
|
467
|
+
options: ?BuildSchemaOptions,
|
|
468
468
|
): void | string {
|
|
469
469
|
if (node.description) {
|
|
470
470
|
return node.description.value;
|
|
@@ -503,6 +503,9 @@ function getLeadingCommentBlock(node): void | string {
|
|
|
503
503
|
* A helper function to build a GraphQLSchema directly from a source
|
|
504
504
|
* document.
|
|
505
505
|
*/
|
|
506
|
-
export function buildSchema(
|
|
507
|
-
|
|
506
|
+
export function buildSchema(
|
|
507
|
+
source: string | Source,
|
|
508
|
+
options?: BuildSchemaOptions & ParseOptions,
|
|
509
|
+
): GraphQLSchema {
|
|
510
|
+
return buildASTSchema(parse(source, options), options);
|
|
508
511
|
}
|
|
@@ -20,9 +20,7 @@ import { parse } from '../language/parser';
|
|
|
20
20
|
import { getDirectiveValues } from '../execution/values';
|
|
21
21
|
import { Kind } from '../language/kinds';
|
|
22
22
|
|
|
23
|
-
import { assertNullableType, GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType } from '../type/definition';
|
|
24
|
-
|
|
25
|
-
import { GraphQLList, GraphQLNonNull } from '../type/wrappers';
|
|
23
|
+
import { assertNullableType, GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull } from '../type/definition';
|
|
26
24
|
|
|
27
25
|
import { GraphQLDirective, GraphQLSkipDirective, GraphQLIncludeDirective, GraphQLDeprecatedDirective } from '../type/directives';
|
|
28
26
|
|
|
@@ -116,10 +114,7 @@ export function buildASTSchema(ast, options) {
|
|
|
116
114
|
throw new Error('Type "' + typeRef.name.value + '" not found in document.');
|
|
117
115
|
});
|
|
118
116
|
|
|
119
|
-
var types =
|
|
120
|
-
return definitionBuilder.buildType(def);
|
|
121
|
-
});
|
|
122
|
-
|
|
117
|
+
var types = definitionBuilder.buildTypes(typeDefs);
|
|
123
118
|
var directives = directiveDefs.map(function (def) {
|
|
124
119
|
return definitionBuilder.buildDirective(def);
|
|
125
120
|
});
|
|
@@ -187,6 +182,14 @@ export var ASTDefinitionBuilder = function () {
|
|
|
187
182
|
});
|
|
188
183
|
}
|
|
189
184
|
|
|
185
|
+
ASTDefinitionBuilder.prototype.buildTypes = function buildTypes(nodes) {
|
|
186
|
+
var _this = this;
|
|
187
|
+
|
|
188
|
+
return nodes.map(function (node) {
|
|
189
|
+
return _this.buildType(node);
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
190
193
|
ASTDefinitionBuilder.prototype.buildType = function buildType(node) {
|
|
191
194
|
var typeName = node.name.value;
|
|
192
195
|
if (!this._cache[typeName]) {
|
|
@@ -250,44 +253,36 @@ export var ASTDefinitionBuilder = function () {
|
|
|
250
253
|
};
|
|
251
254
|
|
|
252
255
|
ASTDefinitionBuilder.prototype._makeTypeDef = function _makeTypeDef(def) {
|
|
253
|
-
var
|
|
256
|
+
var _this2 = this;
|
|
254
257
|
|
|
255
258
|
var typeName = def.name.value;
|
|
259
|
+
var interfaces = def.interfaces;
|
|
256
260
|
return new GraphQLObjectType({
|
|
257
261
|
name: typeName,
|
|
258
262
|
description: getDescription(def, this._options),
|
|
259
263
|
fields: function fields() {
|
|
260
|
-
return
|
|
261
|
-
},
|
|
262
|
-
interfaces: function interfaces() {
|
|
263
|
-
return _this._makeImplementedInterfaces(def);
|
|
264
|
+
return _this2._makeFieldDefMap(def);
|
|
264
265
|
},
|
|
266
|
+
// Note: While this could make early assertions to get the correctly
|
|
267
|
+
// typed values, that would throw immediately while type system
|
|
268
|
+
// validation with validateSchema() will produce more actionable results.
|
|
269
|
+
interfaces: interfaces ? function () {
|
|
270
|
+
return _this2.buildTypes(interfaces);
|
|
271
|
+
} : [],
|
|
265
272
|
astNode: def
|
|
266
273
|
});
|
|
267
274
|
};
|
|
268
275
|
|
|
269
276
|
ASTDefinitionBuilder.prototype._makeFieldDefMap = function _makeFieldDefMap(def) {
|
|
270
|
-
var
|
|
277
|
+
var _this3 = this;
|
|
271
278
|
|
|
272
279
|
return def.fields ? keyValMap(def.fields, function (field) {
|
|
273
280
|
return field.name.value;
|
|
274
281
|
}, function (field) {
|
|
275
|
-
return
|
|
282
|
+
return _this3.buildField(field);
|
|
276
283
|
}) : {};
|
|
277
284
|
};
|
|
278
285
|
|
|
279
|
-
ASTDefinitionBuilder.prototype._makeImplementedInterfaces = function _makeImplementedInterfaces(def) {
|
|
280
|
-
var _this3 = this;
|
|
281
|
-
|
|
282
|
-
return def.interfaces &&
|
|
283
|
-
// Note: While this could make early assertions to get the correctly
|
|
284
|
-
// typed values, that would throw immediately while type system
|
|
285
|
-
// validation with validateSchema() will produce more actionable results.
|
|
286
|
-
def.interfaces.map(function (iface) {
|
|
287
|
-
return _this3.buildType(iface);
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
|
|
291
286
|
ASTDefinitionBuilder.prototype._makeInputValues = function _makeInputValues(values) {
|
|
292
287
|
var _this4 = this;
|
|
293
288
|
|
|
@@ -339,17 +334,13 @@ export var ASTDefinitionBuilder = function () {
|
|
|
339
334
|
};
|
|
340
335
|
|
|
341
336
|
ASTDefinitionBuilder.prototype._makeUnionDef = function _makeUnionDef(def) {
|
|
342
|
-
var _this7 = this;
|
|
343
|
-
|
|
344
337
|
return new GraphQLUnionType({
|
|
345
338
|
name: def.name.value,
|
|
346
339
|
description: getDescription(def, this._options),
|
|
347
340
|
// Note: While this could make assertions to get the correctly typed
|
|
348
341
|
// values below, that would throw immediately while type system
|
|
349
342
|
// validation with validateSchema() will produce more actionable results.
|
|
350
|
-
types: def.types ? def.types
|
|
351
|
-
return _this7.buildType(t);
|
|
352
|
-
}) : [],
|
|
343
|
+
types: def.types ? this.buildTypes(def.types) : [],
|
|
353
344
|
astNode: def
|
|
354
345
|
});
|
|
355
346
|
};
|
|
@@ -366,13 +357,13 @@ export var ASTDefinitionBuilder = function () {
|
|
|
366
357
|
};
|
|
367
358
|
|
|
368
359
|
ASTDefinitionBuilder.prototype._makeInputObjectDef = function _makeInputObjectDef(def) {
|
|
369
|
-
var
|
|
360
|
+
var _this7 = this;
|
|
370
361
|
|
|
371
362
|
return new GraphQLInputObjectType({
|
|
372
363
|
name: def.name.value,
|
|
373
364
|
description: getDescription(def, this._options),
|
|
374
365
|
fields: function fields() {
|
|
375
|
-
return def.fields ?
|
|
366
|
+
return def.fields ? _this7._makeInputValues(def.fields) : {};
|
|
376
367
|
},
|
|
377
368
|
astNode: def
|
|
378
369
|
});
|
|
@@ -430,6 +421,6 @@ function getLeadingCommentBlock(node) {
|
|
|
430
421
|
* A helper function to build a GraphQLSchema directly from a source
|
|
431
422
|
* document.
|
|
432
423
|
*/
|
|
433
|
-
export function buildSchema(source) {
|
|
434
|
-
return buildASTSchema(parse(source));
|
|
424
|
+
export function buildSchema(source, options) {
|
|
425
|
+
return buildASTSchema(parse(source, options), options);
|
|
435
426
|
}
|
|
@@ -27,8 +27,6 @@ var _directiveLocation = require('../language/directiveLocation');
|
|
|
27
27
|
|
|
28
28
|
var _definition = require('../type/definition');
|
|
29
29
|
|
|
30
|
-
var _wrappers = require('../type/wrappers');
|
|
31
|
-
|
|
32
30
|
var _directives = require('../type/directives');
|
|
33
31
|
|
|
34
32
|
var _introspection = require('../type/introspection');
|
|
@@ -49,15 +47,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
49
47
|
* This function expects a complete introspection result. Don't forget to check
|
|
50
48
|
* the "errors" field of a server response before calling this function.
|
|
51
49
|
*/
|
|
52
|
-
/**
|
|
53
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
54
|
-
*
|
|
55
|
-
* This source code is licensed under the MIT license found in the
|
|
56
|
-
* LICENSE file in the root directory of this source tree.
|
|
57
|
-
*
|
|
58
|
-
* strict
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
50
|
function buildClientSchema(introspection, options) {
|
|
62
51
|
// Get the schema from the introspection result.
|
|
63
52
|
var schemaIntrospection = introspection.__schema;
|
|
@@ -82,7 +71,7 @@ function buildClientSchema(introspection, options) {
|
|
|
82
71
|
if (!itemRef) {
|
|
83
72
|
throw new Error('Decorated type deeper than introspection query.');
|
|
84
73
|
}
|
|
85
|
-
return (0,
|
|
74
|
+
return (0, _definition.GraphQLList)(getType(itemRef));
|
|
86
75
|
}
|
|
87
76
|
if (typeRef.kind === _introspection.TypeKind.NON_NULL) {
|
|
88
77
|
var nullableRef = typeRef.ofType;
|
|
@@ -90,7 +79,7 @@ function buildClientSchema(introspection, options) {
|
|
|
90
79
|
throw new Error('Decorated type deeper than introspection query.');
|
|
91
80
|
}
|
|
92
81
|
var nullableType = getType(nullableRef);
|
|
93
|
-
return (0,
|
|
82
|
+
return (0, _definition.GraphQLNonNull)((0, _definition.assertNullableType)(nullableType));
|
|
94
83
|
}
|
|
95
84
|
if (!typeRef.name) {
|
|
96
85
|
throw new Error('Unknown type reference: ' + JSON.stringify(typeRef));
|
|
@@ -309,4 +298,11 @@ function buildClientSchema(introspection, options) {
|
|
|
309
298
|
assumeValid: options && options.assumeValid,
|
|
310
299
|
allowedLegacyNames: options && options.allowedLegacyNames
|
|
311
300
|
});
|
|
312
|
-
}
|
|
301
|
+
} /**
|
|
302
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
303
|
+
*
|
|
304
|
+
* This source code is licensed under the MIT license found in the
|
|
305
|
+
* LICENSE file in the root directory of this source tree.
|
|
306
|
+
*
|
|
307
|
+
* strict
|
|
308
|
+
*/
|
|
@@ -25,13 +25,13 @@ import {
|
|
|
25
25
|
GraphQLUnionType,
|
|
26
26
|
GraphQLEnumType,
|
|
27
27
|
GraphQLInputObjectType,
|
|
28
|
+
GraphQLList,
|
|
29
|
+
GraphQLNonNull,
|
|
28
30
|
assertNullableType,
|
|
29
31
|
assertObjectType,
|
|
30
32
|
assertInterfaceType,
|
|
31
33
|
} from '../type/definition';
|
|
32
34
|
|
|
33
|
-
import { GraphQLList, GraphQLNonNull } from '../type/wrappers';
|
|
34
|
-
|
|
35
35
|
import type {
|
|
36
36
|
GraphQLType,
|
|
37
37
|
GraphQLInputType,
|
|
@@ -16,9 +16,7 @@ import { GraphQLSchema } from '../type/schema';
|
|
|
16
16
|
|
|
17
17
|
import { DirectiveLocation } from '../language/directiveLocation';
|
|
18
18
|
|
|
19
|
-
import { isInputType, isOutputType, GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, assertNullableType, assertObjectType, assertInterfaceType } from '../type/definition';
|
|
20
|
-
|
|
21
|
-
import { GraphQLList, GraphQLNonNull } from '../type/wrappers';
|
|
19
|
+
import { isInputType, isOutputType, GraphQLScalarType, GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, assertNullableType, assertObjectType, assertInterfaceType } from '../type/definition';
|
|
22
20
|
|
|
23
21
|
import { GraphQLDirective } from '../type/directives';
|
|
24
22
|
|
|
@@ -27,8 +27,6 @@ var _introspection = require('../type/introspection');
|
|
|
27
27
|
|
|
28
28
|
var _definition = require('../type/definition');
|
|
29
29
|
|
|
30
|
-
var _wrappers = require('../type/wrappers');
|
|
31
|
-
|
|
32
30
|
var _directives = require('../type/directives');
|
|
33
31
|
|
|
34
32
|
var _kinds = require('../language/kinds');
|
|
@@ -53,6 +51,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
53
51
|
* Provide true to use preceding comments as the description.
|
|
54
52
|
*
|
|
55
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
56
|
+
*
|
|
57
|
+
* This source code is licensed under the MIT license found in the
|
|
58
|
+
* LICENSE file in the root directory of this source tree.
|
|
59
|
+
*
|
|
60
|
+
* strict
|
|
61
|
+
*/
|
|
62
|
+
|
|
56
63
|
function extendSchema(schema, documentAST, options) {
|
|
57
64
|
!(0, _schema.isSchema)(schema) ? (0, _invariant2.default)(0, 'Must provide valid GraphQLSchema') : void 0;
|
|
58
65
|
|
|
@@ -84,6 +91,7 @@ function extendSchema(schema, documentAST, options) {
|
|
|
84
91
|
typeDefinitionMap[typeName] = def;
|
|
85
92
|
break;
|
|
86
93
|
case _kinds.Kind.OBJECT_TYPE_EXTENSION:
|
|
94
|
+
case _kinds.Kind.INTERFACE_TYPE_EXTENSION:
|
|
87
95
|
// Sanity check that this type extension exists within the
|
|
88
96
|
// schema's existing types.
|
|
89
97
|
var extendedTypeName = def.name.value;
|
|
@@ -91,21 +99,10 @@ function extendSchema(schema, documentAST, options) {
|
|
|
91
99
|
if (!existingType) {
|
|
92
100
|
throw new _GraphQLError.GraphQLError('Cannot extend type "' + extendedTypeName + '" because it does not ' + 'exist in the existing schema.', [def]);
|
|
93
101
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
typeExtensionsMap[extendedTypeName] =
|
|
98
|
-
break;
|
|
99
|
-
case _kinds.Kind.INTERFACE_TYPE_EXTENSION:
|
|
100
|
-
var extendedInterfaceTypeName = def.name.value;
|
|
101
|
-
var existingInterfaceType = schema.getType(extendedInterfaceTypeName);
|
|
102
|
-
if (!existingInterfaceType) {
|
|
103
|
-
throw new _GraphQLError.GraphQLError('Cannot extend interface "' + extendedInterfaceTypeName + '" because ' + 'it does not exist in the existing schema.', [def]);
|
|
104
|
-
}
|
|
105
|
-
if (!(0, _definition.isInterfaceType)(existingInterfaceType)) {
|
|
106
|
-
throw new _GraphQLError.GraphQLError('Cannot extend non-interface type "' + extendedInterfaceTypeName + '".', [def]);
|
|
107
|
-
}
|
|
108
|
-
typeExtensionsMap[extendedInterfaceTypeName] = appendExtensionToTypeExtensions(def, typeExtensionsMap[extendedInterfaceTypeName]);
|
|
102
|
+
checkExtensionNode(existingType, def);
|
|
103
|
+
|
|
104
|
+
var existingTypeExtensions = typeExtensionsMap[extendedTypeName];
|
|
105
|
+
typeExtensionsMap[extendedTypeName] = existingTypeExtensions ? existingTypeExtensions.concat([def]) : [def];
|
|
109
106
|
break;
|
|
110
107
|
case _kinds.Kind.DIRECTIVE_DEFINITION:
|
|
111
108
|
var directiveName = def.name.value;
|
|
@@ -142,9 +139,6 @@ function extendSchema(schema, documentAST, options) {
|
|
|
142
139
|
var extendTypeCache = Object.create(null);
|
|
143
140
|
|
|
144
141
|
// Get the root Query, Mutation, and Subscription object types.
|
|
145
|
-
// Note: While this could make early assertions to get the correctly
|
|
146
|
-
// typed values below, that would throw immediately while type system
|
|
147
|
-
// validation with validateSchema() will produce more actionable results.
|
|
148
142
|
var existingQueryType = schema.getQueryType();
|
|
149
143
|
var queryType = existingQueryType ? getExtendedType(existingQueryType) : null;
|
|
150
144
|
|
|
@@ -156,9 +150,7 @@ function extendSchema(schema, documentAST, options) {
|
|
|
156
150
|
|
|
157
151
|
var types = [].concat((0, _objectValues2.default)(schema.getTypeMap()).map(function (type) {
|
|
158
152
|
return getExtendedType(type);
|
|
159
|
-
}), (0, _objectValues2.default)(typeDefinitionMap)
|
|
160
|
-
return astBuilder.buildType(type);
|
|
161
|
-
}));
|
|
153
|
+
}), astBuilder.buildTypes((0, _objectValues2.default)(typeDefinitionMap)));
|
|
162
154
|
|
|
163
155
|
// Support both original legacy names and extended legacy names.
|
|
164
156
|
var schemaAllowedLegacyNames = schema.__allowedLegacyNames;
|
|
@@ -176,14 +168,6 @@ function extendSchema(schema, documentAST, options) {
|
|
|
176
168
|
allowedLegacyNames: allowedLegacyNames
|
|
177
169
|
});
|
|
178
170
|
|
|
179
|
-
function appendExtensionToTypeExtensions(extension, existingTypeExtensions) {
|
|
180
|
-
if (!existingTypeExtensions) {
|
|
181
|
-
return [extension];
|
|
182
|
-
}
|
|
183
|
-
existingTypeExtensions.push(extension);
|
|
184
|
-
return existingTypeExtensions;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
171
|
// Below are functions used for producing this schema that have closed over
|
|
188
172
|
// this scope and have access to the schema, cache, and newly defined types.
|
|
189
173
|
|
|
@@ -320,18 +304,26 @@ function extendSchema(schema, documentAST, options) {
|
|
|
320
304
|
|
|
321
305
|
function extendFieldType(typeDef) {
|
|
322
306
|
if ((0, _definition.isListType)(typeDef)) {
|
|
323
|
-
return (0,
|
|
307
|
+
return (0, _definition.GraphQLList)(extendFieldType(typeDef.ofType));
|
|
324
308
|
}
|
|
325
309
|
if ((0, _definition.isNonNullType)(typeDef)) {
|
|
326
|
-
return (0,
|
|
310
|
+
return (0, _definition.GraphQLNonNull)(extendFieldType(typeDef.ofType));
|
|
327
311
|
}
|
|
328
312
|
return getExtendedType(typeDef);
|
|
329
313
|
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function checkExtensionNode(type, node) {
|
|
317
|
+
switch (node.kind) {
|
|
318
|
+
case _kinds.Kind.OBJECT_TYPE_EXTENSION:
|
|
319
|
+
if (!(0, _definition.isObjectType)(type)) {
|
|
320
|
+
throw new _GraphQLError.GraphQLError('Cannot extend non-object type "' + type.name + '".', [node]);
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
case _kinds.Kind.INTERFACE_TYPE_EXTENSION:
|
|
324
|
+
if (!(0, _definition.isInterfaceType)(type)) {
|
|
325
|
+
throw new _GraphQLError.GraphQLError('Cannot extend non-interface type "' + type.name + '".', [node]);
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
@@ -23,23 +23,19 @@ import {
|
|
|
23
23
|
isUnionType,
|
|
24
24
|
isListType,
|
|
25
25
|
isNonNullType,
|
|
26
|
+
GraphQLList,
|
|
27
|
+
GraphQLNonNull,
|
|
26
28
|
GraphQLObjectType,
|
|
27
29
|
GraphQLInterfaceType,
|
|
28
30
|
GraphQLUnionType,
|
|
29
31
|
} from '../type/definition';
|
|
30
|
-
import { GraphQLList, GraphQLNonNull } from '../type/wrappers';
|
|
31
32
|
|
|
32
33
|
import { GraphQLDirective } from '../type/directives';
|
|
33
34
|
|
|
34
35
|
import { Kind } from '../language/kinds';
|
|
35
36
|
|
|
36
37
|
import type { GraphQLType, GraphQLNamedType } from '../type/definition';
|
|
37
|
-
|
|
38
|
-
import type {
|
|
39
|
-
DocumentNode,
|
|
40
|
-
DirectiveDefinitionNode,
|
|
41
|
-
TypeExtensionNode,
|
|
42
|
-
} from '../language/ast';
|
|
38
|
+
import type { DocumentNode, DirectiveDefinitionNode } from '../language/ast';
|
|
43
39
|
|
|
44
40
|
type Options = {|
|
|
45
41
|
...GraphQLSchemaValidationOptions,
|
|
@@ -114,6 +110,7 @@ export function extendSchema(
|
|
|
114
110
|
typeDefinitionMap[typeName] = def;
|
|
115
111
|
break;
|
|
116
112
|
case Kind.OBJECT_TYPE_EXTENSION:
|
|
113
|
+
case Kind.INTERFACE_TYPE_EXTENSION:
|
|
117
114
|
// Sanity check that this type extension exists within the
|
|
118
115
|
// schema's existing types.
|
|
119
116
|
const extendedTypeName = def.name.value;
|
|
@@ -125,39 +122,12 @@ export function extendSchema(
|
|
|
125
122
|
[def],
|
|
126
123
|
);
|
|
127
124
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
typeExtensionsMap[extendedTypeName] = appendExtensionToTypeExtensions(
|
|
135
|
-
def,
|
|
136
|
-
typeExtensionsMap[extendedTypeName],
|
|
137
|
-
);
|
|
138
|
-
break;
|
|
139
|
-
case Kind.INTERFACE_TYPE_EXTENSION:
|
|
140
|
-
const extendedInterfaceTypeName = def.name.value;
|
|
141
|
-
const existingInterfaceType = schema.getType(extendedInterfaceTypeName);
|
|
142
|
-
if (!existingInterfaceType) {
|
|
143
|
-
throw new GraphQLError(
|
|
144
|
-
`Cannot extend interface "${extendedInterfaceTypeName}" because ` +
|
|
145
|
-
'it does not exist in the existing schema.',
|
|
146
|
-
[def],
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
if (!isInterfaceType(existingInterfaceType)) {
|
|
150
|
-
throw new GraphQLError(
|
|
151
|
-
`Cannot extend non-interface type "${extendedInterfaceTypeName}".`,
|
|
152
|
-
[def],
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
typeExtensionsMap[
|
|
156
|
-
extendedInterfaceTypeName
|
|
157
|
-
] = appendExtensionToTypeExtensions(
|
|
158
|
-
def,
|
|
159
|
-
typeExtensionsMap[extendedInterfaceTypeName],
|
|
160
|
-
);
|
|
125
|
+
checkExtensionNode(existingType, def);
|
|
126
|
+
|
|
127
|
+
const existingTypeExtensions = typeExtensionsMap[extendedTypeName];
|
|
128
|
+
typeExtensionsMap[extendedTypeName] = existingTypeExtensions
|
|
129
|
+
? existingTypeExtensions.concat([def])
|
|
130
|
+
: [def];
|
|
161
131
|
break;
|
|
162
132
|
case Kind.DIRECTIVE_DEFINITION:
|
|
163
133
|
const directiveName = def.name.value;
|
|
@@ -212,9 +182,6 @@ export function extendSchema(
|
|
|
212
182
|
const extendTypeCache = Object.create(null);
|
|
213
183
|
|
|
214
184
|
// Get the root Query, Mutation, and Subscription object types.
|
|
215
|
-
// Note: While this could make early assertions to get the correctly
|
|
216
|
-
// typed values below, that would throw immediately while type system
|
|
217
|
-
// validation with validateSchema() will produce more actionable results.
|
|
218
185
|
const existingQueryType = schema.getQueryType();
|
|
219
186
|
const queryType = existingQueryType
|
|
220
187
|
? getExtendedType(existingQueryType)
|
|
@@ -235,7 +202,7 @@ export function extendSchema(
|
|
|
235
202
|
// that any type not directly referenced by a field will get created.
|
|
236
203
|
...objectValues(schema.getTypeMap()).map(type => getExtendedType(type)),
|
|
237
204
|
// Do the same with new types.
|
|
238
|
-
...objectValues(typeDefinitionMap)
|
|
205
|
+
...astBuilder.buildTypes(objectValues(typeDefinitionMap)),
|
|
239
206
|
];
|
|
240
207
|
|
|
241
208
|
// Support both original legacy names and extended legacy names.
|
|
@@ -257,17 +224,6 @@ export function extendSchema(
|
|
|
257
224
|
allowedLegacyNames,
|
|
258
225
|
});
|
|
259
226
|
|
|
260
|
-
function appendExtensionToTypeExtensions(
|
|
261
|
-
extension: TypeExtensionNode,
|
|
262
|
-
existingTypeExtensions: ?Array<TypeExtensionNode>,
|
|
263
|
-
): Array<TypeExtensionNode> {
|
|
264
|
-
if (!existingTypeExtensions) {
|
|
265
|
-
return [extension];
|
|
266
|
-
}
|
|
267
|
-
existingTypeExtensions.push(extension);
|
|
268
|
-
return existingTypeExtensions;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
227
|
// Below are functions used for producing this schema that have closed over
|
|
272
228
|
// this scope and have access to the schema, cache, and newly defined types.
|
|
273
229
|
|
|
@@ -420,3 +376,24 @@ export function extendSchema(
|
|
|
420
376
|
return getExtendedType(typeDef);
|
|
421
377
|
}
|
|
422
378
|
}
|
|
379
|
+
|
|
380
|
+
function checkExtensionNode(type, node) {
|
|
381
|
+
switch (node.kind) {
|
|
382
|
+
case Kind.OBJECT_TYPE_EXTENSION:
|
|
383
|
+
if (!isObjectType(type)) {
|
|
384
|
+
throw new GraphQLError(
|
|
385
|
+
`Cannot extend non-object type "${type.name}".`,
|
|
386
|
+
[node],
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
break;
|
|
390
|
+
case Kind.INTERFACE_TYPE_EXTENSION:
|
|
391
|
+
if (!isInterfaceType(type)) {
|
|
392
|
+
throw new GraphQLError(
|
|
393
|
+
`Cannot extend non-interface type "${type.name}".`,
|
|
394
|
+
[node],
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|