graphql 14.0.2 → 14.2.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/LICENSE +1 -1
- package/README.md +5 -5
- package/codecov.yml +14 -0
- package/error/GraphQLError.js +2 -2
- package/error/GraphQLError.js.flow +4 -4
- package/error/GraphQLError.mjs +2 -2
- package/error/formatError.js +2 -2
- package/error/formatError.js.flow +1 -1
- package/error/formatError.mjs +2 -2
- package/error/index.js.flow +1 -1
- package/error/index.mjs +2 -2
- package/error/locatedError.js +2 -2
- package/error/locatedError.js.flow +1 -1
- package/error/locatedError.mjs +2 -2
- package/error/printError.js +2 -2
- package/error/printError.js.flow +1 -1
- package/error/printError.mjs +2 -2
- package/error/syntaxError.js +2 -2
- package/error/syntaxError.js.flow +1 -1
- package/error/syntaxError.mjs +2 -2
- package/execution/execute.js +20 -11
- package/execution/execute.js.flow +41 -27
- package/execution/execute.mjs +19 -13
- package/execution/index.js +6 -0
- package/execution/index.js.flow +7 -2
- package/execution/index.mjs +3 -3
- package/execution/values.js +10 -10
- package/execution/values.js.flow +8 -8
- package/execution/values.mjs +9 -9
- package/graphql.js +8 -8
- package/graphql.js.flow +18 -4
- package/graphql.mjs +8 -8
- package/index.js +18 -0
- package/index.js.flow +4 -1
- package/index.mjs +4 -4
- package/jsutils/ObjMap.js.flow +1 -1
- package/jsutils/{MaybePromise.js → PromiseOrValue.js} +0 -0
- package/jsutils/{MaybePromise.js.flow → PromiseOrValue.js.flow} +2 -2
- package/jsutils/{MaybePromise.mjs → PromiseOrValue.mjs} +0 -0
- package/jsutils/dedent.js +2 -2
- package/jsutils/dedent.js.flow +1 -1
- package/jsutils/dedent.mjs +2 -2
- package/jsutils/defineToJSON.js +18 -7
- package/jsutils/defineToJSON.js.flow +15 -6
- package/jsutils/defineToJSON.mjs +15 -7
- package/jsutils/defineToStringTag.js +6 -6
- package/jsutils/defineToStringTag.js.flow +4 -4
- package/jsutils/defineToStringTag.mjs +5 -5
- package/jsutils/inspect.js +109 -23
- package/jsutils/inspect.js.flow +112 -14
- package/jsutils/inspect.mjs +108 -17
- package/jsutils/instanceOf.js +2 -2
- package/jsutils/instanceOf.js.flow +1 -1
- package/jsutils/instanceOf.mjs +2 -2
- package/jsutils/invariant.js +2 -2
- package/jsutils/invariant.js.flow +1 -1
- package/jsutils/invariant.mjs +2 -2
- package/jsutils/isInvalid.js +2 -2
- package/jsutils/isInvalid.js.flow +1 -1
- package/jsutils/isInvalid.mjs +2 -2
- package/jsutils/isNullish.js +2 -2
- package/jsutils/isNullish.js.flow +1 -1
- package/jsutils/isNullish.mjs +2 -2
- package/jsutils/isPromise.js +2 -2
- package/jsutils/isPromise.js.flow +1 -1
- package/jsutils/isPromise.mjs +2 -2
- package/jsutils/keyMap.js +2 -2
- package/jsutils/keyMap.js.flow +1 -1
- package/jsutils/keyMap.mjs +2 -2
- package/jsutils/keyValMap.js +2 -2
- package/jsutils/keyValMap.js.flow +1 -1
- package/jsutils/keyValMap.mjs +2 -2
- package/jsutils/mapValue.js +54 -0
- package/jsutils/mapValue.js.flow +27 -0
- package/jsutils/mapValue.mjs +44 -0
- package/jsutils/memoize3.js +2 -2
- package/jsutils/memoize3.js.flow +1 -1
- package/jsutils/memoize3.mjs +2 -2
- package/jsutils/nodejsCustomInspectSymbol.js +18 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
- package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
- package/jsutils/orList.js +18 -5
- package/jsutils/orList.js.flow +14 -8
- package/jsutils/orList.mjs +15 -5
- package/jsutils/promiseForObject.js +2 -2
- package/jsutils/promiseForObject.js.flow +1 -1
- package/jsutils/promiseForObject.mjs +2 -2
- package/jsutils/promiseReduce.js +2 -2
- package/jsutils/promiseReduce.js.flow +5 -5
- package/jsutils/promiseReduce.mjs +2 -2
- package/jsutils/quotedOrList.js +2 -2
- package/jsutils/quotedOrList.js.flow +1 -1
- package/jsutils/quotedOrList.mjs +2 -2
- package/jsutils/suggestionList.js +2 -2
- package/jsutils/suggestionList.js.flow +1 -1
- package/jsutils/suggestionList.mjs +2 -2
- package/language/ast.js.flow +1 -1
- package/language/{blockStringValue.mjs → blockString.js} +39 -3
- package/language/{blockStringValue.js.flow → blockString.js.flow} +31 -2
- package/language/{blockStringValue.js → blockString.mjs} +31 -10
- package/language/directiveLocation.js +2 -2
- package/language/directiveLocation.js.flow +1 -1
- package/language/directiveLocation.mjs +2 -2
- package/language/index.js.flow +1 -1
- package/language/index.mjs +2 -2
- package/language/kinds.js +2 -2
- package/language/kinds.js.flow +1 -1
- package/language/kinds.mjs +2 -2
- package/language/lexer.js +60 -46
- package/language/lexer.js.flow +71 -69
- package/language/lexer.mjs +58 -45
- package/language/location.js +2 -2
- package/language/location.js.flow +1 -1
- package/language/location.mjs +2 -2
- package/language/parser.js +84 -83
- package/language/parser.js.flow +85 -94
- package/language/parser.mjs +83 -83
- package/language/predicates.js +2 -2
- package/language/predicates.js.flow +1 -1
- package/language/predicates.mjs +2 -2
- package/language/printer.js +15 -17
- package/language/printer.js.flow +21 -20
- package/language/printer.mjs +14 -17
- package/language/source.js +8 -7
- package/language/source.js.flow +1 -1
- package/language/source.mjs +2 -10
- package/language/visitor.js +7 -6
- package/language/visitor.js.flow +3 -5
- package/language/visitor.mjs +7 -6
- package/package.json +5 -2
- package/polyfills/find.js +31 -0
- package/polyfills/find.js.flow +29 -0
- package/polyfills/find.mjs +23 -0
- package/polyfills/flatMap.js +38 -0
- package/polyfills/flatMap.js.flow +34 -0
- package/polyfills/flatMap.mjs +30 -0
- package/{jsutils → polyfills}/isFinite.js +2 -2
- package/{jsutils → polyfills}/isFinite.js.flow +1 -1
- package/{jsutils → polyfills}/isFinite.mjs +2 -2
- package/{jsutils → polyfills}/isInteger.js +2 -2
- package/{jsutils → polyfills}/isInteger.js.flow +1 -1
- package/{jsutils → polyfills}/isInteger.mjs +2 -2
- package/polyfills/objectEntries.js +26 -0
- package/polyfills/objectEntries.js.flow +19 -0
- package/polyfills/objectEntries.mjs +18 -0
- package/{jsutils → polyfills}/objectValues.js +2 -2
- package/{jsutils → polyfills}/objectValues.js.flow +2 -2
- package/{jsutils → polyfills}/objectValues.mjs +2 -2
- package/subscription/asyncIteratorReject.js.flow +1 -1
- package/subscription/asyncIteratorReject.mjs +2 -2
- package/subscription/index.js.flow +1 -1
- package/subscription/index.mjs +2 -2
- package/subscription/mapAsyncIterator.js.flow +5 -5
- package/subscription/mapAsyncIterator.mjs +2 -2
- package/subscription/subscribe.js +2 -2
- package/subscription/subscribe.js.flow +1 -1
- package/subscription/subscribe.mjs +2 -2
- package/type/definition.js +161 -138
- package/type/definition.js.flow +193 -57
- package/type/definition.mjs +158 -140
- package/type/directives.js +35 -29
- package/type/directives.js.flow +39 -21
- package/type/directives.mjs +34 -31
- package/type/index.js +12 -0
- package/type/index.js.flow +5 -1
- package/type/index.mjs +6 -4
- package/type/introspection.js +11 -7
- package/type/introspection.js.flow +11 -8
- package/type/introspection.mjs +11 -7
- package/type/scalars.js +45 -34
- package/type/scalars.js.flow +41 -27
- package/type/scalars.mjs +45 -27
- package/type/schema.js +134 -88
- package/type/schema.js.flow +77 -11
- package/type/schema.mjs +132 -88
- package/type/validate.js +152 -187
- package/type/validate.js.flow +12 -61
- package/type/validate.mjs +143 -188
- package/utilities/TypeInfo.js +10 -23
- package/utilities/TypeInfo.js.flow +2 -2
- package/utilities/TypeInfo.mjs +3 -25
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +1 -1
- package/utilities/assertValidName.mjs +2 -2
- package/utilities/astFromValue.js +7 -6
- package/utilities/astFromValue.js.flow +7 -6
- package/utilities/astFromValue.mjs +9 -8
- package/utilities/buildASTSchema.js +213 -197
- package/utilities/buildASTSchema.js.flow +163 -173
- package/utilities/buildASTSchema.mjs +203 -198
- package/utilities/buildClientSchema.js +39 -47
- package/utilities/buildClientSchema.js.flow +49 -58
- package/utilities/buildClientSchema.mjs +38 -46
- package/utilities/coerceValue.js +41 -21
- package/utilities/coerceValue.js.flow +44 -49
- package/utilities/coerceValue.mjs +42 -23
- package/utilities/concatAST.js +9 -13
- package/utilities/concatAST.js.flow +3 -9
- package/utilities/concatAST.mjs +6 -13
- package/utilities/extendSchema.js +256 -630
- package/utilities/extendSchema.js.flow +190 -426
- package/utilities/extendSchema.mjs +256 -631
- package/utilities/findBreakingChanges.js +8 -6
- package/utilities/findBreakingChanges.js.flow +4 -3
- package/utilities/findBreakingChanges.mjs +7 -6
- package/utilities/findDeprecatedUsages.js +4 -4
- package/utilities/findDeprecatedUsages.js.flow +3 -3
- package/utilities/findDeprecatedUsages.mjs +4 -4
- package/utilities/getOperationAST.js +2 -2
- package/utilities/getOperationAST.js.flow +1 -1
- package/utilities/getOperationAST.mjs +2 -2
- package/utilities/getOperationRootType.js +6 -6
- package/utilities/getOperationRootType.js.flow +9 -7
- package/utilities/getOperationRootType.mjs +6 -6
- package/utilities/index.js.flow +1 -1
- package/utilities/index.mjs +2 -2
- package/utilities/introspectionFromSchema.js +2 -2
- package/utilities/introspectionFromSchema.js.flow +1 -1
- package/utilities/introspectionFromSchema.mjs +2 -2
- package/utilities/introspectionQuery.js +2 -2
- package/utilities/introspectionQuery.js.flow +1 -1
- package/utilities/introspectionQuery.mjs +2 -2
- package/utilities/isValidJSValue.js +4 -2
- package/utilities/isValidJSValue.js.flow +2 -1
- package/utilities/isValidJSValue.mjs +4 -2
- package/utilities/isValidLiteralValue.js +2 -2
- package/utilities/isValidLiteralValue.js.flow +1 -1
- package/utilities/isValidLiteralValue.mjs +2 -2
- package/utilities/lexicographicSortSchema.js +86 -124
- package/utilities/lexicographicSortSchema.js.flow +68 -96
- package/utilities/lexicographicSortSchema.mjs +86 -124
- package/utilities/schemaPrinter.js +47 -73
- package/utilities/schemaPrinter.js.flow +62 -111
- package/utilities/schemaPrinter.mjs +46 -73
- package/utilities/separateOperations.js +11 -10
- package/utilities/separateOperations.js.flow +1 -1
- package/utilities/separateOperations.mjs +11 -10
- package/utilities/typeComparators.js +2 -2
- package/utilities/typeComparators.js.flow +1 -1
- package/utilities/typeComparators.mjs +2 -2
- package/utilities/typeFromAST.js +9 -4
- package/utilities/typeFromAST.js.flow +5 -2
- package/utilities/typeFromAST.mjs +6 -4
- package/utilities/valueFromAST.js +9 -6
- package/utilities/valueFromAST.js.flow +5 -3
- package/utilities/valueFromAST.mjs +7 -5
- package/utilities/valueFromASTUntyped.js +7 -4
- package/utilities/valueFromASTUntyped.js.flow +5 -2
- package/utilities/valueFromASTUntyped.mjs +6 -4
- package/validation/ValidationContext.js +57 -82
- package/validation/ValidationContext.js.flow +53 -50
- package/validation/ValidationContext.mjs +53 -78
- package/validation/index.js.flow +1 -1
- package/validation/index.mjs +2 -2
- package/validation/rules/ExecutableDefinitions.js +3 -3
- package/validation/rules/ExecutableDefinitions.js.flow +3 -3
- package/validation/rules/ExecutableDefinitions.mjs +3 -3
- package/validation/rules/FieldsOnCorrectType.js +3 -3
- package/validation/rules/FieldsOnCorrectType.js.flow +2 -2
- package/validation/rules/FieldsOnCorrectType.mjs +3 -3
- package/validation/rules/FragmentsOnCompositeTypes.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +3 -3
- package/validation/rules/FragmentsOnCompositeTypes.mjs +4 -4
- package/validation/rules/KnownArgumentNames.js.flow +1 -1
- package/validation/rules/KnownArgumentNames.mjs +2 -2
- package/validation/rules/KnownDirectives.js +4 -4
- package/validation/rules/KnownDirectives.js.flow +5 -4
- package/validation/rules/KnownDirectives.mjs +4 -4
- package/validation/rules/KnownFragmentNames.js +3 -3
- package/validation/rules/KnownFragmentNames.js.flow +2 -2
- package/validation/rules/KnownFragmentNames.mjs +3 -3
- package/validation/rules/KnownTypeNames.js +60 -22
- package/validation/rules/KnownTypeNames.js.flow +55 -21
- package/validation/rules/KnownTypeNames.mjs +57 -22
- package/validation/rules/LoneAnonymousOperation.js +3 -3
- package/validation/rules/LoneAnonymousOperation.js.flow +2 -2
- package/validation/rules/LoneAnonymousOperation.mjs +3 -3
- package/validation/rules/LoneSchemaDefinition.js +2 -2
- package/validation/rules/LoneSchemaDefinition.js.flow +1 -1
- package/validation/rules/LoneSchemaDefinition.mjs +2 -2
- package/validation/rules/NoFragmentCycles.js +2 -2
- package/validation/rules/NoFragmentCycles.js.flow +3 -3
- package/validation/rules/NoFragmentCycles.mjs +2 -2
- package/validation/rules/NoUndefinedVariables.js +2 -2
- package/validation/rules/NoUndefinedVariables.js.flow +1 -1
- package/validation/rules/NoUndefinedVariables.mjs +2 -2
- package/validation/rules/NoUnusedFragments.js +10 -7
- package/validation/rules/NoUnusedFragments.js.flow +4 -4
- package/validation/rules/NoUnusedFragments.mjs +10 -7
- package/validation/rules/NoUnusedVariables.js +7 -5
- package/validation/rules/NoUnusedVariables.js.flow +4 -3
- package/validation/rules/NoUnusedVariables.mjs +7 -5
- package/validation/rules/OverlappingFieldsCanBeMerged.js +58 -33
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +4 -4
- package/validation/rules/OverlappingFieldsCanBeMerged.mjs +50 -34
- package/validation/rules/PossibleFragmentSpreads.js +4 -4
- package/validation/rules/PossibleFragmentSpreads.js.flow +3 -3
- package/validation/rules/PossibleFragmentSpreads.mjs +4 -4
- 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.js +3 -3
- package/validation/rules/ProvidedRequiredArguments.js.flow +4 -4
- package/validation/rules/ProvidedRequiredArguments.mjs +5 -5
- package/validation/rules/ScalarLeafs.js +4 -4
- package/validation/rules/ScalarLeafs.js.flow +3 -3
- package/validation/rules/ScalarLeafs.mjs +4 -4
- package/validation/rules/SingleFieldSubscriptions.js +2 -2
- package/validation/rules/SingleFieldSubscriptions.js.flow +1 -1
- package/validation/rules/SingleFieldSubscriptions.mjs +2 -2
- package/validation/rules/UniqueArgumentNames.js +2 -2
- package/validation/rules/UniqueArgumentNames.js.flow +1 -1
- package/validation/rules/UniqueArgumentNames.mjs +2 -2
- 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 +2 -2
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.mjs +2 -2
- package/validation/rules/UniqueEnumValueNames.js +90 -0
- package/validation/rules/UniqueEnumValueNames.js.flow +85 -0
- package/validation/rules/UniqueEnumValueNames.mjs +77 -0
- package/validation/rules/UniqueFieldDefinitionNames.js +101 -0
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +99 -0
- package/validation/rules/UniqueFieldDefinitionNames.mjs +88 -0
- package/validation/rules/UniqueFragmentNames.js +2 -2
- package/validation/rules/UniqueFragmentNames.js.flow +1 -1
- package/validation/rules/UniqueFragmentNames.mjs +2 -2
- package/validation/rules/UniqueInputFieldNames.js +2 -4
- package/validation/rules/UniqueInputFieldNames.js.flow +1 -2
- package/validation/rules/UniqueInputFieldNames.mjs +2 -4
- package/validation/rules/UniqueOperationNames.js +2 -2
- package/validation/rules/UniqueOperationNames.js.flow +1 -1
- package/validation/rules/UniqueOperationNames.mjs +2 -2
- 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 +2 -2
- package/validation/rules/UniqueVariableNames.js.flow +1 -1
- package/validation/rules/UniqueVariableNames.mjs +2 -2
- package/validation/rules/ValuesOfCorrectType.js +30 -14
- package/validation/rules/ValuesOfCorrectType.js.flow +5 -6
- package/validation/rules/ValuesOfCorrectType.mjs +29 -14
- package/validation/rules/VariablesAreInputTypes.js +3 -3
- package/validation/rules/VariablesAreInputTypes.js.flow +2 -2
- package/validation/rules/VariablesAreInputTypes.mjs +3 -3
- package/validation/rules/VariablesInAllowedPosition.js +5 -5
- package/validation/rules/VariablesInAllowedPosition.js.flow +1 -1
- package/validation/rules/VariablesInAllowedPosition.mjs +5 -5
- package/validation/specifiedRules.js +15 -3
- package/validation/specifiedRules.js.flow +14 -1
- package/validation/specifiedRules.mjs +9 -3
- package/validation/validate.js +2 -2
- package/validation/validate.js.flow +1 -1
- package/validation/validate.mjs +2 -2
- package/jsutils/find.js +0 -22
- package/jsutils/find.js.flow +0 -19
- package/jsutils/find.mjs +0 -15
package/type/validate.js
CHANGED
|
@@ -6,6 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.validateSchema = validateSchema;
|
|
7
7
|
exports.assertValidSchema = assertValidSchema;
|
|
8
8
|
|
|
9
|
+
var _find = _interopRequireDefault(require("../polyfills/find"));
|
|
10
|
+
|
|
11
|
+
var _flatMap = _interopRequireDefault(require("../polyfills/flatMap"));
|
|
12
|
+
|
|
13
|
+
var _objectValues = _interopRequireDefault(require("../polyfills/objectValues"));
|
|
14
|
+
|
|
15
|
+
var _objectEntries = _interopRequireDefault(require("../polyfills/objectEntries"));
|
|
16
|
+
|
|
9
17
|
var _definition = require("./definition");
|
|
10
18
|
|
|
11
19
|
var _directives = require("./directives");
|
|
@@ -16,12 +24,6 @@ var _schema = require("./schema");
|
|
|
16
24
|
|
|
17
25
|
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
|
18
26
|
|
|
19
|
-
var _find = _interopRequireDefault(require("../jsutils/find"));
|
|
20
|
-
|
|
21
|
-
var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
|
|
22
|
-
|
|
23
|
-
var _objectValues = _interopRequireDefault(require("../jsutils/objectValues"));
|
|
24
|
-
|
|
25
27
|
var _GraphQLError = require("../error/GraphQLError");
|
|
26
28
|
|
|
27
29
|
var _assertValidName = require("../utilities/assertValidName");
|
|
@@ -30,7 +32,14 @@ var _typeComparators = require("../utilities/typeComparators");
|
|
|
30
32
|
|
|
31
33
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
37
|
+
*
|
|
38
|
+
* This source code is licensed under the MIT license found in the
|
|
39
|
+
* LICENSE file in the root directory of this source tree.
|
|
40
|
+
*
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
34
43
|
|
|
35
44
|
/**
|
|
36
45
|
* Implements the "Type Validation" sub-sections of the specification's
|
|
@@ -41,7 +50,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
41
50
|
*/
|
|
42
51
|
function validateSchema(schema) {
|
|
43
52
|
// First check to ensure the provided value is in fact a GraphQLSchema.
|
|
44
|
-
|
|
53
|
+
(0, _schema.assertSchema)(schema); // If this Schema has already been validated, return the previous results.
|
|
45
54
|
|
|
46
55
|
if (schema.__validationErrors) {
|
|
47
56
|
return schema.__validationErrors;
|
|
@@ -78,10 +87,6 @@ var SchemaValidationContext =
|
|
|
78
87
|
/*#__PURE__*/
|
|
79
88
|
function () {
|
|
80
89
|
function SchemaValidationContext(schema) {
|
|
81
|
-
_defineProperty(this, "_errors", void 0);
|
|
82
|
-
|
|
83
|
-
_defineProperty(this, "schema", void 0);
|
|
84
|
-
|
|
85
90
|
this._errors = [];
|
|
86
91
|
this.schema = schema;
|
|
87
92
|
}
|
|
@@ -89,7 +94,7 @@ function () {
|
|
|
89
94
|
var _proto = SchemaValidationContext.prototype;
|
|
90
95
|
|
|
91
96
|
_proto.reportError = function reportError(message, nodes) {
|
|
92
|
-
var _nodes =
|
|
97
|
+
var _nodes = Array.isArray(nodes) ? nodes.filter(Boolean) : nodes;
|
|
93
98
|
|
|
94
99
|
this.addError(new _GraphQLError.GraphQLError(message, _nodes));
|
|
95
100
|
};
|
|
@@ -321,15 +326,7 @@ function validateFields(context, type) {
|
|
|
321
326
|
for (var _iterator5 = fields[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
322
327
|
var field = _step5.value;
|
|
323
328
|
// Ensure they are named correctly.
|
|
324
|
-
validateName(context, field); // Ensure
|
|
325
|
-
|
|
326
|
-
var fieldNodes = getAllFieldNodes(type, field.name);
|
|
327
|
-
|
|
328
|
-
if (fieldNodes.length > 1) {
|
|
329
|
-
context.reportError("Field ".concat(type.name, ".").concat(field.name, " can only be defined once."), fieldNodes);
|
|
330
|
-
continue;
|
|
331
|
-
} // Ensure the type is an output type
|
|
332
|
-
|
|
329
|
+
validateName(context, field); // Ensure the type is an output type
|
|
333
330
|
|
|
334
331
|
if (!(0, _definition.isOutputType)(field.type)) {
|
|
335
332
|
context.reportError("The type of ".concat(type.name, ".").concat(field.name, " must be Output Type ") + "but got: ".concat((0, _inspect.default)(field.type), "."), getFieldTypeNode(type, field.name));
|
|
@@ -432,104 +429,122 @@ function validateObjectImplementsInterface(context, object, iface) {
|
|
|
432
429
|
var objectFieldMap = object.getFields();
|
|
433
430
|
var ifaceFieldMap = iface.getFields(); // Assert each interface field is implemented.
|
|
434
431
|
|
|
435
|
-
var
|
|
432
|
+
var _iteratorNormalCompletion8 = true;
|
|
433
|
+
var _didIteratorError8 = false;
|
|
434
|
+
var _iteratorError8 = undefined;
|
|
436
435
|
|
|
437
|
-
|
|
438
|
-
var
|
|
439
|
-
|
|
440
|
-
|
|
436
|
+
try {
|
|
437
|
+
for (var _iterator8 = (0, _objectEntries.default)(ifaceFieldMap)[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
|
438
|
+
var _ref2 = _step8.value;
|
|
439
|
+
var fieldName = _ref2[0];
|
|
440
|
+
var ifaceField = _ref2[1];
|
|
441
|
+
var objectField = objectFieldMap[fieldName]; // Assert interface field exists on object.
|
|
442
|
+
|
|
443
|
+
if (!objectField) {
|
|
444
|
+
context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expected but ") + "".concat(object.name, " does not provide it."), [getFieldNode(iface, fieldName)].concat(getAllNodes(object)));
|
|
445
|
+
continue;
|
|
446
|
+
} // Assert interface field type is satisfied by object field type, by being
|
|
447
|
+
// a valid subtype. (covariant)
|
|
441
448
|
|
|
442
|
-
if (!objectField) {
|
|
443
|
-
context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expected but ") + "".concat(object.name, " does not provide it."), [getFieldNode(iface, fieldName)].concat(getAllNodes(object)));
|
|
444
|
-
continue;
|
|
445
|
-
} // Assert interface field type is satisfied by object field type, by being
|
|
446
|
-
// a valid subtype. (covariant)
|
|
447
449
|
|
|
450
|
+
if (!(0, _typeComparators.isTypeSubTypeOf)(context.schema, objectField.type, ifaceField.type)) {
|
|
451
|
+
context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expects type ") + "".concat((0, _inspect.default)(ifaceField.type), " but ").concat(object.name, ".").concat(fieldName, " ") + "is type ".concat((0, _inspect.default)(objectField.type), "."), [getFieldTypeNode(iface, fieldName), getFieldTypeNode(object, fieldName)]);
|
|
452
|
+
} // Assert each interface field arg is implemented.
|
|
448
453
|
|
|
449
|
-
if (!(0, _typeComparators.isTypeSubTypeOf)(context.schema, objectField.type, ifaceField.type)) {
|
|
450
|
-
context.reportError("Interface field ".concat(iface.name, ".").concat(fieldName, " expects type ") + "".concat((0, _inspect.default)(ifaceField.type), " but ").concat(object.name, ".").concat(fieldName, " ") + "is type ".concat((0, _inspect.default)(objectField.type), "."), [getFieldTypeNode(iface, fieldName), getFieldTypeNode(object, fieldName)]);
|
|
451
|
-
} // Assert each interface field arg is implemented.
|
|
452
454
|
|
|
455
|
+
var _iteratorNormalCompletion9 = true;
|
|
456
|
+
var _didIteratorError9 = false;
|
|
457
|
+
var _iteratorError9 = undefined;
|
|
453
458
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
459
|
+
try {
|
|
460
|
+
var _loop = function _loop() {
|
|
461
|
+
var ifaceArg = _step9.value;
|
|
462
|
+
var argName = ifaceArg.name;
|
|
463
|
+
var objectArg = (0, _find.default)(objectField.args, function (arg) {
|
|
464
|
+
return arg.name === argName;
|
|
465
|
+
}); // Assert interface field arg exists on object field.
|
|
457
466
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}); // Assert interface field arg exists on object field.
|
|
467
|
+
if (!objectArg) {
|
|
468
|
+
context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expected but ".concat(object.name, ".").concat(fieldName, " does not provide it."), [getFieldArgNode(iface, fieldName, argName), getFieldNode(object, fieldName)]);
|
|
469
|
+
return "continue";
|
|
470
|
+
} // Assert interface field arg type matches object field arg type.
|
|
471
|
+
// (invariant)
|
|
472
|
+
// TODO: change to contravariant?
|
|
465
473
|
|
|
466
|
-
if (!objectArg) {
|
|
467
|
-
context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expected but ".concat(object.name, ".").concat(fieldName, " does not provide it."), [getFieldArgNode(iface, fieldName, argName), getFieldNode(object, fieldName)]);
|
|
468
|
-
return "continue";
|
|
469
|
-
} // Assert interface field arg type matches object field arg type.
|
|
470
|
-
// (invariant)
|
|
471
|
-
// TODO: change to contravariant?
|
|
472
474
|
|
|
475
|
+
if (!(0, _typeComparators.isEqualType)(ifaceArg.type, objectArg.type)) {
|
|
476
|
+
context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expects type ".concat((0, _inspect.default)(ifaceArg.type), " but ") + "".concat(object.name, ".").concat(fieldName, "(").concat(argName, ":) is type ") + "".concat((0, _inspect.default)(objectArg.type), "."), [getFieldArgTypeNode(iface, fieldName, argName), getFieldArgTypeNode(object, fieldName, argName)]);
|
|
477
|
+
} // TODO: validate default values?
|
|
473
478
|
|
|
474
|
-
|
|
475
|
-
context.reportError("Interface field argument ".concat(iface.name, ".").concat(fieldName, "(").concat(argName, ":) ") + "expects type ".concat((0, _inspect.default)(ifaceArg.type), " but ") + "".concat(object.name, ".").concat(fieldName, "(").concat(argName, ":) is type ") + "".concat((0, _inspect.default)(objectArg.type), "."), [getFieldArgTypeNode(iface, fieldName, argName), getFieldArgTypeNode(object, fieldName, argName)]);
|
|
476
|
-
} // TODO: validate default values?
|
|
479
|
+
};
|
|
477
480
|
|
|
478
|
-
|
|
481
|
+
for (var _iterator9 = ifaceField.args[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
|
|
482
|
+
var _ret = _loop();
|
|
479
483
|
|
|
480
|
-
|
|
481
|
-
|
|
484
|
+
if (_ret === "continue") continue;
|
|
485
|
+
} // Assert additional arguments must not be required.
|
|
486
|
+
|
|
487
|
+
} catch (err) {
|
|
488
|
+
_didIteratorError9 = true;
|
|
489
|
+
_iteratorError9 = err;
|
|
490
|
+
} finally {
|
|
491
|
+
try {
|
|
492
|
+
if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
|
|
493
|
+
_iterator9.return();
|
|
494
|
+
}
|
|
495
|
+
} finally {
|
|
496
|
+
if (_didIteratorError9) {
|
|
497
|
+
throw _iteratorError9;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
482
501
|
|
|
483
|
-
|
|
484
|
-
|
|
502
|
+
var _iteratorNormalCompletion10 = true;
|
|
503
|
+
var _didIteratorError10 = false;
|
|
504
|
+
var _iteratorError10 = undefined;
|
|
485
505
|
|
|
486
|
-
} catch (err) {
|
|
487
|
-
_didIteratorError8 = true;
|
|
488
|
-
_iteratorError8 = err;
|
|
489
|
-
} finally {
|
|
490
506
|
try {
|
|
491
|
-
|
|
492
|
-
|
|
507
|
+
var _loop2 = function _loop2() {
|
|
508
|
+
var objectArg = _step10.value;
|
|
509
|
+
var argName = objectArg.name;
|
|
510
|
+
var ifaceArg = (0, _find.default)(ifaceField.args, function (arg) {
|
|
511
|
+
return arg.name === argName;
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
if (!ifaceArg && (0, _definition.isRequiredArgument)(objectArg)) {
|
|
515
|
+
context.reportError("Object field ".concat(object.name, ".").concat(fieldName, " includes required ") + "argument ".concat(argName, " that is missing from the Interface field ") + "".concat(iface.name, ".").concat(fieldName, "."), [getFieldArgNode(object, fieldName, argName), getFieldNode(iface, fieldName)]);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
for (var _iterator10 = objectField.args[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
|
|
520
|
+
_loop2();
|
|
493
521
|
}
|
|
522
|
+
} catch (err) {
|
|
523
|
+
_didIteratorError10 = true;
|
|
524
|
+
_iteratorError10 = err;
|
|
494
525
|
} finally {
|
|
495
|
-
|
|
496
|
-
|
|
526
|
+
try {
|
|
527
|
+
if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
|
|
528
|
+
_iterator10.return();
|
|
529
|
+
}
|
|
530
|
+
} finally {
|
|
531
|
+
if (_didIteratorError10) {
|
|
532
|
+
throw _iteratorError10;
|
|
533
|
+
}
|
|
497
534
|
}
|
|
498
535
|
}
|
|
499
536
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
537
|
+
} catch (err) {
|
|
538
|
+
_didIteratorError8 = true;
|
|
539
|
+
_iteratorError8 = err;
|
|
540
|
+
} finally {
|
|
505
541
|
try {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
var argName = objectArg.name;
|
|
509
|
-
var ifaceArg = (0, _find.default)(ifaceField.args, function (arg) {
|
|
510
|
-
return arg.name === argName;
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
if (!ifaceArg && (0, _definition.isRequiredArgument)(objectArg)) {
|
|
514
|
-
context.reportError("Object field ".concat(object.name, ".").concat(fieldName, " includes required ") + "argument ".concat(argName, " that is missing from the Interface field ") + "".concat(iface.name, ".").concat(fieldName, "."), [getFieldArgNode(object, fieldName, argName), getFieldNode(iface, fieldName)]);
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
for (var _iterator9 = objectField.args[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
|
|
519
|
-
_loop2();
|
|
542
|
+
if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
|
|
543
|
+
_iterator8.return();
|
|
520
544
|
}
|
|
521
|
-
} catch (err) {
|
|
522
|
-
_didIteratorError9 = true;
|
|
523
|
-
_iteratorError9 = err;
|
|
524
545
|
} finally {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
_iterator9.return();
|
|
528
|
-
}
|
|
529
|
-
} finally {
|
|
530
|
-
if (_didIteratorError9) {
|
|
531
|
-
throw _iteratorError9;
|
|
532
|
-
}
|
|
546
|
+
if (_didIteratorError8) {
|
|
547
|
+
throw _iteratorError8;
|
|
533
548
|
}
|
|
534
549
|
}
|
|
535
550
|
}
|
|
@@ -543,13 +558,13 @@ function validateUnionMembers(context, union) {
|
|
|
543
558
|
}
|
|
544
559
|
|
|
545
560
|
var includedTypeNames = Object.create(null);
|
|
546
|
-
var
|
|
547
|
-
var
|
|
548
|
-
var
|
|
561
|
+
var _iteratorNormalCompletion11 = true;
|
|
562
|
+
var _didIteratorError11 = false;
|
|
563
|
+
var _iteratorError11 = undefined;
|
|
549
564
|
|
|
550
565
|
try {
|
|
551
|
-
for (var
|
|
552
|
-
var memberType =
|
|
566
|
+
for (var _iterator11 = memberTypes[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
|
|
567
|
+
var memberType = _step11.value;
|
|
553
568
|
|
|
554
569
|
if (includedTypeNames[memberType.name]) {
|
|
555
570
|
context.reportError("Union type ".concat(union.name, " can only include type ") + "".concat(memberType.name, " once."), getUnionMemberTypeNodes(union, memberType.name));
|
|
@@ -563,16 +578,16 @@ function validateUnionMembers(context, union) {
|
|
|
563
578
|
}
|
|
564
579
|
}
|
|
565
580
|
} catch (err) {
|
|
566
|
-
|
|
567
|
-
|
|
581
|
+
_didIteratorError11 = true;
|
|
582
|
+
_iteratorError11 = err;
|
|
568
583
|
} finally {
|
|
569
584
|
try {
|
|
570
|
-
if (!
|
|
571
|
-
|
|
585
|
+
if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
|
|
586
|
+
_iterator11.return();
|
|
572
587
|
}
|
|
573
588
|
} finally {
|
|
574
|
-
if (
|
|
575
|
-
throw
|
|
589
|
+
if (_didIteratorError11) {
|
|
590
|
+
throw _iteratorError11;
|
|
576
591
|
}
|
|
577
592
|
}
|
|
578
593
|
}
|
|
@@ -585,21 +600,14 @@ function validateEnumValues(context, enumType) {
|
|
|
585
600
|
context.reportError("Enum type ".concat(enumType.name, " must define one or more values."), getAllNodes(enumType));
|
|
586
601
|
}
|
|
587
602
|
|
|
588
|
-
var
|
|
589
|
-
var
|
|
590
|
-
var
|
|
603
|
+
var _iteratorNormalCompletion12 = true;
|
|
604
|
+
var _didIteratorError12 = false;
|
|
605
|
+
var _iteratorError12 = undefined;
|
|
591
606
|
|
|
592
607
|
try {
|
|
593
|
-
for (var
|
|
594
|
-
var enumValue =
|
|
595
|
-
var valueName = enumValue.name; // Ensure
|
|
596
|
-
|
|
597
|
-
var allNodes = getEnumValueNodes(enumType, valueName);
|
|
598
|
-
|
|
599
|
-
if (allNodes && allNodes.length > 1) {
|
|
600
|
-
context.reportError("Enum type ".concat(enumType.name, " can include value ").concat(valueName, " only once."), allNodes);
|
|
601
|
-
} // Ensure valid name.
|
|
602
|
-
|
|
608
|
+
for (var _iterator12 = enumValues[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
|
|
609
|
+
var enumValue = _step12.value;
|
|
610
|
+
var valueName = enumValue.name; // Ensure valid name.
|
|
603
611
|
|
|
604
612
|
validateName(context, enumValue);
|
|
605
613
|
|
|
@@ -608,16 +616,16 @@ function validateEnumValues(context, enumType) {
|
|
|
608
616
|
}
|
|
609
617
|
}
|
|
610
618
|
} catch (err) {
|
|
611
|
-
|
|
612
|
-
|
|
619
|
+
_didIteratorError12 = true;
|
|
620
|
+
_iteratorError12 = err;
|
|
613
621
|
} finally {
|
|
614
622
|
try {
|
|
615
|
-
if (!
|
|
616
|
-
|
|
623
|
+
if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
|
|
624
|
+
_iterator12.return();
|
|
617
625
|
}
|
|
618
626
|
} finally {
|
|
619
|
-
if (
|
|
620
|
-
throw
|
|
627
|
+
if (_didIteratorError12) {
|
|
628
|
+
throw _iteratorError12;
|
|
621
629
|
}
|
|
622
630
|
}
|
|
623
631
|
}
|
|
@@ -631,32 +639,31 @@ function validateInputFields(context, inputObj) {
|
|
|
631
639
|
} // Ensure the arguments are valid
|
|
632
640
|
|
|
633
641
|
|
|
634
|
-
var
|
|
635
|
-
var
|
|
636
|
-
var
|
|
642
|
+
var _iteratorNormalCompletion13 = true;
|
|
643
|
+
var _didIteratorError13 = false;
|
|
644
|
+
var _iteratorError13 = undefined;
|
|
637
645
|
|
|
638
646
|
try {
|
|
639
|
-
for (var
|
|
640
|
-
var field =
|
|
647
|
+
for (var _iterator13 = fields[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
|
|
648
|
+
var field = _step13.value;
|
|
641
649
|
// Ensure they are named correctly.
|
|
642
|
-
validateName(context, field); //
|
|
643
|
-
// Ensure the type is an input type
|
|
650
|
+
validateName(context, field); // Ensure the type is an input type
|
|
644
651
|
|
|
645
652
|
if (!(0, _definition.isInputType)(field.type)) {
|
|
646
653
|
context.reportError("The type of ".concat(inputObj.name, ".").concat(field.name, " must be Input Type ") + "but got: ".concat((0, _inspect.default)(field.type), "."), field.astNode && field.astNode.type);
|
|
647
654
|
}
|
|
648
655
|
}
|
|
649
656
|
} catch (err) {
|
|
650
|
-
|
|
651
|
-
|
|
657
|
+
_didIteratorError13 = true;
|
|
658
|
+
_iteratorError13 = err;
|
|
652
659
|
} finally {
|
|
653
660
|
try {
|
|
654
|
-
if (!
|
|
655
|
-
|
|
661
|
+
if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
|
|
662
|
+
_iterator13.return();
|
|
656
663
|
}
|
|
657
664
|
} finally {
|
|
658
|
-
if (
|
|
659
|
-
throw
|
|
665
|
+
if (_didIteratorError13) {
|
|
666
|
+
throw _iteratorError13;
|
|
660
667
|
}
|
|
661
668
|
}
|
|
662
669
|
}
|
|
@@ -669,39 +676,9 @@ function getAllNodes(object) {
|
|
|
669
676
|
}
|
|
670
677
|
|
|
671
678
|
function getAllSubNodes(object, getter) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
var _iteratorError13 = undefined;
|
|
676
|
-
|
|
677
|
-
try {
|
|
678
|
-
for (var _iterator13 = getAllNodes(object)[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
|
|
679
|
-
var astNode = _step13.value;
|
|
680
|
-
|
|
681
|
-
if (astNode) {
|
|
682
|
-
var subNodes = getter(astNode);
|
|
683
|
-
|
|
684
|
-
if (subNodes) {
|
|
685
|
-
result = result.concat(subNodes);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
} catch (err) {
|
|
690
|
-
_didIteratorError13 = true;
|
|
691
|
-
_iteratorError13 = err;
|
|
692
|
-
} finally {
|
|
693
|
-
try {
|
|
694
|
-
if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
|
|
695
|
-
_iterator13.return();
|
|
696
|
-
}
|
|
697
|
-
} finally {
|
|
698
|
-
if (_didIteratorError13) {
|
|
699
|
-
throw _iteratorError13;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
return result;
|
|
679
|
+
return (0, _flatMap.default)(getAllNodes(object), function (item) {
|
|
680
|
+
return getter(item) || [];
|
|
681
|
+
});
|
|
705
682
|
}
|
|
706
683
|
|
|
707
684
|
function getImplementsInterfaceNode(type, iface) {
|
|
@@ -717,13 +694,9 @@ function getAllImplementsInterfaceNodes(type, iface) {
|
|
|
717
694
|
}
|
|
718
695
|
|
|
719
696
|
function getFieldNode(type, fieldName) {
|
|
720
|
-
return
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
function getAllFieldNodes(type, fieldName) {
|
|
724
|
-
return getAllSubNodes(type, function (typeNode) {
|
|
697
|
+
return (0, _find.default)(getAllSubNodes(type, function (typeNode) {
|
|
725
698
|
return typeNode.fields;
|
|
726
|
-
})
|
|
699
|
+
}), function (fieldNode) {
|
|
727
700
|
return fieldNode.name.value === fieldName;
|
|
728
701
|
});
|
|
729
702
|
}
|
|
@@ -797,12 +770,4 @@ function getUnionMemberTypeNodes(union, typeName) {
|
|
|
797
770
|
}).filter(function (typeNode) {
|
|
798
771
|
return typeNode.name.value === typeName;
|
|
799
772
|
});
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
function getEnumValueNodes(enumType, valueName) {
|
|
803
|
-
return getAllSubNodes(enumType, function (enumNode) {
|
|
804
|
-
return enumNode.values;
|
|
805
|
-
}).filter(function (valueNode) {
|
|
806
|
-
return valueNode.name.value === valueName;
|
|
807
|
-
});
|
|
808
773
|
}
|
package/type/validate.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import find from '../polyfills/find';
|
|
11
|
+
import flatMap from '../polyfills/flatMap';
|
|
12
|
+
import objectValues from '../polyfills/objectValues';
|
|
13
|
+
import objectEntries from '../polyfills/objectEntries';
|
|
10
14
|
import {
|
|
11
15
|
isObjectType,
|
|
12
16
|
isInterfaceType,
|
|
@@ -28,17 +32,13 @@ import type {
|
|
|
28
32
|
import { isDirective } from './directives';
|
|
29
33
|
import type { GraphQLDirective } from './directives';
|
|
30
34
|
import { isIntrospectionType } from './introspection';
|
|
31
|
-
import {
|
|
35
|
+
import { assertSchema } from './schema';
|
|
32
36
|
import type { GraphQLSchema } from './schema';
|
|
33
37
|
import inspect from '../jsutils/inspect';
|
|
34
|
-
import find from '../jsutils/find';
|
|
35
|
-
import invariant from '../jsutils/invariant';
|
|
36
|
-
import objectValues from '../jsutils/objectValues';
|
|
37
38
|
import { GraphQLError } from '../error/GraphQLError';
|
|
38
39
|
import type {
|
|
39
40
|
ASTNode,
|
|
40
41
|
FieldDefinitionNode,
|
|
41
|
-
EnumValueDefinitionNode,
|
|
42
42
|
InputValueDefinitionNode,
|
|
43
43
|
NamedTypeNode,
|
|
44
44
|
TypeNode,
|
|
@@ -57,10 +57,7 @@ export function validateSchema(
|
|
|
57
57
|
schema: GraphQLSchema,
|
|
58
58
|
): $ReadOnlyArray<GraphQLError> {
|
|
59
59
|
// First check to ensure the provided value is in fact a GraphQLSchema.
|
|
60
|
-
|
|
61
|
-
isSchema(schema),
|
|
62
|
-
`Expected ${inspect(schema)} to be a GraphQL schema.`,
|
|
63
|
-
);
|
|
60
|
+
assertSchema(schema);
|
|
64
61
|
|
|
65
62
|
// If this Schema has already been validated, return the previous results.
|
|
66
63
|
if (schema.__validationErrors) {
|
|
@@ -104,7 +101,7 @@ class SchemaValidationContext {
|
|
|
104
101
|
message: string,
|
|
105
102
|
nodes?: $ReadOnlyArray<?ASTNode> | ?ASTNode,
|
|
106
103
|
): void {
|
|
107
|
-
const _nodes =
|
|
104
|
+
const _nodes = Array.isArray(nodes) ? nodes.filter(Boolean) : nodes;
|
|
108
105
|
this.addError(new GraphQLError(message, _nodes));
|
|
109
106
|
}
|
|
110
107
|
|
|
@@ -284,16 +281,6 @@ function validateFields(
|
|
|
284
281
|
// Ensure they are named correctly.
|
|
285
282
|
validateName(context, field);
|
|
286
283
|
|
|
287
|
-
// Ensure they were defined at most once.
|
|
288
|
-
const fieldNodes = getAllFieldNodes(type, field.name);
|
|
289
|
-
if (fieldNodes.length > 1) {
|
|
290
|
-
context.reportError(
|
|
291
|
-
`Field ${type.name}.${field.name} can only be defined once.`,
|
|
292
|
-
fieldNodes,
|
|
293
|
-
);
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
284
|
// Ensure the type is an output type
|
|
298
285
|
if (!isOutputType(field.type)) {
|
|
299
286
|
context.reportError(
|
|
@@ -369,9 +356,8 @@ function validateObjectImplementsInterface(
|
|
|
369
356
|
const ifaceFieldMap = iface.getFields();
|
|
370
357
|
|
|
371
358
|
// Assert each interface field is implemented.
|
|
372
|
-
for (const fieldName of
|
|
359
|
+
for (const [fieldName, ifaceField] of objectEntries(ifaceFieldMap)) {
|
|
373
360
|
const objectField = objectFieldMap[fieldName];
|
|
374
|
-
const ifaceField = ifaceFieldMap[fieldName];
|
|
375
361
|
|
|
376
362
|
// Assert interface field exists on object.
|
|
377
363
|
if (!objectField) {
|
|
@@ -503,15 +489,6 @@ function validateEnumValues(
|
|
|
503
489
|
for (const enumValue of enumValues) {
|
|
504
490
|
const valueName = enumValue.name;
|
|
505
491
|
|
|
506
|
-
// Ensure no duplicates.
|
|
507
|
-
const allNodes = getEnumValueNodes(enumType, valueName);
|
|
508
|
-
if (allNodes && allNodes.length > 1) {
|
|
509
|
-
context.reportError(
|
|
510
|
-
`Enum type ${enumType.name} can include value ${valueName} only once.`,
|
|
511
|
-
allNodes,
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
492
|
// Ensure valid name.
|
|
516
493
|
validateName(context, enumValue);
|
|
517
494
|
if (valueName === 'true' || valueName === 'false' || valueName === 'null') {
|
|
@@ -541,8 +518,6 @@ function validateInputFields(
|
|
|
541
518
|
// Ensure they are named correctly.
|
|
542
519
|
validateName(context, field);
|
|
543
520
|
|
|
544
|
-
// TODO: Ensure they are unique per field.
|
|
545
|
-
|
|
546
521
|
// Ensure the type is an input type
|
|
547
522
|
if (!isInputType(field.type)) {
|
|
548
523
|
context.reportError(
|
|
@@ -574,16 +549,7 @@ function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
|
|
|
574
549
|
object: SDLDefinedObject<T, K>,
|
|
575
550
|
getter: (T | K) => ?(L | $ReadOnlyArray<L>),
|
|
576
551
|
): $ReadOnlyArray<L> {
|
|
577
|
-
|
|
578
|
-
for (const astNode of getAllNodes(object)) {
|
|
579
|
-
if (astNode) {
|
|
580
|
-
const subNodes = getter(astNode);
|
|
581
|
-
if (subNodes) {
|
|
582
|
-
result = result.concat(subNodes);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
return result;
|
|
552
|
+
return flatMap(getAllNodes(object), item => getter(item) || []);
|
|
587
553
|
}
|
|
588
554
|
|
|
589
555
|
function getImplementsInterfaceNode(
|
|
@@ -606,14 +572,8 @@ function getFieldNode(
|
|
|
606
572
|
type: GraphQLObjectType | GraphQLInterfaceType,
|
|
607
573
|
fieldName: string,
|
|
608
574
|
): ?FieldDefinitionNode {
|
|
609
|
-
return
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
function getAllFieldNodes(
|
|
613
|
-
type: GraphQLObjectType | GraphQLInterfaceType,
|
|
614
|
-
fieldName: string,
|
|
615
|
-
): $ReadOnlyArray<FieldDefinitionNode> {
|
|
616
|
-
return getAllSubNodes(type, typeNode => typeNode.fields).filter(
|
|
575
|
+
return find(
|
|
576
|
+
getAllSubNodes(type, typeNode => typeNode.fields),
|
|
617
577
|
fieldNode => fieldNode.name.value === fieldName,
|
|
618
578
|
);
|
|
619
579
|
}
|
|
@@ -686,12 +646,3 @@ function getUnionMemberTypeNodes(
|
|
|
686
646
|
typeNode => typeNode.name.value === typeName,
|
|
687
647
|
);
|
|
688
648
|
}
|
|
689
|
-
|
|
690
|
-
function getEnumValueNodes(
|
|
691
|
-
enumType: GraphQLEnumType,
|
|
692
|
-
valueName: string,
|
|
693
|
-
): ?$ReadOnlyArray<EnumValueDefinitionNode> {
|
|
694
|
-
return getAllSubNodes(enumType, enumNode => enumNode.values).filter(
|
|
695
|
-
valueNode => valueNode.name.value === valueName,
|
|
696
|
-
);
|
|
697
|
-
}
|