graphql 0.0.1-test.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 +21 -0
- package/NotSupportedTSVersion.d.ts +1 -0
- package/README.md +158 -0
- package/error/GraphQLError.d.ts +142 -0
- package/error/GraphQLError.js +267 -0
- package/error/GraphQLError.mjs +253 -0
- package/error/index.d.ts +7 -0
- package/error/index.js +41 -0
- package/error/index.mjs +3 -0
- package/error/locatedError.d.ts +13 -0
- package/error/locatedError.js +40 -0
- package/error/locatedError.mjs +32 -0
- package/error/syntaxError.d.ts +11 -0
- package/error/syntaxError.js +21 -0
- package/error/syntaxError.mjs +11 -0
- package/execution/collectFields.d.ts +45 -0
- package/execution/collectFields.js +229 -0
- package/execution/collectFields.mjs +213 -0
- package/execution/execute.d.ts +185 -0
- package/execution/execute.js +1016 -0
- package/execution/execute.mjs +988 -0
- package/execution/index.d.ts +14 -0
- package/execution/index.js +67 -0
- package/execution/index.mjs +9 -0
- package/execution/mapAsyncIterator.d.ts +9 -0
- package/execution/mapAsyncIterator.js +68 -0
- package/execution/mapAsyncIterator.mjs +61 -0
- package/execution/subscribe.d.ts +68 -0
- package/execution/subscribe.js +261 -0
- package/execution/subscribe.mjs +239 -0
- package/execution/values.d.ts +81 -0
- package/execution/values.js +292 -0
- package/execution/values.mjs +255 -0
- package/graphql.d.ts +67 -0
- package/graphql.js +96 -0
- package/graphql.mjs +122 -0
- package/index.d.ts +411 -0
- package/index.js +1263 -0
- package/index.mjs +254 -0
- package/jsutils/Maybe.d.ts +2 -0
- package/jsutils/Maybe.js +5 -0
- package/jsutils/Maybe.mjs +1 -0
- package/jsutils/ObjMap.d.ts +16 -0
- package/jsutils/ObjMap.js +5 -0
- package/jsutils/ObjMap.mjs +1 -0
- package/jsutils/Path.d.ts +20 -0
- package/jsutils/Path.js +33 -0
- package/jsutils/Path.mjs +25 -0
- package/jsutils/PromiseOrValue.d.ts +1 -0
- package/jsutils/PromiseOrValue.js +5 -0
- package/jsutils/PromiseOrValue.mjs +1 -0
- package/jsutils/devAssert.d.ts +1 -0
- package/jsutils/devAssert.js +14 -0
- package/jsutils/devAssert.mjs +7 -0
- package/jsutils/didYouMean.d.ts +8 -0
- package/jsutils/didYouMean.js +38 -0
- package/jsutils/didYouMean.mjs +32 -0
- package/jsutils/groupBy.d.ts +7 -0
- package/jsutils/groupBy.js +26 -0
- package/jsutils/groupBy.mjs +19 -0
- package/jsutils/identityFunc.d.ts +4 -0
- package/jsutils/identityFunc.js +13 -0
- package/jsutils/identityFunc.mjs +6 -0
- package/jsutils/inspect.d.ts +4 -0
- package/jsutils/inspect.js +121 -0
- package/jsutils/inspect.mjs +115 -0
- package/jsutils/instanceOf.d.ts +16 -0
- package/jsutils/instanceOf.js +60 -0
- package/jsutils/instanceOf.mjs +52 -0
- package/jsutils/invariant.d.ts +4 -0
- package/jsutils/invariant.js +16 -0
- package/jsutils/invariant.mjs +9 -0
- package/jsutils/isAsyncIterable.d.ts +7 -0
- package/jsutils/isAsyncIterable.js +18 -0
- package/jsutils/isAsyncIterable.mjs +11 -0
- package/jsutils/isIterableObject.d.ts +20 -0
- package/jsutils/isIterableObject.js +32 -0
- package/jsutils/isIterableObject.mjs +25 -0
- package/jsutils/isObjectLike.d.ts +7 -0
- package/jsutils/isObjectLike.js +14 -0
- package/jsutils/isObjectLike.mjs +7 -0
- package/jsutils/isPromise.d.ts +5 -0
- package/jsutils/isPromise.js +17 -0
- package/jsutils/isPromise.mjs +10 -0
- package/jsutils/keyMap.d.ts +32 -0
- package/jsutils/keyMap.js +43 -0
- package/jsutils/keyMap.mjs +36 -0
- package/jsutils/keyValMap.d.ts +23 -0
- package/jsutils/keyValMap.js +33 -0
- package/jsutils/keyValMap.mjs +26 -0
- package/jsutils/mapValue.d.ts +9 -0
- package/jsutils/mapValue.js +20 -0
- package/jsutils/mapValue.mjs +13 -0
- package/jsutils/memoize3.d.ts +9 -0
- package/jsutils/memoize3.js +41 -0
- package/jsutils/memoize3.mjs +34 -0
- package/jsutils/naturalCompare.d.ts +8 -0
- package/jsutils/naturalCompare.js +69 -0
- package/jsutils/naturalCompare.mjs +61 -0
- package/jsutils/printPathArray.d.ts +6 -0
- package/jsutils/printPathArray.js +17 -0
- package/jsutils/printPathArray.mjs +10 -0
- package/jsutils/promiseForObject.d.ts +11 -0
- package/jsutils/promiseForObject.js +25 -0
- package/jsutils/promiseForObject.mjs +18 -0
- package/jsutils/promiseReduce.d.ts +13 -0
- package/jsutils/promiseReduce.js +27 -0
- package/jsutils/promiseReduce.mjs +20 -0
- package/jsutils/suggestionList.d.ts +8 -0
- package/jsutils/suggestionList.js +139 -0
- package/jsutils/suggestionList.mjs +130 -0
- package/jsutils/toError.d.ts +4 -0
- package/jsutils/toError.js +25 -0
- package/jsutils/toError.mjs +18 -0
- package/jsutils/toObjMap.d.ts +5 -0
- package/jsutils/toObjMap.js +24 -0
- package/jsutils/toObjMap.mjs +17 -0
- package/language/ast.d.ts +536 -0
- package/language/ast.js +224 -0
- package/language/ast.mjs +206 -0
- package/language/blockString.d.ts +28 -0
- package/language/blockString.js +195 -0
- package/language/blockString.mjs +178 -0
- package/language/characterClasses.d.ts +47 -0
- package/language/characterClasses.js +75 -0
- package/language/characterClasses.mjs +64 -0
- package/language/directiveLocation.d.ts +32 -0
- package/language/directiveLocation.js +40 -0
- package/language/directiveLocation.mjs +31 -0
- package/language/index.d.ts +97 -0
- package/language/index.js +215 -0
- package/language/index.mjs +29 -0
- package/language/kinds.d.ts +65 -0
- package/language/kinds.js +64 -0
- package/language/kinds.mjs +55 -0
- package/language/lexer.d.ts +45 -0
- package/language/lexer.js +1006 -0
- package/language/lexer.mjs +902 -0
- package/language/location.d.ts +16 -0
- package/language/location.js +38 -0
- package/language/location.mjs +30 -0
- package/language/parser.d.ts +554 -0
- package/language/parser.js +1567 -0
- package/language/parser.mjs +1524 -0
- package/language/predicates.d.ts +33 -0
- package/language/predicates.js +109 -0
- package/language/predicates.mjs +81 -0
- package/language/printLocation.d.ts +14 -0
- package/language/printLocation.js +74 -0
- package/language/printLocation.mjs +66 -0
- package/language/printString.d.ts +5 -0
- package/language/printString.js +183 -0
- package/language/printString.mjs +176 -0
- package/language/printer.d.ts +6 -0
- package/language/printer.js +351 -0
- package/language/printer.mjs +339 -0
- package/language/source.d.ts +25 -0
- package/language/source.js +65 -0
- package/language/source.mjs +50 -0
- package/language/tokenKind.d.ts +34 -0
- package/language/tokenKind.js +44 -0
- package/language/tokenKind.mjs +35 -0
- package/language/visitor.d.ts +194 -0
- package/language/visitor.js +377 -0
- package/language/visitor.mjs +361 -0
- package/package.json +40 -0
- package/subscription/index.d.ts +19 -0
- package/subscription/index.js +19 -0
- package/subscription/index.mjs +19 -0
- package/type/assertName.d.ts +10 -0
- package/type/assertName.js +59 -0
- package/type/assertName.mjs +44 -0
- package/type/definition.d.ts +917 -0
- package/type/definition.js +1329 -0
- package/type/definition.mjs +1167 -0
- package/type/directives.d.ts +86 -0
- package/type/directives.js +224 -0
- package/type/directives.mjs +190 -0
- package/type/index.d.ts +150 -0
- package/type/index.js +547 -0
- package/type/index.mjs +103 -0
- package/type/introspection.d.ts +29 -0
- package/type/introspection.js +617 -0
- package/type/introspection.mjs +550 -0
- package/type/scalars.d.ts +19 -0
- package/type/scalars.js +359 -0
- package/type/scalars.mjs +299 -0
- package/type/schema.d.ts +170 -0
- package/type/schema.js +402 -0
- package/type/schema.mjs +381 -0
- package/type/validate.d.ts +17 -0
- package/type/validate.js +672 -0
- package/type/validate.mjs +647 -0
- package/utilities/TypeInfo.d.ts +67 -0
- package/utilities/TypeInfo.js +418 -0
- package/utilities/TypeInfo.mjs +395 -0
- package/utilities/assertValidName.d.ts +13 -0
- package/utilities/assertValidName.js +51 -0
- package/utilities/assertValidName.mjs +40 -0
- package/utilities/astFromValue.d.ts +28 -0
- package/utilities/astFromValue.js +190 -0
- package/utilities/astFromValue.mjs +177 -0
- package/utilities/buildASTSchema.d.ts +35 -0
- package/utilities/buildASTSchema.js +115 -0
- package/utilities/buildASTSchema.mjs +97 -0
- package/utilities/buildClientSchema.d.ts +19 -0
- package/utilities/buildClientSchema.js +386 -0
- package/utilities/buildClientSchema.mjs +363 -0
- package/utilities/coerceInputValue.d.ts +16 -0
- package/utilities/coerceInputValue.js +191 -0
- package/utilities/coerceInputValue.mjs +172 -0
- package/utilities/concatAST.d.ts +9 -0
- package/utilities/concatAST.js +26 -0
- package/utilities/concatAST.mjs +19 -0
- package/utilities/extendSchema.d.ts +40 -0
- package/utilities/extendSchema.js +798 -0
- package/utilities/extendSchema.mjs +789 -0
- package/utilities/findBreakingChanges.d.ts +51 -0
- package/utilities/findBreakingChanges.js +547 -0
- package/utilities/findBreakingChanges.mjs +516 -0
- package/utilities/getIntrospectionQuery.d.ts +182 -0
- package/utilities/getIntrospectionQuery.js +134 -0
- package/utilities/getIntrospectionQuery.mjs +127 -0
- package/utilities/getOperationAST.d.ts +11 -0
- package/utilities/getOperationAST.js +43 -0
- package/utilities/getOperationAST.mjs +36 -0
- package/utilities/getOperationRootType.d.ts +15 -0
- package/utilities/getOperationRootType.js +59 -0
- package/utilities/getOperationRootType.mjs +52 -0
- package/utilities/index.d.ts +61 -0
- package/utilities/index.js +233 -0
- package/utilities/index.mjs +55 -0
- package/utilities/introspectionFromSchema.d.ts +18 -0
- package/utilities/introspectionFromSchema.js +42 -0
- package/utilities/introspectionFromSchema.mjs +30 -0
- package/utilities/lexicographicSortSchema.d.ts +9 -0
- package/utilities/lexicographicSortSchema.js +177 -0
- package/utilities/lexicographicSortSchema.mjs +172 -0
- package/utilities/printSchema.d.ts +5 -0
- package/utilities/printSchema.js +333 -0
- package/utilities/printSchema.mjs +309 -0
- package/utilities/separateOperations.d.ts +11 -0
- package/utilities/separateOperations.js +88 -0
- package/utilities/separateOperations.mjs +80 -0
- package/utilities/sortValueNode.d.ts +9 -0
- package/utilities/sortValueNode.js +47 -0
- package/utilities/sortValueNode.mjs +39 -0
- package/utilities/stripIgnoredCharacters.d.ts +62 -0
- package/utilities/stripIgnoredCharacters.js +121 -0
- package/utilities/stripIgnoredCharacters.mjs +104 -0
- package/utilities/typeComparators.d.ts +32 -0
- package/utilities/typeComparators.js +116 -0
- package/utilities/typeComparators.mjs +106 -0
- package/utilities/typeFromAST.d.ts +32 -0
- package/utilities/typeFromAST.js +27 -0
- package/utilities/typeFromAST.mjs +18 -0
- package/utilities/typedQueryDocumentNode.d.ts +22 -0
- package/utilities/typedQueryDocumentNode.js +5 -0
- package/utilities/typedQueryDocumentNode.mjs +1 -0
- package/utilities/valueFromAST.d.ts +29 -0
- package/utilities/valueFromAST.js +185 -0
- package/utilities/valueFromAST.mjs +172 -0
- package/utilities/valueFromASTUntyped.d.ts +23 -0
- package/utilities/valueFromASTUntyped.js +61 -0
- package/utilities/valueFromASTUntyped.mjs +53 -0
- package/validation/ValidationContext.d.ts +95 -0
- package/validation/ValidationContext.js +232 -0
- package/validation/ValidationContext.mjs +212 -0
- package/validation/index.d.ts +40 -0
- package/validation/index.js +317 -0
- package/validation/index.mjs +68 -0
- package/validation/rules/ExecutableDefinitionsRule.d.ts +13 -0
- package/validation/rules/ExecutableDefinitionsRule.js +44 -0
- package/validation/rules/ExecutableDefinitionsRule.mjs +35 -0
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +13 -0
- package/validation/rules/FieldsOnCorrectTypeRule.js +143 -0
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +125 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +14 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.js +65 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs +49 -0
- package/validation/rules/KnownArgumentNamesRule.d.ts +23 -0
- package/validation/rules/KnownArgumentNamesRule.js +116 -0
- package/validation/rules/KnownArgumentNamesRule.mjs +98 -0
- package/validation/rules/KnownDirectivesRule.d.ts +16 -0
- package/validation/rules/KnownDirectivesRule.js +163 -0
- package/validation/rules/KnownDirectivesRule.mjs +146 -0
- package/validation/rules/KnownFragmentNamesRule.d.ts +13 -0
- package/validation/rules/KnownFragmentNamesRule.js +34 -0
- package/validation/rules/KnownFragmentNamesRule.mjs +24 -0
- package/validation/rules/KnownTypeNamesRule.d.ts +16 -0
- package/validation/rules/KnownTypeNamesRule.js +87 -0
- package/validation/rules/KnownTypeNamesRule.mjs +75 -0
- package/validation/rules/LoneAnonymousOperationRule.d.ts +13 -0
- package/validation/rules/LoneAnonymousOperationRule.js +40 -0
- package/validation/rules/LoneAnonymousOperationRule.mjs +32 -0
- package/validation/rules/LoneSchemaDefinitionRule.d.ts +10 -0
- package/validation/rules/LoneSchemaDefinitionRule.js +63 -0
- package/validation/rules/LoneSchemaDefinitionRule.mjs +53 -0
- package/validation/rules/NoFragmentCyclesRule.d.ts +13 -0
- package/validation/rules/NoFragmentCyclesRule.js +83 -0
- package/validation/rules/NoFragmentCyclesRule.mjs +76 -0
- package/validation/rules/NoUndefinedVariablesRule.d.ts +13 -0
- package/validation/rules/NoUndefinedVariablesRule.js +50 -0
- package/validation/rules/NoUndefinedVariablesRule.mjs +43 -0
- package/validation/rules/NoUnusedFragmentsRule.d.ts +13 -0
- package/validation/rules/NoUnusedFragmentsRule.js +59 -0
- package/validation/rules/NoUnusedFragmentsRule.mjs +52 -0
- package/validation/rules/NoUnusedVariablesRule.d.ts +13 -0
- package/validation/rules/NoUnusedVariablesRule.js +55 -0
- package/validation/rules/NoUnusedVariablesRule.mjs +48 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule-old.js +805 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule-old.mjs +788 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +14 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +805 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +788 -0
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +12 -0
- package/validation/rules/PossibleFragmentSpreadsRule.js +91 -0
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +69 -0
- package/validation/rules/PossibleTypeExtensionsRule.d.ts +10 -0
- package/validation/rules/PossibleTypeExtensionsRule.js +167 -0
- package/validation/rules/PossibleTypeExtensionsRule.mjs +147 -0
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +20 -0
- package/validation/rules/ProvidedRequiredArgumentsRule.js +158 -0
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +138 -0
- package/validation/rules/ScalarLeafsRule.d.ts +9 -0
- package/validation/rules/ScalarLeafsRule.js +51 -0
- package/validation/rules/ScalarLeafsRule.mjs +42 -0
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +13 -0
- package/validation/rules/SingleFieldSubscriptionsRule.js +82 -0
- package/validation/rules/SingleFieldSubscriptionsRule.mjs +73 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.d.ts +11 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.js +90 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +79 -0
- package/validation/rules/UniqueArgumentNamesRule.d.ts +13 -0
- package/validation/rules/UniqueArgumentNamesRule.js +53 -0
- package/validation/rules/UniqueArgumentNamesRule.mjs +42 -0
- package/validation/rules/UniqueDirectiveNamesRule.d.ts +10 -0
- package/validation/rules/UniqueDirectiveNamesRule.js +50 -0
- package/validation/rules/UniqueDirectiveNamesRule.mjs +43 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +16 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.js +93 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs +83 -0
- package/validation/rules/UniqueEnumValueNamesRule.d.ts +10 -0
- package/validation/rules/UniqueEnumValueNamesRule.js +71 -0
- package/validation/rules/UniqueEnumValueNamesRule.mjs +60 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.d.ts +10 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +83 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +75 -0
- package/validation/rules/UniqueFragmentNamesRule.d.ts +12 -0
- package/validation/rules/UniqueFragmentNamesRule.js +39 -0
- package/validation/rules/UniqueFragmentNamesRule.mjs +32 -0
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +13 -0
- package/validation/rules/UniqueInputFieldNamesRule.js +52 -0
- package/validation/rules/UniqueInputFieldNamesRule.mjs +44 -0
- package/validation/rules/UniqueOperationNamesRule.d.ts +12 -0
- package/validation/rules/UniqueOperationNamesRule.js +41 -0
- package/validation/rules/UniqueOperationNamesRule.mjs +34 -0
- package/validation/rules/UniqueOperationTypesRule.d.ts +10 -0
- package/validation/rules/UniqueOperationTypesRule.js +67 -0
- package/validation/rules/UniqueOperationTypesRule.mjs +60 -0
- package/validation/rules/UniqueTypeNamesRule.d.ts +10 -0
- package/validation/rules/UniqueTypeNamesRule.js +53 -0
- package/validation/rules/UniqueTypeNamesRule.mjs +46 -0
- package/validation/rules/UniqueVariableNamesRule.d.ts +10 -0
- package/validation/rules/UniqueVariableNamesRule.js +47 -0
- package/validation/rules/UniqueVariableNamesRule.mjs +39 -0
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +13 -0
- package/validation/rules/ValuesOfCorrectTypeRule.js +183 -0
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +164 -0
- package/validation/rules/VariablesAreInputTypesRule.d.ts +13 -0
- package/validation/rules/VariablesAreInputTypesRule.js +44 -0
- package/validation/rules/VariablesAreInputTypesRule.mjs +31 -0
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +12 -0
- package/validation/rules/VariablesInAllowedPositionRule.js +114 -0
- package/validation/rules/VariablesInAllowedPositionRule.mjs +95 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +15 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.js +121 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +107 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +15 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +39 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +30 -0
- package/validation/specifiedRules.d.ts +12 -0
- package/validation/specifiedRules.js +160 -0
- package/validation/specifiedRules.mjs +123 -0
- package/validation/validate.d.ts +61 -0
- package/validation/validate.js +151 -0
- package/validation/validate.mjs +133 -0
- package/version.d.ts +13 -0
- package/version.js +25 -0
- package/version.mjs +17 -0
package/type/validate.js
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.assertValidSchema = assertValidSchema;
|
|
7
|
+
exports.validateSchema = validateSchema;
|
|
8
|
+
|
|
9
|
+
var _inspect = require('../jsutils/inspect.js');
|
|
10
|
+
|
|
11
|
+
var _GraphQLError = require('../error/GraphQLError.js');
|
|
12
|
+
|
|
13
|
+
var _ast = require('../language/ast.js');
|
|
14
|
+
|
|
15
|
+
var _typeComparators = require('../utilities/typeComparators.js');
|
|
16
|
+
|
|
17
|
+
var _definition = require('./definition.js');
|
|
18
|
+
|
|
19
|
+
var _directives = require('./directives.js');
|
|
20
|
+
|
|
21
|
+
var _introspection = require('./introspection.js');
|
|
22
|
+
|
|
23
|
+
var _schema = require('./schema.js');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Implements the "Type Validation" sub-sections of the specification's
|
|
27
|
+
* "Type System" section.
|
|
28
|
+
*
|
|
29
|
+
* Validation runs synchronously, returning an array of encountered errors, or
|
|
30
|
+
* an empty array if no errors were encountered and the Schema is valid.
|
|
31
|
+
*/
|
|
32
|
+
function validateSchema(schema) {
|
|
33
|
+
// First check to ensure the provided value is in fact a GraphQLSchema.
|
|
34
|
+
(0, _schema.assertSchema)(schema); // If this Schema has already been validated, return the previous results.
|
|
35
|
+
|
|
36
|
+
if (schema.__validationErrors) {
|
|
37
|
+
return schema.__validationErrors;
|
|
38
|
+
} // Validate the schema, producing a list of errors.
|
|
39
|
+
|
|
40
|
+
const context = new SchemaValidationContext(schema);
|
|
41
|
+
validateRootTypes(context);
|
|
42
|
+
validateDirectives(context);
|
|
43
|
+
validateTypes(context); // Persist the results of validation before returning to ensure validation
|
|
44
|
+
// does not run multiple times for this schema.
|
|
45
|
+
|
|
46
|
+
const errors = context.getErrors();
|
|
47
|
+
schema.__validationErrors = errors;
|
|
48
|
+
return errors;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Utility function which asserts a schema is valid by throwing an error if
|
|
52
|
+
* it is invalid.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
function assertValidSchema(schema) {
|
|
56
|
+
const errors = validateSchema(schema);
|
|
57
|
+
|
|
58
|
+
if (errors.length !== 0) {
|
|
59
|
+
throw new Error(errors.map((error) => error.message).join('\n\n'));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class SchemaValidationContext {
|
|
64
|
+
constructor(schema) {
|
|
65
|
+
this._errors = [];
|
|
66
|
+
this.schema = schema;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
reportError(message, nodes) {
|
|
70
|
+
const _nodes = Array.isArray(nodes) ? nodes.filter(Boolean) : nodes;
|
|
71
|
+
|
|
72
|
+
this._errors.push(new _GraphQLError.GraphQLError(message, _nodes));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getErrors() {
|
|
76
|
+
return this._errors;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function validateRootTypes(context) {
|
|
81
|
+
const schema = context.schema;
|
|
82
|
+
const queryType = schema.getQueryType();
|
|
83
|
+
|
|
84
|
+
if (!queryType) {
|
|
85
|
+
context.reportError('Query root type must be provided.', schema.astNode);
|
|
86
|
+
} else if (!(0, _definition.isObjectType)(queryType)) {
|
|
87
|
+
var _getOperationTypeNode;
|
|
88
|
+
|
|
89
|
+
context.reportError(
|
|
90
|
+
`Query root type must be Object type, it cannot be ${(0,
|
|
91
|
+
_inspect.inspect)(queryType)}.`,
|
|
92
|
+
(_getOperationTypeNode = getOperationTypeNode(
|
|
93
|
+
schema,
|
|
94
|
+
_ast.OperationTypeNode.QUERY,
|
|
95
|
+
)) !== null && _getOperationTypeNode !== void 0
|
|
96
|
+
? _getOperationTypeNode
|
|
97
|
+
: queryType.astNode,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const mutationType = schema.getMutationType();
|
|
102
|
+
|
|
103
|
+
if (mutationType && !(0, _definition.isObjectType)(mutationType)) {
|
|
104
|
+
var _getOperationTypeNode2;
|
|
105
|
+
|
|
106
|
+
context.reportError(
|
|
107
|
+
'Mutation root type must be Object type if provided, it cannot be ' +
|
|
108
|
+
`${(0, _inspect.inspect)(mutationType)}.`,
|
|
109
|
+
(_getOperationTypeNode2 = getOperationTypeNode(
|
|
110
|
+
schema,
|
|
111
|
+
_ast.OperationTypeNode.MUTATION,
|
|
112
|
+
)) !== null && _getOperationTypeNode2 !== void 0
|
|
113
|
+
? _getOperationTypeNode2
|
|
114
|
+
: mutationType.astNode,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const subscriptionType = schema.getSubscriptionType();
|
|
119
|
+
|
|
120
|
+
if (subscriptionType && !(0, _definition.isObjectType)(subscriptionType)) {
|
|
121
|
+
var _getOperationTypeNode3;
|
|
122
|
+
|
|
123
|
+
context.reportError(
|
|
124
|
+
'Subscription root type must be Object type if provided, it cannot be ' +
|
|
125
|
+
`${(0, _inspect.inspect)(subscriptionType)}.`,
|
|
126
|
+
(_getOperationTypeNode3 = getOperationTypeNode(
|
|
127
|
+
schema,
|
|
128
|
+
_ast.OperationTypeNode.SUBSCRIPTION,
|
|
129
|
+
)) !== null && _getOperationTypeNode3 !== void 0
|
|
130
|
+
? _getOperationTypeNode3
|
|
131
|
+
: subscriptionType.astNode,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function getOperationTypeNode(schema, operation) {
|
|
137
|
+
var _flatMap$find;
|
|
138
|
+
|
|
139
|
+
return (_flatMap$find = [schema.astNode, ...schema.extensionASTNodes]
|
|
140
|
+
.flatMap(
|
|
141
|
+
// FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
142
|
+
(schemaNode) => {
|
|
143
|
+
var _schemaNode$operation;
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
/* c8 ignore next */
|
|
147
|
+
(_schemaNode$operation =
|
|
148
|
+
schemaNode === null || schemaNode === void 0
|
|
149
|
+
? void 0
|
|
150
|
+
: schemaNode.operationTypes) !== null &&
|
|
151
|
+
_schemaNode$operation !== void 0
|
|
152
|
+
? _schemaNode$operation
|
|
153
|
+
: []
|
|
154
|
+
);
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
.find((operationNode) => operationNode.operation === operation)) === null ||
|
|
158
|
+
_flatMap$find === void 0
|
|
159
|
+
? void 0
|
|
160
|
+
: _flatMap$find.type;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function validateDirectives(context) {
|
|
164
|
+
for (const directive of context.schema.getDirectives()) {
|
|
165
|
+
// Ensure all directives are in fact GraphQL directives.
|
|
166
|
+
if (!(0, _directives.isDirective)(directive)) {
|
|
167
|
+
context.reportError(
|
|
168
|
+
`Expected directive but got: ${(0, _inspect.inspect)(directive)}.`,
|
|
169
|
+
directive === null || directive === void 0 ? void 0 : directive.astNode,
|
|
170
|
+
);
|
|
171
|
+
continue;
|
|
172
|
+
} // Ensure they are named correctly.
|
|
173
|
+
|
|
174
|
+
validateName(context, directive); // TODO: Ensure proper locations.
|
|
175
|
+
// Ensure the arguments are valid.
|
|
176
|
+
|
|
177
|
+
for (const arg of directive.args) {
|
|
178
|
+
// Ensure they are named correctly.
|
|
179
|
+
validateName(context, arg); // Ensure the type is an input type.
|
|
180
|
+
|
|
181
|
+
if (!(0, _definition.isInputType)(arg.type)) {
|
|
182
|
+
context.reportError(
|
|
183
|
+
`The type of @${directive.name}(${arg.name}:) must be Input Type ` +
|
|
184
|
+
`but got: ${(0, _inspect.inspect)(arg.type)}.`,
|
|
185
|
+
arg.astNode,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
(0, _definition.isRequiredArgument)(arg) &&
|
|
191
|
+
arg.deprecationReason != null
|
|
192
|
+
) {
|
|
193
|
+
var _arg$astNode;
|
|
194
|
+
|
|
195
|
+
context.reportError(
|
|
196
|
+
`Required argument @${directive.name}(${arg.name}:) cannot be deprecated.`,
|
|
197
|
+
[
|
|
198
|
+
getDeprecatedDirectiveNode(arg.astNode),
|
|
199
|
+
(_arg$astNode = arg.astNode) === null || _arg$astNode === void 0
|
|
200
|
+
? void 0
|
|
201
|
+
: _arg$astNode.type,
|
|
202
|
+
],
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function validateName(context, node) {
|
|
210
|
+
// Ensure names are valid, however introspection types opt out.
|
|
211
|
+
if (node.name.startsWith('__')) {
|
|
212
|
+
context.reportError(
|
|
213
|
+
`Name "${node.name}" must not begin with "__", which is reserved by GraphQL introspection.`,
|
|
214
|
+
node.astNode,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function validateTypes(context) {
|
|
220
|
+
const validateInputObjectCircularRefs =
|
|
221
|
+
createInputObjectCircularRefsValidator(context);
|
|
222
|
+
const typeMap = context.schema.getTypeMap();
|
|
223
|
+
|
|
224
|
+
for (const type of Object.values(typeMap)) {
|
|
225
|
+
// Ensure all provided types are in fact GraphQL type.
|
|
226
|
+
if (!(0, _definition.isNamedType)(type)) {
|
|
227
|
+
context.reportError(
|
|
228
|
+
`Expected GraphQL named type but got: ${(0, _inspect.inspect)(type)}.`,
|
|
229
|
+
type.astNode,
|
|
230
|
+
);
|
|
231
|
+
continue;
|
|
232
|
+
} // Ensure it is named correctly (excluding introspection types).
|
|
233
|
+
|
|
234
|
+
if (!(0, _introspection.isIntrospectionType)(type)) {
|
|
235
|
+
validateName(context, type);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if ((0, _definition.isObjectType)(type)) {
|
|
239
|
+
// Ensure fields are valid
|
|
240
|
+
validateFields(context, type); // Ensure objects implement the interfaces they claim to.
|
|
241
|
+
|
|
242
|
+
validateInterfaces(context, type);
|
|
243
|
+
} else if ((0, _definition.isInterfaceType)(type)) {
|
|
244
|
+
// Ensure fields are valid.
|
|
245
|
+
validateFields(context, type); // Ensure interfaces implement the interfaces they claim to.
|
|
246
|
+
|
|
247
|
+
validateInterfaces(context, type);
|
|
248
|
+
} else if ((0, _definition.isUnionType)(type)) {
|
|
249
|
+
// Ensure Unions include valid member types.
|
|
250
|
+
validateUnionMembers(context, type);
|
|
251
|
+
} else if ((0, _definition.isEnumType)(type)) {
|
|
252
|
+
// Ensure Enums have valid values.
|
|
253
|
+
validateEnumValues(context, type);
|
|
254
|
+
} else if ((0, _definition.isInputObjectType)(type)) {
|
|
255
|
+
// Ensure Input Object fields are valid.
|
|
256
|
+
validateInputFields(context, type); // Ensure Input Objects do not contain non-nullable circular references
|
|
257
|
+
|
|
258
|
+
validateInputObjectCircularRefs(type);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function validateFields(context, type) {
|
|
264
|
+
const fields = Object.values(type.getFields()); // Objects and Interfaces both must define one or more fields.
|
|
265
|
+
|
|
266
|
+
if (fields.length === 0) {
|
|
267
|
+
context.reportError(`Type ${type.name} must define one or more fields.`, [
|
|
268
|
+
type.astNode,
|
|
269
|
+
...type.extensionASTNodes,
|
|
270
|
+
]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
for (const field of fields) {
|
|
274
|
+
// Ensure they are named correctly.
|
|
275
|
+
validateName(context, field); // Ensure the type is an output type
|
|
276
|
+
|
|
277
|
+
if (!(0, _definition.isOutputType)(field.type)) {
|
|
278
|
+
var _field$astNode;
|
|
279
|
+
|
|
280
|
+
context.reportError(
|
|
281
|
+
`The type of ${type.name}.${field.name} must be Output Type ` +
|
|
282
|
+
`but got: ${(0, _inspect.inspect)(field.type)}.`,
|
|
283
|
+
(_field$astNode = field.astNode) === null || _field$astNode === void 0
|
|
284
|
+
? void 0
|
|
285
|
+
: _field$astNode.type,
|
|
286
|
+
);
|
|
287
|
+
} // Ensure the arguments are valid
|
|
288
|
+
|
|
289
|
+
for (const arg of field.args) {
|
|
290
|
+
const argName = arg.name; // Ensure they are named correctly.
|
|
291
|
+
|
|
292
|
+
validateName(context, arg); // Ensure the type is an input type
|
|
293
|
+
|
|
294
|
+
if (!(0, _definition.isInputType)(arg.type)) {
|
|
295
|
+
var _arg$astNode2;
|
|
296
|
+
|
|
297
|
+
context.reportError(
|
|
298
|
+
`The type of ${type.name}.${field.name}(${argName}:) must be Input ` +
|
|
299
|
+
`Type but got: ${(0, _inspect.inspect)(arg.type)}.`,
|
|
300
|
+
(_arg$astNode2 = arg.astNode) === null || _arg$astNode2 === void 0
|
|
301
|
+
? void 0
|
|
302
|
+
: _arg$astNode2.type,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (
|
|
307
|
+
(0, _definition.isRequiredArgument)(arg) &&
|
|
308
|
+
arg.deprecationReason != null
|
|
309
|
+
) {
|
|
310
|
+
var _arg$astNode3;
|
|
311
|
+
|
|
312
|
+
context.reportError(
|
|
313
|
+
`Required argument ${type.name}.${field.name}(${argName}:) cannot be deprecated.`,
|
|
314
|
+
[
|
|
315
|
+
getDeprecatedDirectiveNode(arg.astNode),
|
|
316
|
+
(_arg$astNode3 = arg.astNode) === null || _arg$astNode3 === void 0
|
|
317
|
+
? void 0
|
|
318
|
+
: _arg$astNode3.type,
|
|
319
|
+
],
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function validateInterfaces(context, type) {
|
|
327
|
+
const ifaceTypeNames = Object.create(null);
|
|
328
|
+
|
|
329
|
+
for (const iface of type.getInterfaces()) {
|
|
330
|
+
if (!(0, _definition.isInterfaceType)(iface)) {
|
|
331
|
+
context.reportError(
|
|
332
|
+
`Type ${(0, _inspect.inspect)(
|
|
333
|
+
type,
|
|
334
|
+
)} must only implement Interface types, ` +
|
|
335
|
+
`it cannot implement ${(0, _inspect.inspect)(iface)}.`,
|
|
336
|
+
getAllImplementsInterfaceNodes(type, iface),
|
|
337
|
+
);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (type === iface) {
|
|
342
|
+
context.reportError(
|
|
343
|
+
`Type ${type.name} cannot implement itself because it would create a circular reference.`,
|
|
344
|
+
getAllImplementsInterfaceNodes(type, iface),
|
|
345
|
+
);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (ifaceTypeNames[iface.name]) {
|
|
350
|
+
context.reportError(
|
|
351
|
+
`Type ${type.name} can only implement ${iface.name} once.`,
|
|
352
|
+
getAllImplementsInterfaceNodes(type, iface),
|
|
353
|
+
);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
ifaceTypeNames[iface.name] = true;
|
|
358
|
+
validateTypeImplementsAncestors(context, type, iface);
|
|
359
|
+
validateTypeImplementsInterface(context, type, iface);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function validateTypeImplementsInterface(context, type, iface) {
|
|
364
|
+
const typeFieldMap = type.getFields(); // Assert each interface field is implemented.
|
|
365
|
+
|
|
366
|
+
for (const ifaceField of Object.values(iface.getFields())) {
|
|
367
|
+
const fieldName = ifaceField.name;
|
|
368
|
+
const typeField = typeFieldMap[fieldName]; // Assert interface field exists on type.
|
|
369
|
+
|
|
370
|
+
if (!typeField) {
|
|
371
|
+
context.reportError(
|
|
372
|
+
`Interface field ${iface.name}.${fieldName} expected but ${type.name} does not provide it.`,
|
|
373
|
+
[ifaceField.astNode, type.astNode, ...type.extensionASTNodes],
|
|
374
|
+
);
|
|
375
|
+
continue;
|
|
376
|
+
} // Assert interface field type is satisfied by type field type, by being
|
|
377
|
+
// a valid subtype. (covariant)
|
|
378
|
+
|
|
379
|
+
if (
|
|
380
|
+
!(0, _typeComparators.isTypeSubTypeOf)(
|
|
381
|
+
context.schema,
|
|
382
|
+
typeField.type,
|
|
383
|
+
ifaceField.type,
|
|
384
|
+
)
|
|
385
|
+
) {
|
|
386
|
+
var _ifaceField$astNode, _typeField$astNode;
|
|
387
|
+
|
|
388
|
+
context.reportError(
|
|
389
|
+
`Interface field ${iface.name}.${fieldName} expects type ` +
|
|
390
|
+
`${(0, _inspect.inspect)(ifaceField.type)} but ${
|
|
391
|
+
type.name
|
|
392
|
+
}.${fieldName} ` +
|
|
393
|
+
`is type ${(0, _inspect.inspect)(typeField.type)}.`,
|
|
394
|
+
[
|
|
395
|
+
(_ifaceField$astNode = ifaceField.astNode) === null ||
|
|
396
|
+
_ifaceField$astNode === void 0
|
|
397
|
+
? void 0
|
|
398
|
+
: _ifaceField$astNode.type,
|
|
399
|
+
(_typeField$astNode = typeField.astNode) === null ||
|
|
400
|
+
_typeField$astNode === void 0
|
|
401
|
+
? void 0
|
|
402
|
+
: _typeField$astNode.type,
|
|
403
|
+
],
|
|
404
|
+
);
|
|
405
|
+
} // Assert each interface field arg is implemented.
|
|
406
|
+
|
|
407
|
+
for (const ifaceArg of ifaceField.args) {
|
|
408
|
+
const argName = ifaceArg.name;
|
|
409
|
+
const typeArg = typeField.args.find((arg) => arg.name === argName); // Assert interface field arg exists on object field.
|
|
410
|
+
|
|
411
|
+
if (!typeArg) {
|
|
412
|
+
context.reportError(
|
|
413
|
+
`Interface field argument ${iface.name}.${fieldName}(${argName}:) expected but ${type.name}.${fieldName} does not provide it.`,
|
|
414
|
+
[ifaceArg.astNode, typeField.astNode],
|
|
415
|
+
);
|
|
416
|
+
continue;
|
|
417
|
+
} // Assert interface field arg type matches object field arg type.
|
|
418
|
+
// (invariant)
|
|
419
|
+
// TODO: change to contravariant?
|
|
420
|
+
|
|
421
|
+
if (!(0, _typeComparators.isEqualType)(ifaceArg.type, typeArg.type)) {
|
|
422
|
+
var _ifaceArg$astNode, _typeArg$astNode;
|
|
423
|
+
|
|
424
|
+
context.reportError(
|
|
425
|
+
`Interface field argument ${iface.name}.${fieldName}(${argName}:) ` +
|
|
426
|
+
`expects type ${(0, _inspect.inspect)(ifaceArg.type)} but ` +
|
|
427
|
+
`${type.name}.${fieldName}(${argName}:) is type ` +
|
|
428
|
+
`${(0, _inspect.inspect)(typeArg.type)}.`,
|
|
429
|
+
[
|
|
430
|
+
(_ifaceArg$astNode = ifaceArg.astNode) === null ||
|
|
431
|
+
_ifaceArg$astNode === void 0
|
|
432
|
+
? void 0
|
|
433
|
+
: _ifaceArg$astNode.type,
|
|
434
|
+
(_typeArg$astNode = typeArg.astNode) === null ||
|
|
435
|
+
_typeArg$astNode === void 0
|
|
436
|
+
? void 0
|
|
437
|
+
: _typeArg$astNode.type,
|
|
438
|
+
],
|
|
439
|
+
);
|
|
440
|
+
} // TODO: validate default values?
|
|
441
|
+
} // Assert additional arguments must not be required.
|
|
442
|
+
|
|
443
|
+
for (const typeArg of typeField.args) {
|
|
444
|
+
const argName = typeArg.name;
|
|
445
|
+
const ifaceArg = ifaceField.args.find((arg) => arg.name === argName);
|
|
446
|
+
|
|
447
|
+
if (!ifaceArg && (0, _definition.isRequiredArgument)(typeArg)) {
|
|
448
|
+
context.reportError(
|
|
449
|
+
`Object field ${type.name}.${fieldName} includes required argument ${argName} that is missing from the Interface field ${iface.name}.${fieldName}.`,
|
|
450
|
+
[typeArg.astNode, ifaceField.astNode],
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function validateTypeImplementsAncestors(context, type, iface) {
|
|
458
|
+
const ifaceInterfaces = type.getInterfaces();
|
|
459
|
+
|
|
460
|
+
for (const transitive of iface.getInterfaces()) {
|
|
461
|
+
if (!ifaceInterfaces.includes(transitive)) {
|
|
462
|
+
context.reportError(
|
|
463
|
+
transitive === type
|
|
464
|
+
? `Type ${type.name} cannot implement ${iface.name} because it would create a circular reference.`
|
|
465
|
+
: `Type ${type.name} must implement ${transitive.name} because it is implemented by ${iface.name}.`,
|
|
466
|
+
[
|
|
467
|
+
...getAllImplementsInterfaceNodes(iface, transitive),
|
|
468
|
+
...getAllImplementsInterfaceNodes(type, iface),
|
|
469
|
+
],
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function validateUnionMembers(context, union) {
|
|
476
|
+
const memberTypes = union.getTypes();
|
|
477
|
+
|
|
478
|
+
if (memberTypes.length === 0) {
|
|
479
|
+
context.reportError(
|
|
480
|
+
`Union type ${union.name} must define one or more member types.`,
|
|
481
|
+
[union.astNode, ...union.extensionASTNodes],
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const includedTypeNames = Object.create(null);
|
|
486
|
+
|
|
487
|
+
for (const memberType of memberTypes) {
|
|
488
|
+
if (includedTypeNames[memberType.name]) {
|
|
489
|
+
context.reportError(
|
|
490
|
+
`Union type ${union.name} can only include type ${memberType.name} once.`,
|
|
491
|
+
getUnionMemberTypeNodes(union, memberType.name),
|
|
492
|
+
);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
includedTypeNames[memberType.name] = true;
|
|
497
|
+
|
|
498
|
+
if (!(0, _definition.isObjectType)(memberType)) {
|
|
499
|
+
context.reportError(
|
|
500
|
+
`Union type ${union.name} can only include Object types, ` +
|
|
501
|
+
`it cannot include ${(0, _inspect.inspect)(memberType)}.`,
|
|
502
|
+
getUnionMemberTypeNodes(union, String(memberType)),
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function validateEnumValues(context, enumType) {
|
|
509
|
+
const enumValues = enumType.getValues();
|
|
510
|
+
|
|
511
|
+
if (enumValues.length === 0) {
|
|
512
|
+
context.reportError(
|
|
513
|
+
`Enum type ${enumType.name} must define one or more values.`,
|
|
514
|
+
[enumType.astNode, ...enumType.extensionASTNodes],
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
for (const enumValue of enumValues) {
|
|
519
|
+
// Ensure valid name.
|
|
520
|
+
validateName(context, enumValue);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function validateInputFields(context, inputObj) {
|
|
525
|
+
const fields = Object.values(inputObj.getFields());
|
|
526
|
+
|
|
527
|
+
if (fields.length === 0) {
|
|
528
|
+
context.reportError(
|
|
529
|
+
`Input Object type ${inputObj.name} must define one or more fields.`,
|
|
530
|
+
[inputObj.astNode, ...inputObj.extensionASTNodes],
|
|
531
|
+
);
|
|
532
|
+
} // Ensure the arguments are valid
|
|
533
|
+
|
|
534
|
+
for (const field of fields) {
|
|
535
|
+
// Ensure they are named correctly.
|
|
536
|
+
validateName(context, field); // Ensure the type is an input type
|
|
537
|
+
|
|
538
|
+
if (!(0, _definition.isInputType)(field.type)) {
|
|
539
|
+
var _field$astNode2;
|
|
540
|
+
|
|
541
|
+
context.reportError(
|
|
542
|
+
`The type of ${inputObj.name}.${field.name} must be Input Type ` +
|
|
543
|
+
`but got: ${(0, _inspect.inspect)(field.type)}.`,
|
|
544
|
+
(_field$astNode2 = field.astNode) === null || _field$astNode2 === void 0
|
|
545
|
+
? void 0
|
|
546
|
+
: _field$astNode2.type,
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (
|
|
551
|
+
(0, _definition.isRequiredInputField)(field) &&
|
|
552
|
+
field.deprecationReason != null
|
|
553
|
+
) {
|
|
554
|
+
var _field$astNode3;
|
|
555
|
+
|
|
556
|
+
context.reportError(
|
|
557
|
+
`Required input field ${inputObj.name}.${field.name} cannot be deprecated.`,
|
|
558
|
+
[
|
|
559
|
+
getDeprecatedDirectiveNode(field.astNode),
|
|
560
|
+
(_field$astNode3 = field.astNode) === null ||
|
|
561
|
+
_field$astNode3 === void 0
|
|
562
|
+
? void 0
|
|
563
|
+
: _field$astNode3.type,
|
|
564
|
+
],
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function createInputObjectCircularRefsValidator(context) {
|
|
571
|
+
// Modified copy of algorithm from 'src/validation/rules/NoFragmentCycles.js'.
|
|
572
|
+
// Tracks already visited types to maintain O(N) and to ensure that cycles
|
|
573
|
+
// are not redundantly reported.
|
|
574
|
+
const visitedTypes = Object.create(null); // Array of types nodes used to produce meaningful errors
|
|
575
|
+
|
|
576
|
+
const fieldPath = []; // Position in the type path
|
|
577
|
+
|
|
578
|
+
const fieldPathIndexByTypeName = Object.create(null);
|
|
579
|
+
return detectCycleRecursive; // This does a straight-forward DFS to find cycles.
|
|
580
|
+
// It does not terminate when a cycle was found but continues to explore
|
|
581
|
+
// the graph to find all possible cycles.
|
|
582
|
+
|
|
583
|
+
function detectCycleRecursive(inputObj) {
|
|
584
|
+
if (visitedTypes[inputObj.name]) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
visitedTypes[inputObj.name] = true;
|
|
589
|
+
fieldPathIndexByTypeName[inputObj.name] = fieldPath.length;
|
|
590
|
+
const fields = Object.values(inputObj.getFields());
|
|
591
|
+
|
|
592
|
+
for (const field of fields) {
|
|
593
|
+
if (
|
|
594
|
+
(0, _definition.isNonNullType)(field.type) &&
|
|
595
|
+
(0, _definition.isInputObjectType)(field.type.ofType)
|
|
596
|
+
) {
|
|
597
|
+
const fieldType = field.type.ofType;
|
|
598
|
+
const cycleIndex = fieldPathIndexByTypeName[fieldType.name];
|
|
599
|
+
fieldPath.push(field);
|
|
600
|
+
|
|
601
|
+
if (cycleIndex === undefined) {
|
|
602
|
+
detectCycleRecursive(fieldType);
|
|
603
|
+
} else {
|
|
604
|
+
const cyclePath = fieldPath.slice(cycleIndex);
|
|
605
|
+
const pathStr = cyclePath.map((fieldObj) => fieldObj.name).join('.');
|
|
606
|
+
context.reportError(
|
|
607
|
+
`Cannot reference Input Object "${fieldType.name}" within itself through a series of non-null fields: "${pathStr}".`,
|
|
608
|
+
cyclePath.map((fieldObj) => fieldObj.astNode),
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
fieldPath.pop();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
fieldPathIndexByTypeName[inputObj.name] = undefined;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function getAllImplementsInterfaceNodes(type, iface) {
|
|
621
|
+
const { astNode, extensionASTNodes } = type;
|
|
622
|
+
const nodes =
|
|
623
|
+
astNode != null ? [astNode, ...extensionASTNodes] : extensionASTNodes; // FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
624
|
+
|
|
625
|
+
return nodes
|
|
626
|
+
.flatMap((typeNode) => {
|
|
627
|
+
var _typeNode$interfaces;
|
|
628
|
+
|
|
629
|
+
return (
|
|
630
|
+
/* c8 ignore next */
|
|
631
|
+
(_typeNode$interfaces = typeNode.interfaces) !== null &&
|
|
632
|
+
_typeNode$interfaces !== void 0
|
|
633
|
+
? _typeNode$interfaces
|
|
634
|
+
: []
|
|
635
|
+
);
|
|
636
|
+
})
|
|
637
|
+
.filter((ifaceNode) => ifaceNode.name.value === iface.name);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function getUnionMemberTypeNodes(union, typeName) {
|
|
641
|
+
const { astNode, extensionASTNodes } = union;
|
|
642
|
+
const nodes =
|
|
643
|
+
astNode != null ? [astNode, ...extensionASTNodes] : extensionASTNodes; // FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
644
|
+
|
|
645
|
+
return nodes
|
|
646
|
+
.flatMap((unionNode) => {
|
|
647
|
+
var _unionNode$types;
|
|
648
|
+
|
|
649
|
+
return (
|
|
650
|
+
/* c8 ignore next */
|
|
651
|
+
(_unionNode$types = unionNode.types) !== null &&
|
|
652
|
+
_unionNode$types !== void 0
|
|
653
|
+
? _unionNode$types
|
|
654
|
+
: []
|
|
655
|
+
);
|
|
656
|
+
})
|
|
657
|
+
.filter((typeNode) => typeNode.name.value === typeName);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function getDeprecatedDirectiveNode(definitionNode) {
|
|
661
|
+
var _definitionNode$direc;
|
|
662
|
+
|
|
663
|
+
return definitionNode === null || definitionNode === void 0
|
|
664
|
+
? void 0
|
|
665
|
+
: (_definitionNode$direc = definitionNode.directives) === null ||
|
|
666
|
+
_definitionNode$direc === void 0
|
|
667
|
+
? void 0
|
|
668
|
+
: _definitionNode$direc.find(
|
|
669
|
+
(node) =>
|
|
670
|
+
node.name.value === _directives.GraphQLDeprecatedDirective.name,
|
|
671
|
+
);
|
|
672
|
+
}
|