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
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
5
3
|
*
|
|
6
4
|
* This source code is licensed under the MIT license found in the
|
|
7
5
|
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
7
|
+
*
|
|
10
8
|
*/
|
|
9
|
+
import objectValues from '../polyfills/objectValues';
|
|
11
10
|
import invariant from '../jsutils/invariant';
|
|
12
11
|
import keyMap from '../jsutils/keyMap';
|
|
13
12
|
import keyValMap from '../jsutils/keyValMap';
|
|
@@ -49,26 +48,36 @@ export function buildASTSchema(documentAST, options) {
|
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
var schemaDef;
|
|
52
|
-
var typeDefs = [];
|
|
53
51
|
var nodeMap = Object.create(null);
|
|
54
52
|
var directiveDefs = [];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
var _iteratorNormalCompletion = true;
|
|
54
|
+
var _didIteratorError = false;
|
|
55
|
+
var _iteratorError = undefined;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
for (var _iterator = documentAST.definitions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
59
|
+
var def = _step.value;
|
|
60
|
+
|
|
61
|
+
if (def.kind === Kind.SCHEMA_DEFINITION) {
|
|
62
|
+
schemaDef = def;
|
|
63
|
+
} else if (isTypeDefinitionNode(def)) {
|
|
64
|
+
nodeMap[def.name.value] = def;
|
|
65
|
+
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
|
66
|
+
directiveDefs.push(def);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
_didIteratorError = true;
|
|
71
|
+
_iteratorError = err;
|
|
72
|
+
} finally {
|
|
73
|
+
try {
|
|
74
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
75
|
+
_iterator.return();
|
|
76
|
+
}
|
|
77
|
+
} finally {
|
|
78
|
+
if (_didIteratorError) {
|
|
79
|
+
throw _iteratorError;
|
|
66
80
|
}
|
|
67
|
-
|
|
68
|
-
typeDefs.push(def);
|
|
69
|
-
nodeMap[typeName] = def;
|
|
70
|
-
} else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
|
|
71
|
-
directiveDefs.push(def);
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
|
|
@@ -77,8 +86,8 @@ export function buildASTSchema(documentAST, options) {
|
|
|
77
86
|
mutation: nodeMap.Mutation,
|
|
78
87
|
subscription: nodeMap.Subscription
|
|
79
88
|
};
|
|
80
|
-
var definitionBuilder = new ASTDefinitionBuilder(nodeMap, options, function (
|
|
81
|
-
throw new Error("Type \"".concat(
|
|
89
|
+
var definitionBuilder = new ASTDefinitionBuilder(nodeMap, options, function (typeName) {
|
|
90
|
+
throw new Error("Type \"".concat(typeName, "\" not found in document."));
|
|
82
91
|
});
|
|
83
92
|
var directives = directiveDefs.map(function (def) {
|
|
84
93
|
return definitionBuilder.buildDirective(def);
|
|
@@ -109,7 +118,7 @@ export function buildASTSchema(documentAST, options) {
|
|
|
109
118
|
query: operationTypes.query ? definitionBuilder.buildType(operationTypes.query) : null,
|
|
110
119
|
mutation: operationTypes.mutation ? definitionBuilder.buildType(operationTypes.mutation) : null,
|
|
111
120
|
subscription: operationTypes.subscription ? definitionBuilder.buildType(operationTypes.subscription) : null,
|
|
112
|
-
types:
|
|
121
|
+
types: objectValues(nodeMap).map(function (node) {
|
|
113
122
|
return definitionBuilder.buildType(node);
|
|
114
123
|
}),
|
|
115
124
|
directives: directives,
|
|
@@ -120,37 +129,26 @@ export function buildASTSchema(documentAST, options) {
|
|
|
120
129
|
|
|
121
130
|
function getOperationTypes(schema) {
|
|
122
131
|
var opTypes = {};
|
|
123
|
-
var
|
|
124
|
-
var
|
|
125
|
-
var
|
|
132
|
+
var _iteratorNormalCompletion2 = true;
|
|
133
|
+
var _didIteratorError2 = false;
|
|
134
|
+
var _iteratorError2 = undefined;
|
|
126
135
|
|
|
127
136
|
try {
|
|
128
|
-
for (var
|
|
129
|
-
var operationType =
|
|
130
|
-
|
|
131
|
-
var operation = operationType.operation;
|
|
132
|
-
|
|
133
|
-
if (opTypes[operation]) {
|
|
134
|
-
throw new Error("Must provide only one ".concat(operation, " type in schema."));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!nodeMap[_typeName]) {
|
|
138
|
-
throw new Error("Specified ".concat(operation, " type \"").concat(_typeName, "\" not found in document."));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
opTypes[operation] = operationType.type;
|
|
137
|
+
for (var _iterator2 = schema.operationTypes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
138
|
+
var operationType = _step2.value;
|
|
139
|
+
opTypes[operationType.operation] = operationType.type;
|
|
142
140
|
}
|
|
143
141
|
} catch (err) {
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
_didIteratorError2 = true;
|
|
143
|
+
_iteratorError2 = err;
|
|
146
144
|
} finally {
|
|
147
145
|
try {
|
|
148
|
-
if (!
|
|
149
|
-
|
|
146
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
147
|
+
_iterator2.return();
|
|
150
148
|
}
|
|
151
149
|
} finally {
|
|
152
|
-
if (
|
|
153
|
-
throw
|
|
150
|
+
if (_didIteratorError2) {
|
|
151
|
+
throw _iteratorError2;
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
154
|
}
|
|
@@ -162,14 +160,6 @@ export var ASTDefinitionBuilder =
|
|
|
162
160
|
/*#__PURE__*/
|
|
163
161
|
function () {
|
|
164
162
|
function ASTDefinitionBuilder(typeDefinitionsMap, options, resolveType) {
|
|
165
|
-
_defineProperty(this, "_typeDefinitionsMap", void 0);
|
|
166
|
-
|
|
167
|
-
_defineProperty(this, "_options", void 0);
|
|
168
|
-
|
|
169
|
-
_defineProperty(this, "_resolveType", void 0);
|
|
170
|
-
|
|
171
|
-
_defineProperty(this, "_cache", void 0);
|
|
172
|
-
|
|
173
163
|
this._typeDefinitionsMap = typeDefinitionsMap;
|
|
174
164
|
this._options = options;
|
|
175
165
|
this._resolveType = resolveType; // Initialize to the GraphQL built in scalars and introspection types.
|
|
@@ -187,7 +177,7 @@ function () {
|
|
|
187
177
|
if (!this._cache[typeName]) {
|
|
188
178
|
if (node.kind === Kind.NAMED_TYPE) {
|
|
189
179
|
var defNode = this._typeDefinitionsMap[typeName];
|
|
190
|
-
this._cache[typeName] = defNode ? this._makeSchemaDef(defNode) : this._resolveType(node);
|
|
180
|
+
this._cache[typeName] = defNode ? this._makeSchemaDef(defNode) : this._resolveType(node.name.value);
|
|
191
181
|
} else {
|
|
192
182
|
this._cache[typeName] = this._makeSchemaDef(node);
|
|
193
183
|
}
|
|
@@ -209,38 +199,60 @@ function () {
|
|
|
209
199
|
return this.buildType(typeNode);
|
|
210
200
|
};
|
|
211
201
|
|
|
212
|
-
_proto.buildDirective = function buildDirective(
|
|
202
|
+
_proto.buildDirective = function buildDirective(directive) {
|
|
203
|
+
var _this = this;
|
|
204
|
+
|
|
205
|
+
var locations = directive.locations.map(function (_ref) {
|
|
206
|
+
var value = _ref.value;
|
|
207
|
+
return value;
|
|
208
|
+
});
|
|
213
209
|
return new GraphQLDirective({
|
|
214
|
-
name:
|
|
215
|
-
description: getDescription(
|
|
216
|
-
locations:
|
|
217
|
-
|
|
210
|
+
name: directive.name.value,
|
|
211
|
+
description: getDescription(directive, this._options),
|
|
212
|
+
locations: locations,
|
|
213
|
+
args: keyByNameNode(directive.arguments || [], function (arg) {
|
|
214
|
+
return _this.buildArg(arg);
|
|
218
215
|
}),
|
|
219
|
-
|
|
220
|
-
astNode: directiveNode
|
|
216
|
+
astNode: directive
|
|
221
217
|
});
|
|
222
218
|
};
|
|
223
219
|
|
|
224
220
|
_proto.buildField = function buildField(field) {
|
|
221
|
+
var _this2 = this;
|
|
222
|
+
|
|
225
223
|
return {
|
|
226
224
|
// Note: While this could make assertions to get the correctly typed
|
|
227
225
|
// value, that would throw immediately while type system validation
|
|
228
226
|
// with validateSchema() will produce more actionable results.
|
|
229
227
|
type: this._buildWrappedType(field.type),
|
|
230
228
|
description: getDescription(field, this._options),
|
|
231
|
-
args: field.arguments
|
|
229
|
+
args: keyByNameNode(field.arguments || [], function (arg) {
|
|
230
|
+
return _this2.buildArg(arg);
|
|
231
|
+
}),
|
|
232
232
|
deprecationReason: getDeprecationReason(field),
|
|
233
233
|
astNode: field
|
|
234
234
|
};
|
|
235
235
|
};
|
|
236
236
|
|
|
237
|
+
_proto.buildArg = function buildArg(value) {
|
|
238
|
+
// Note: While this could make assertions to get the correctly typed
|
|
239
|
+
// value, that would throw immediately while type system validation
|
|
240
|
+
var type = this._buildWrappedType(value.type);
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
type: type,
|
|
244
|
+
description: getDescription(value, this._options),
|
|
245
|
+
defaultValue: valueFromAST(value.defaultValue, type),
|
|
246
|
+
astNode: value
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
237
250
|
_proto.buildInputField = function buildInputField(value) {
|
|
238
251
|
// Note: While this could make assertions to get the correctly typed
|
|
239
252
|
// value, that would throw immediately while type system validation
|
|
240
253
|
var type = this._buildWrappedType(value.type);
|
|
241
254
|
|
|
242
255
|
return {
|
|
243
|
-
name: value.name.value,
|
|
244
256
|
type: type,
|
|
245
257
|
description: getDescription(value, this._options),
|
|
246
258
|
defaultValue: valueFromAST(value.defaultValue, type),
|
|
@@ -256,129 +268,114 @@ function () {
|
|
|
256
268
|
};
|
|
257
269
|
};
|
|
258
270
|
|
|
259
|
-
_proto._makeSchemaDef = function _makeSchemaDef(
|
|
260
|
-
switch (
|
|
271
|
+
_proto._makeSchemaDef = function _makeSchemaDef(astNode) {
|
|
272
|
+
switch (astNode.kind) {
|
|
261
273
|
case Kind.OBJECT_TYPE_DEFINITION:
|
|
262
|
-
return this._makeTypeDef(
|
|
274
|
+
return this._makeTypeDef(astNode);
|
|
263
275
|
|
|
264
276
|
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
265
|
-
return this._makeInterfaceDef(
|
|
277
|
+
return this._makeInterfaceDef(astNode);
|
|
266
278
|
|
|
267
279
|
case Kind.ENUM_TYPE_DEFINITION:
|
|
268
|
-
return this._makeEnumDef(
|
|
280
|
+
return this._makeEnumDef(astNode);
|
|
269
281
|
|
|
270
282
|
case Kind.UNION_TYPE_DEFINITION:
|
|
271
|
-
return this._makeUnionDef(
|
|
283
|
+
return this._makeUnionDef(astNode);
|
|
272
284
|
|
|
273
285
|
case Kind.SCALAR_TYPE_DEFINITION:
|
|
274
|
-
return this._makeScalarDef(
|
|
286
|
+
return this._makeScalarDef(astNode);
|
|
275
287
|
|
|
276
288
|
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
277
|
-
return this._makeInputObjectDef(
|
|
289
|
+
return this._makeInputObjectDef(astNode);
|
|
278
290
|
|
|
279
291
|
default:
|
|
280
|
-
throw new Error("Type kind \"".concat(
|
|
292
|
+
throw new Error("Type kind \"".concat(astNode.kind, "\" not supported."));
|
|
281
293
|
}
|
|
282
294
|
};
|
|
283
295
|
|
|
284
|
-
_proto._makeTypeDef = function _makeTypeDef(
|
|
285
|
-
var _this = this;
|
|
286
|
-
|
|
287
|
-
var interfaces = def.interfaces;
|
|
288
|
-
return new GraphQLObjectType({
|
|
289
|
-
name: def.name.value,
|
|
290
|
-
description: getDescription(def, this._options),
|
|
291
|
-
fields: function fields() {
|
|
292
|
-
return _this._makeFieldDefMap(def);
|
|
293
|
-
},
|
|
294
|
-
// Note: While this could make early assertions to get the correctly
|
|
295
|
-
// typed values, that would throw immediately while type system
|
|
296
|
-
// validation with validateSchema() will produce more actionable results.
|
|
297
|
-
interfaces: interfaces ? function () {
|
|
298
|
-
return interfaces.map(function (ref) {
|
|
299
|
-
return _this.buildType(ref);
|
|
300
|
-
});
|
|
301
|
-
} : [],
|
|
302
|
-
astNode: def
|
|
303
|
-
});
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
_proto._makeFieldDefMap = function _makeFieldDefMap(def) {
|
|
307
|
-
var _this2 = this;
|
|
308
|
-
|
|
309
|
-
return def.fields ? keyValMap(def.fields, function (field) {
|
|
310
|
-
return field.name.value;
|
|
311
|
-
}, function (field) {
|
|
312
|
-
return _this2.buildField(field);
|
|
313
|
-
}) : {};
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
_proto._makeInputValues = function _makeInputValues(values) {
|
|
296
|
+
_proto._makeTypeDef = function _makeTypeDef(astNode) {
|
|
317
297
|
var _this3 = this;
|
|
318
298
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
299
|
+
var interfaceNodes = astNode.interfaces;
|
|
300
|
+
var fieldNodes = astNode.fields; // Note: While this could make assertions to get the correctly typed
|
|
301
|
+
// values below, that would throw immediately while type system
|
|
302
|
+
// validation with validateSchema() will produce more actionable results.
|
|
303
|
+
|
|
304
|
+
var interfaces = interfaceNodes && interfaceNodes.length > 0 ? function () {
|
|
305
|
+
return interfaceNodes.map(function (ref) {
|
|
306
|
+
return _this3.buildType(ref);
|
|
307
|
+
});
|
|
308
|
+
} : [];
|
|
309
|
+
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
|
310
|
+
return keyByNameNode(fieldNodes, function (field) {
|
|
311
|
+
return _this3.buildField(field);
|
|
312
|
+
});
|
|
313
|
+
} : Object.create(null);
|
|
314
|
+
return new GraphQLObjectType({
|
|
315
|
+
name: astNode.name.value,
|
|
316
|
+
description: getDescription(astNode, this._options),
|
|
317
|
+
interfaces: interfaces,
|
|
318
|
+
fields: fields,
|
|
319
|
+
astNode: astNode
|
|
323
320
|
});
|
|
324
321
|
};
|
|
325
322
|
|
|
326
|
-
_proto._makeInterfaceDef = function _makeInterfaceDef(
|
|
323
|
+
_proto._makeInterfaceDef = function _makeInterfaceDef(astNode) {
|
|
327
324
|
var _this4 = this;
|
|
328
325
|
|
|
326
|
+
var fieldNodes = astNode.fields;
|
|
327
|
+
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
|
328
|
+
return keyByNameNode(fieldNodes, function (field) {
|
|
329
|
+
return _this4.buildField(field);
|
|
330
|
+
});
|
|
331
|
+
} : Object.create(null);
|
|
329
332
|
return new GraphQLInterfaceType({
|
|
330
|
-
name:
|
|
331
|
-
description: getDescription(
|
|
332
|
-
fields:
|
|
333
|
-
|
|
334
|
-
},
|
|
335
|
-
astNode: def
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
_proto._makeEnumDef = function _makeEnumDef(def) {
|
|
340
|
-
return new GraphQLEnumType({
|
|
341
|
-
name: def.name.value,
|
|
342
|
-
description: getDescription(def, this._options),
|
|
343
|
-
values: this._makeValueDefMap(def),
|
|
344
|
-
astNode: def
|
|
333
|
+
name: astNode.name.value,
|
|
334
|
+
description: getDescription(astNode, this._options),
|
|
335
|
+
fields: fields,
|
|
336
|
+
astNode: astNode
|
|
345
337
|
});
|
|
346
338
|
};
|
|
347
339
|
|
|
348
|
-
_proto.
|
|
340
|
+
_proto._makeEnumDef = function _makeEnumDef(astNode) {
|
|
349
341
|
var _this5 = this;
|
|
350
342
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
343
|
+
var valueNodes = astNode.values || [];
|
|
344
|
+
return new GraphQLEnumType({
|
|
345
|
+
name: astNode.name.value,
|
|
346
|
+
description: getDescription(astNode, this._options),
|
|
347
|
+
values: keyByNameNode(valueNodes, function (value) {
|
|
348
|
+
return _this5.buildEnumValue(value);
|
|
349
|
+
}),
|
|
350
|
+
astNode: astNode
|
|
351
|
+
});
|
|
356
352
|
};
|
|
357
353
|
|
|
358
|
-
_proto._makeUnionDef = function _makeUnionDef(
|
|
354
|
+
_proto._makeUnionDef = function _makeUnionDef(astNode) {
|
|
359
355
|
var _this6 = this;
|
|
360
356
|
|
|
361
|
-
var
|
|
357
|
+
var typeNodes = astNode.types; // Note: While this could make assertions to get the correctly typed
|
|
358
|
+
// values below, that would throw immediately while type system
|
|
359
|
+
// validation with validateSchema() will produce more actionable results.
|
|
360
|
+
|
|
361
|
+
var types = typeNodes && typeNodes.length > 0 ? function () {
|
|
362
|
+
return typeNodes.map(function (ref) {
|
|
363
|
+
return _this6.buildType(ref);
|
|
364
|
+
});
|
|
365
|
+
} : [];
|
|
362
366
|
return new GraphQLUnionType({
|
|
363
|
-
name:
|
|
364
|
-
description: getDescription(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// validation with validateSchema() will produce more actionable results.
|
|
368
|
-
types: types ? function () {
|
|
369
|
-
return types.map(function (ref) {
|
|
370
|
-
return _this6.buildType(ref);
|
|
371
|
-
});
|
|
372
|
-
} : [],
|
|
373
|
-
astNode: def
|
|
367
|
+
name: astNode.name.value,
|
|
368
|
+
description: getDescription(astNode, this._options),
|
|
369
|
+
types: types,
|
|
370
|
+
astNode: astNode
|
|
374
371
|
});
|
|
375
372
|
};
|
|
376
373
|
|
|
377
|
-
_proto._makeScalarDef = function _makeScalarDef(
|
|
374
|
+
_proto._makeScalarDef = function _makeScalarDef(astNode) {
|
|
378
375
|
return new GraphQLScalarType({
|
|
379
|
-
name:
|
|
380
|
-
description: getDescription(
|
|
381
|
-
astNode:
|
|
376
|
+
name: astNode.name.value,
|
|
377
|
+
description: getDescription(astNode, this._options),
|
|
378
|
+
astNode: astNode,
|
|
382
379
|
serialize: function serialize(value) {
|
|
383
380
|
return value;
|
|
384
381
|
}
|
|
@@ -388,23 +385,34 @@ function () {
|
|
|
388
385
|
_proto._makeInputObjectDef = function _makeInputObjectDef(def) {
|
|
389
386
|
var _this7 = this;
|
|
390
387
|
|
|
388
|
+
var fields = def.fields;
|
|
391
389
|
return new GraphQLInputObjectType({
|
|
392
390
|
name: def.name.value,
|
|
393
391
|
description: getDescription(def, this._options),
|
|
394
|
-
fields: function
|
|
395
|
-
return
|
|
396
|
-
|
|
392
|
+
fields: fields ? function () {
|
|
393
|
+
return keyByNameNode(fields, function (field) {
|
|
394
|
+
return _this7.buildInputField(field);
|
|
395
|
+
});
|
|
396
|
+
} : Object.create(null),
|
|
397
397
|
astNode: def
|
|
398
398
|
});
|
|
399
399
|
};
|
|
400
400
|
|
|
401
401
|
return ASTDefinitionBuilder;
|
|
402
402
|
}();
|
|
403
|
+
|
|
404
|
+
function keyByNameNode(list, valFn) {
|
|
405
|
+
return keyValMap(list, function (_ref2) {
|
|
406
|
+
var name = _ref2.name;
|
|
407
|
+
return name.value;
|
|
408
|
+
}, valFn);
|
|
409
|
+
}
|
|
403
410
|
/**
|
|
404
411
|
* Given a field or enum value node, returns the string value for the
|
|
405
412
|
* deprecation reason.
|
|
406
413
|
*/
|
|
407
414
|
|
|
415
|
+
|
|
408
416
|
function getDeprecationReason(node) {
|
|
409
417
|
var deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
|
410
418
|
return deprecated && deprecated.reason;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.buildClientSchema = buildClientSchema;
|
|
7
7
|
|
|
8
|
+
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
|
9
|
+
|
|
8
10
|
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
|
9
11
|
|
|
10
12
|
var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
|
|
@@ -33,7 +35,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
33
35
|
* This source code is licensed under the MIT license found in the
|
|
34
36
|
* LICENSE file in the root directory of this source tree.
|
|
35
37
|
*
|
|
36
|
-
*
|
|
38
|
+
*
|
|
37
39
|
*/
|
|
38
40
|
|
|
39
41
|
/**
|
|
@@ -86,7 +88,7 @@ function buildClientSchema(introspection, options) {
|
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
if (!typeRef.name) {
|
|
89
|
-
throw new Error('Unknown type reference: ' +
|
|
91
|
+
throw new Error('Unknown type reference: ' + (0, _inspect.default)(typeRef));
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
return getNamedType(typeRef.name);
|
|
@@ -110,13 +112,13 @@ function buildClientSchema(introspection, options) {
|
|
|
110
112
|
|
|
111
113
|
function getInputType(typeRef) {
|
|
112
114
|
var type = getType(typeRef);
|
|
113
|
-
!(0, _definition.isInputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide input type for arguments.') : void 0;
|
|
115
|
+
!(0, _definition.isInputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide input type for arguments, but received: ' + (0, _inspect.default)(type) + '.') : void 0;
|
|
114
116
|
return type;
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
function getOutputType(typeRef) {
|
|
118
120
|
var type = getType(typeRef);
|
|
119
|
-
!(0, _definition.isOutputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide output type for fields.') : void 0;
|
|
121
|
+
!(0, _definition.isOutputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide output type for fields, but received: ' + (0, _inspect.default)(type) + '.') : void 0;
|
|
120
122
|
return type;
|
|
121
123
|
}
|
|
122
124
|
|
|
@@ -155,7 +157,7 @@ function buildClientSchema(introspection, options) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
throw new Error('Invalid or incomplete introspection result. Ensure that a full ' + 'introspection query is used in order to build a client schema:' +
|
|
160
|
+
throw new Error('Invalid or incomplete introspection result. Ensure that a full ' + 'introspection query is used in order to build a client schema:' + (0, _inspect.default)(type));
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
function buildScalarDef(scalarIntrospection) {
|
|
@@ -170,13 +172,15 @@ function buildClientSchema(introspection, options) {
|
|
|
170
172
|
|
|
171
173
|
function buildObjectDef(objectIntrospection) {
|
|
172
174
|
if (!objectIntrospection.interfaces) {
|
|
173
|
-
throw new Error('Introspection result missing interfaces: ' +
|
|
175
|
+
throw new Error('Introspection result missing interfaces: ' + (0, _inspect.default)(objectIntrospection));
|
|
174
176
|
}
|
|
175
177
|
|
|
176
178
|
return new _definition.GraphQLObjectType({
|
|
177
179
|
name: objectIntrospection.name,
|
|
178
180
|
description: objectIntrospection.description,
|
|
179
|
-
interfaces:
|
|
181
|
+
interfaces: function interfaces() {
|
|
182
|
+
return objectIntrospection.interfaces.map(getInterfaceType);
|
|
183
|
+
},
|
|
180
184
|
fields: function fields() {
|
|
181
185
|
return buildFieldDefMap(objectIntrospection);
|
|
182
186
|
}
|
|
@@ -195,19 +199,21 @@ function buildClientSchema(introspection, options) {
|
|
|
195
199
|
|
|
196
200
|
function buildUnionDef(unionIntrospection) {
|
|
197
201
|
if (!unionIntrospection.possibleTypes) {
|
|
198
|
-
throw new Error('Introspection result missing possibleTypes: ' +
|
|
202
|
+
throw new Error('Introspection result missing possibleTypes: ' + (0, _inspect.default)(unionIntrospection));
|
|
199
203
|
}
|
|
200
204
|
|
|
201
205
|
return new _definition.GraphQLUnionType({
|
|
202
206
|
name: unionIntrospection.name,
|
|
203
207
|
description: unionIntrospection.description,
|
|
204
|
-
types:
|
|
208
|
+
types: function types() {
|
|
209
|
+
return unionIntrospection.possibleTypes.map(getObjectType);
|
|
210
|
+
}
|
|
205
211
|
});
|
|
206
212
|
}
|
|
207
213
|
|
|
208
214
|
function buildEnumDef(enumIntrospection) {
|
|
209
215
|
if (!enumIntrospection.enumValues) {
|
|
210
|
-
throw new Error('Introspection result missing enumValues: ' +
|
|
216
|
+
throw new Error('Introspection result missing enumValues: ' + (0, _inspect.default)(enumIntrospection));
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
return new _definition.GraphQLEnumType({
|
|
@@ -226,7 +232,7 @@ function buildClientSchema(introspection, options) {
|
|
|
226
232
|
|
|
227
233
|
function buildInputObjectDef(inputObjectIntrospection) {
|
|
228
234
|
if (!inputObjectIntrospection.inputFields) {
|
|
229
|
-
throw new Error('Introspection result missing inputFields: ' +
|
|
235
|
+
throw new Error('Introspection result missing inputFields: ' + (0, _inspect.default)(inputObjectIntrospection));
|
|
230
236
|
}
|
|
231
237
|
|
|
232
238
|
return new _definition.GraphQLInputObjectType({
|
|
@@ -240,14 +246,14 @@ function buildClientSchema(introspection, options) {
|
|
|
240
246
|
|
|
241
247
|
function buildFieldDefMap(typeIntrospection) {
|
|
242
248
|
if (!typeIntrospection.fields) {
|
|
243
|
-
throw new Error('Introspection result missing fields: ' +
|
|
249
|
+
throw new Error('Introspection result missing fields: ' + (0, _inspect.default)(typeIntrospection));
|
|
244
250
|
}
|
|
245
251
|
|
|
246
252
|
return (0, _keyValMap.default)(typeIntrospection.fields, function (fieldIntrospection) {
|
|
247
253
|
return fieldIntrospection.name;
|
|
248
254
|
}, function (fieldIntrospection) {
|
|
249
255
|
if (!fieldIntrospection.args) {
|
|
250
|
-
throw new Error('Introspection result missing field args: ' +
|
|
256
|
+
throw new Error('Introspection result missing field args: ' + (0, _inspect.default)(fieldIntrospection));
|
|
251
257
|
}
|
|
252
258
|
|
|
253
259
|
return {
|
|
@@ -277,7 +283,11 @@ function buildClientSchema(introspection, options) {
|
|
|
277
283
|
|
|
278
284
|
function buildDirective(directiveIntrospection) {
|
|
279
285
|
if (!directiveIntrospection.args) {
|
|
280
|
-
throw new Error('Introspection result missing directive args: ' +
|
|
286
|
+
throw new Error('Introspection result missing directive args: ' + (0, _inspect.default)(directiveIntrospection));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!directiveIntrospection.locations) {
|
|
290
|
+
throw new Error('Introspection result missing directive locations: ' + (0, _inspect.default)(directiveIntrospection));
|
|
281
291
|
}
|
|
282
292
|
|
|
283
293
|
return new _directives.GraphQLDirective({
|