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
|
@@ -0,0 +1,1016 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.assertValidExecutionArguments = assertValidExecutionArguments;
|
|
7
|
+
exports.buildExecutionContext = buildExecutionContext;
|
|
8
|
+
exports.buildResolveInfo = buildResolveInfo;
|
|
9
|
+
exports.defaultTypeResolver = exports.defaultFieldResolver = void 0;
|
|
10
|
+
exports.execute = execute;
|
|
11
|
+
exports.executeSync = executeSync;
|
|
12
|
+
exports.getFieldDef = getFieldDef;
|
|
13
|
+
|
|
14
|
+
var _devAssert = require('../jsutils/devAssert.js');
|
|
15
|
+
|
|
16
|
+
var _inspect = require('../jsutils/inspect.js');
|
|
17
|
+
|
|
18
|
+
var _invariant = require('../jsutils/invariant.js');
|
|
19
|
+
|
|
20
|
+
var _isIterableObject = require('../jsutils/isIterableObject.js');
|
|
21
|
+
|
|
22
|
+
var _isObjectLike = require('../jsutils/isObjectLike.js');
|
|
23
|
+
|
|
24
|
+
var _isPromise = require('../jsutils/isPromise.js');
|
|
25
|
+
|
|
26
|
+
var _memoize = require('../jsutils/memoize3.js');
|
|
27
|
+
|
|
28
|
+
var _Path = require('../jsutils/Path.js');
|
|
29
|
+
|
|
30
|
+
var _promiseForObject = require('../jsutils/promiseForObject.js');
|
|
31
|
+
|
|
32
|
+
var _promiseReduce = require('../jsutils/promiseReduce.js');
|
|
33
|
+
|
|
34
|
+
var _GraphQLError = require('../error/GraphQLError.js');
|
|
35
|
+
|
|
36
|
+
var _locatedError = require('../error/locatedError.js');
|
|
37
|
+
|
|
38
|
+
var _ast = require('../language/ast.js');
|
|
39
|
+
|
|
40
|
+
var _kinds = require('../language/kinds.js');
|
|
41
|
+
|
|
42
|
+
var _definition = require('../type/definition.js');
|
|
43
|
+
|
|
44
|
+
var _introspection = require('../type/introspection.js');
|
|
45
|
+
|
|
46
|
+
var _validate = require('../type/validate.js');
|
|
47
|
+
|
|
48
|
+
var _collectFields = require('./collectFields.js');
|
|
49
|
+
|
|
50
|
+
var _values = require('./values.js');
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A memoized collection of relevant subfields with regard to the return
|
|
54
|
+
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
55
|
+
* saves overhead when resolving lists of values.
|
|
56
|
+
*/
|
|
57
|
+
const collectSubfields = (0, _memoize.memoize3)(
|
|
58
|
+
(exeContext, returnType, fieldNodes) =>
|
|
59
|
+
(0, _collectFields.collectSubfields)(
|
|
60
|
+
exeContext.schema,
|
|
61
|
+
exeContext.fragments,
|
|
62
|
+
exeContext.variableValues,
|
|
63
|
+
returnType,
|
|
64
|
+
fieldNodes,
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
/**
|
|
68
|
+
* Terminology
|
|
69
|
+
*
|
|
70
|
+
* "Definitions" are the generic name for top-level statements in the document.
|
|
71
|
+
* Examples of this include:
|
|
72
|
+
* 1) Operations (such as a query)
|
|
73
|
+
* 2) Fragments
|
|
74
|
+
*
|
|
75
|
+
* "Operations" are a generic name for requests in the document.
|
|
76
|
+
* Examples of this include:
|
|
77
|
+
* 1) query,
|
|
78
|
+
* 2) mutation
|
|
79
|
+
*
|
|
80
|
+
* "Selections" are the definitions that can appear legally and at
|
|
81
|
+
* single level of the query. These include:
|
|
82
|
+
* 1) field references e.g `a`
|
|
83
|
+
* 2) fragment "spreads" e.g. `...c`
|
|
84
|
+
* 3) inline fragment "spreads" e.g. `...on Type { a }`
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Data that must be available at all points during query execution.
|
|
89
|
+
*
|
|
90
|
+
* Namely, schema of the type system that is currently executing,
|
|
91
|
+
* and the fragments defined in the query document
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Implements the "Executing requests" section of the GraphQL specification.
|
|
96
|
+
*
|
|
97
|
+
* Returns either a synchronous ExecutionResult (if all encountered resolvers
|
|
98
|
+
* are synchronous), or a Promise of an ExecutionResult that will eventually be
|
|
99
|
+
* resolved and never rejected.
|
|
100
|
+
*
|
|
101
|
+
* If the arguments to this function do not result in a legal execution context,
|
|
102
|
+
* a GraphQLError will be thrown immediately explaining the invalid input.
|
|
103
|
+
*/
|
|
104
|
+
function execute(args) {
|
|
105
|
+
// Temporary for v15 to v16 migration. Remove in v17
|
|
106
|
+
arguments.length < 2 ||
|
|
107
|
+
(0, _devAssert.devAssert)(
|
|
108
|
+
false,
|
|
109
|
+
'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.',
|
|
110
|
+
);
|
|
111
|
+
const { schema, document, variableValues, rootValue } = args; // If arguments are missing or incorrect, throw an error.
|
|
112
|
+
|
|
113
|
+
assertValidExecutionArguments(schema, document, variableValues); // If a valid execution context cannot be created due to incorrect arguments,
|
|
114
|
+
// a "Response" with only errors is returned.
|
|
115
|
+
|
|
116
|
+
const exeContext = buildExecutionContext(args); // Return early errors if execution context failed.
|
|
117
|
+
|
|
118
|
+
if (!('schema' in exeContext)) {
|
|
119
|
+
return {
|
|
120
|
+
errors: exeContext,
|
|
121
|
+
};
|
|
122
|
+
} // Return a Promise that will eventually resolve to the data described by
|
|
123
|
+
// The "Response" section of the GraphQL specification.
|
|
124
|
+
//
|
|
125
|
+
// If errors are encountered while executing a GraphQL field, only that
|
|
126
|
+
// field and its descendants will be omitted, and sibling fields will still
|
|
127
|
+
// be executed. An execution which encounters errors will still result in a
|
|
128
|
+
// resolved Promise.
|
|
129
|
+
//
|
|
130
|
+
// Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
131
|
+
// at which point we still log the error and null the parent field, which
|
|
132
|
+
// in this case is the entire response.
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const { operation } = exeContext;
|
|
136
|
+
const result = executeOperation(exeContext, operation, rootValue);
|
|
137
|
+
|
|
138
|
+
if ((0, _isPromise.isPromise)(result)) {
|
|
139
|
+
return result.then(
|
|
140
|
+
(data) => buildResponse(data, exeContext.errors),
|
|
141
|
+
(error) => {
|
|
142
|
+
exeContext.errors.push(error);
|
|
143
|
+
return buildResponse(null, exeContext.errors);
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return buildResponse(result, exeContext.errors);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
exeContext.errors.push(error);
|
|
151
|
+
return buildResponse(null, exeContext.errors);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Also implements the "Executing requests" section of the GraphQL specification.
|
|
156
|
+
* However, it guarantees to complete synchronously (or throw an error) assuming
|
|
157
|
+
* that all field resolvers are also synchronous.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
function executeSync(args) {
|
|
161
|
+
const result = execute(args); // Assert that the execution was synchronous.
|
|
162
|
+
|
|
163
|
+
if ((0, _isPromise.isPromise)(result)) {
|
|
164
|
+
throw new Error('GraphQL execution failed to complete synchronously.');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Given a completed execution context and data, build the `{ errors, data }`
|
|
171
|
+
* response defined by the "Response" section of the GraphQL specification.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
function buildResponse(data, errors) {
|
|
175
|
+
return errors.length === 0
|
|
176
|
+
? {
|
|
177
|
+
data,
|
|
178
|
+
}
|
|
179
|
+
: {
|
|
180
|
+
errors,
|
|
181
|
+
data,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Essential assertions before executing to provide developer feedback for
|
|
186
|
+
* improper use of the GraphQL library.
|
|
187
|
+
*
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
function assertValidExecutionArguments(schema, document, rawVariableValues) {
|
|
192
|
+
document || (0, _devAssert.devAssert)(false, 'Must provide document.'); // If the schema used for execution is invalid, throw an error.
|
|
193
|
+
|
|
194
|
+
(0, _validate.assertValidSchema)(schema); // Variables, if provided, must be an object.
|
|
195
|
+
|
|
196
|
+
rawVariableValues == null ||
|
|
197
|
+
(0, _isObjectLike.isObjectLike)(rawVariableValues) ||
|
|
198
|
+
(0, _devAssert.devAssert)(
|
|
199
|
+
false,
|
|
200
|
+
'Variables must be provided as an Object where each property is a variable value. Perhaps look to see if an unparsed JSON string was provided.',
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Constructs a ExecutionContext object from the arguments passed to
|
|
205
|
+
* execute, which we will pass throughout the other execution methods.
|
|
206
|
+
*
|
|
207
|
+
* Throws a GraphQLError if a valid execution context cannot be created.
|
|
208
|
+
*
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
function buildExecutionContext(args) {
|
|
213
|
+
var _definition$name, _operation$variableDe;
|
|
214
|
+
|
|
215
|
+
const {
|
|
216
|
+
schema,
|
|
217
|
+
document,
|
|
218
|
+
rootValue,
|
|
219
|
+
contextValue,
|
|
220
|
+
variableValues: rawVariableValues,
|
|
221
|
+
operationName,
|
|
222
|
+
fieldResolver,
|
|
223
|
+
typeResolver,
|
|
224
|
+
subscribeFieldResolver,
|
|
225
|
+
} = args;
|
|
226
|
+
let operation;
|
|
227
|
+
const fragments = Object.create(null);
|
|
228
|
+
|
|
229
|
+
for (const definition of document.definitions) {
|
|
230
|
+
switch (definition.kind) {
|
|
231
|
+
case _kinds.Kind.OPERATION_DEFINITION:
|
|
232
|
+
if (operationName == null) {
|
|
233
|
+
if (operation !== undefined) {
|
|
234
|
+
return [
|
|
235
|
+
new _GraphQLError.GraphQLError(
|
|
236
|
+
'Must provide operation name if query contains multiple operations.',
|
|
237
|
+
),
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
operation = definition;
|
|
242
|
+
} else if (
|
|
243
|
+
((_definition$name = definition.name) === null ||
|
|
244
|
+
_definition$name === void 0
|
|
245
|
+
? void 0
|
|
246
|
+
: _definition$name.value) === operationName
|
|
247
|
+
) {
|
|
248
|
+
operation = definition;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
break;
|
|
252
|
+
|
|
253
|
+
case _kinds.Kind.FRAGMENT_DEFINITION:
|
|
254
|
+
fragments[definition.name.value] = definition;
|
|
255
|
+
break;
|
|
256
|
+
|
|
257
|
+
default: // ignore non-executable definitions
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!operation) {
|
|
262
|
+
if (operationName != null) {
|
|
263
|
+
return [
|
|
264
|
+
new _GraphQLError.GraphQLError(
|
|
265
|
+
`Unknown operation named "${operationName}".`,
|
|
266
|
+
),
|
|
267
|
+
];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return [new _GraphQLError.GraphQLError('Must provide an operation.')];
|
|
271
|
+
} // FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
272
|
+
|
|
273
|
+
/* c8 ignore next */
|
|
274
|
+
|
|
275
|
+
const variableDefinitions =
|
|
276
|
+
(_operation$variableDe = operation.variableDefinitions) !== null &&
|
|
277
|
+
_operation$variableDe !== void 0
|
|
278
|
+
? _operation$variableDe
|
|
279
|
+
: [];
|
|
280
|
+
const coercedVariableValues = (0, _values.getVariableValues)(
|
|
281
|
+
schema,
|
|
282
|
+
variableDefinitions,
|
|
283
|
+
rawVariableValues !== null && rawVariableValues !== void 0
|
|
284
|
+
? rawVariableValues
|
|
285
|
+
: {},
|
|
286
|
+
{
|
|
287
|
+
maxErrors: 50,
|
|
288
|
+
},
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
if (coercedVariableValues.errors) {
|
|
292
|
+
return coercedVariableValues.errors;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
schema,
|
|
297
|
+
fragments,
|
|
298
|
+
rootValue,
|
|
299
|
+
contextValue,
|
|
300
|
+
operation,
|
|
301
|
+
variableValues: coercedVariableValues.coerced,
|
|
302
|
+
fieldResolver:
|
|
303
|
+
fieldResolver !== null && fieldResolver !== void 0
|
|
304
|
+
? fieldResolver
|
|
305
|
+
: defaultFieldResolver,
|
|
306
|
+
typeResolver:
|
|
307
|
+
typeResolver !== null && typeResolver !== void 0
|
|
308
|
+
? typeResolver
|
|
309
|
+
: defaultTypeResolver,
|
|
310
|
+
subscribeFieldResolver:
|
|
311
|
+
subscribeFieldResolver !== null && subscribeFieldResolver !== void 0
|
|
312
|
+
? subscribeFieldResolver
|
|
313
|
+
: defaultFieldResolver,
|
|
314
|
+
errors: [],
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Implements the "Executing operations" section of the spec.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
function executeOperation(exeContext, operation, rootValue) {
|
|
322
|
+
const rootType = exeContext.schema.getRootType(operation.operation);
|
|
323
|
+
|
|
324
|
+
if (rootType == null) {
|
|
325
|
+
throw new _GraphQLError.GraphQLError(
|
|
326
|
+
`Schema is not configured to execute ${operation.operation} operation.`,
|
|
327
|
+
operation,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const rootFields = (0, _collectFields.collectFields)(
|
|
332
|
+
exeContext.schema,
|
|
333
|
+
exeContext.fragments,
|
|
334
|
+
exeContext.variableValues,
|
|
335
|
+
rootType,
|
|
336
|
+
operation.selectionSet,
|
|
337
|
+
);
|
|
338
|
+
const path = undefined;
|
|
339
|
+
|
|
340
|
+
switch (operation.operation) {
|
|
341
|
+
case _ast.OperationTypeNode.QUERY:
|
|
342
|
+
return executeFields(exeContext, rootType, rootValue, path, rootFields);
|
|
343
|
+
|
|
344
|
+
case _ast.OperationTypeNode.MUTATION:
|
|
345
|
+
return executeFieldsSerially(
|
|
346
|
+
exeContext,
|
|
347
|
+
rootType,
|
|
348
|
+
rootValue,
|
|
349
|
+
path,
|
|
350
|
+
rootFields,
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
case _ast.OperationTypeNode.SUBSCRIPTION:
|
|
354
|
+
// TODO: deprecate `subscribe` and move all logic here
|
|
355
|
+
// Temporary solution until we finish merging execute and subscribe together
|
|
356
|
+
return executeFields(exeContext, rootType, rootValue, path, rootFields);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Implements the "Executing selection sets" section of the spec
|
|
361
|
+
* for fields that must be executed serially.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
function executeFieldsSerially(
|
|
365
|
+
exeContext,
|
|
366
|
+
parentType,
|
|
367
|
+
sourceValue,
|
|
368
|
+
path,
|
|
369
|
+
fields,
|
|
370
|
+
) {
|
|
371
|
+
return (0, _promiseReduce.promiseReduce)(
|
|
372
|
+
fields.entries(),
|
|
373
|
+
(results, [responseName, fieldNodes]) => {
|
|
374
|
+
const fieldPath = (0, _Path.addPath)(path, responseName, parentType.name);
|
|
375
|
+
const result = executeField(
|
|
376
|
+
exeContext,
|
|
377
|
+
parentType,
|
|
378
|
+
sourceValue,
|
|
379
|
+
fieldNodes,
|
|
380
|
+
fieldPath,
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
if (result === undefined) {
|
|
384
|
+
return results;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if ((0, _isPromise.isPromise)(result)) {
|
|
388
|
+
return result.then((resolvedResult) => {
|
|
389
|
+
results[responseName] = resolvedResult;
|
|
390
|
+
return results;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
results[responseName] = result;
|
|
395
|
+
return results;
|
|
396
|
+
},
|
|
397
|
+
Object.create(null),
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Implements the "Executing selection sets" section of the spec
|
|
402
|
+
* for fields that may be executed in parallel.
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
function executeFields(exeContext, parentType, sourceValue, path, fields) {
|
|
406
|
+
const results = Object.create(null);
|
|
407
|
+
let containsPromise = false;
|
|
408
|
+
|
|
409
|
+
for (const [responseName, fieldNodes] of fields.entries()) {
|
|
410
|
+
const fieldPath = (0, _Path.addPath)(path, responseName, parentType.name);
|
|
411
|
+
const result = executeField(
|
|
412
|
+
exeContext,
|
|
413
|
+
parentType,
|
|
414
|
+
sourceValue,
|
|
415
|
+
fieldNodes,
|
|
416
|
+
fieldPath,
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
if (result !== undefined) {
|
|
420
|
+
results[responseName] = result;
|
|
421
|
+
|
|
422
|
+
if ((0, _isPromise.isPromise)(result)) {
|
|
423
|
+
containsPromise = true;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
} // If there are no promises, we can just return the object
|
|
427
|
+
|
|
428
|
+
if (!containsPromise) {
|
|
429
|
+
return results;
|
|
430
|
+
} // Otherwise, results is a map from field name to the result of resolving that
|
|
431
|
+
// field, which is possibly a promise. Return a promise that will return this
|
|
432
|
+
// same map, but with any promises replaced with the values they resolved to.
|
|
433
|
+
|
|
434
|
+
return (0, _promiseForObject.promiseForObject)(results);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Implements the "Executing fields" section of the spec
|
|
438
|
+
* In particular, this function figures out the value that the field returns by
|
|
439
|
+
* calling its resolve function, then calls completeValue to complete promises,
|
|
440
|
+
* serialize scalars, or execute the sub-selection-set for objects.
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
function executeField(exeContext, parentType, source, fieldNodes, path) {
|
|
444
|
+
var _fieldDef$resolve;
|
|
445
|
+
|
|
446
|
+
const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
|
|
447
|
+
|
|
448
|
+
if (!fieldDef) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const returnType = fieldDef.type;
|
|
453
|
+
const resolveFn =
|
|
454
|
+
(_fieldDef$resolve = fieldDef.resolve) !== null &&
|
|
455
|
+
_fieldDef$resolve !== void 0
|
|
456
|
+
? _fieldDef$resolve
|
|
457
|
+
: exeContext.fieldResolver;
|
|
458
|
+
const info = buildResolveInfo(
|
|
459
|
+
exeContext,
|
|
460
|
+
fieldDef,
|
|
461
|
+
fieldNodes,
|
|
462
|
+
parentType,
|
|
463
|
+
path,
|
|
464
|
+
); // Get the resolve function, regardless of if its result is normal or abrupt (error).
|
|
465
|
+
|
|
466
|
+
try {
|
|
467
|
+
// Build a JS object of arguments from the field.arguments AST, using the
|
|
468
|
+
// variables scope to fulfill any variable references.
|
|
469
|
+
// TODO: find a way to memoize, in case this field is within a List type.
|
|
470
|
+
const args = (0, _values.getArgumentValues)(
|
|
471
|
+
fieldDef,
|
|
472
|
+
fieldNodes[0],
|
|
473
|
+
exeContext.variableValues,
|
|
474
|
+
); // The resolve function's optional third argument is a context value that
|
|
475
|
+
// is provided to every resolve function within an execution. It is commonly
|
|
476
|
+
// used to represent an authenticated user, or request-specific caches.
|
|
477
|
+
|
|
478
|
+
const contextValue = exeContext.contextValue;
|
|
479
|
+
const result = resolveFn(source, args, contextValue, info);
|
|
480
|
+
let completed;
|
|
481
|
+
|
|
482
|
+
if ((0, _isPromise.isPromise)(result)) {
|
|
483
|
+
completed = result.then((resolved) =>
|
|
484
|
+
completeValue(exeContext, returnType, fieldNodes, info, path, resolved),
|
|
485
|
+
);
|
|
486
|
+
} else {
|
|
487
|
+
completed = completeValue(
|
|
488
|
+
exeContext,
|
|
489
|
+
returnType,
|
|
490
|
+
fieldNodes,
|
|
491
|
+
info,
|
|
492
|
+
path,
|
|
493
|
+
result,
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if ((0, _isPromise.isPromise)(completed)) {
|
|
498
|
+
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
499
|
+
// to take a second callback for the error case.
|
|
500
|
+
return completed.then(undefined, (rawError) => {
|
|
501
|
+
const error = (0, _locatedError.locatedError)(
|
|
502
|
+
rawError,
|
|
503
|
+
fieldNodes,
|
|
504
|
+
(0, _Path.pathToArray)(path),
|
|
505
|
+
);
|
|
506
|
+
return handleFieldError(error, returnType, exeContext);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return completed;
|
|
511
|
+
} catch (rawError) {
|
|
512
|
+
const error = (0, _locatedError.locatedError)(
|
|
513
|
+
rawError,
|
|
514
|
+
fieldNodes,
|
|
515
|
+
(0, _Path.pathToArray)(path),
|
|
516
|
+
);
|
|
517
|
+
return handleFieldError(error, returnType, exeContext);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* @internal
|
|
522
|
+
*/
|
|
523
|
+
|
|
524
|
+
function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
|
|
525
|
+
// The resolve function's optional fourth argument is a collection of
|
|
526
|
+
// information about the current execution state.
|
|
527
|
+
return {
|
|
528
|
+
fieldName: fieldDef.name,
|
|
529
|
+
fieldNodes,
|
|
530
|
+
returnType: fieldDef.type,
|
|
531
|
+
parentType,
|
|
532
|
+
path,
|
|
533
|
+
schema: exeContext.schema,
|
|
534
|
+
fragments: exeContext.fragments,
|
|
535
|
+
rootValue: exeContext.rootValue,
|
|
536
|
+
operation: exeContext.operation,
|
|
537
|
+
variableValues: exeContext.variableValues,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function handleFieldError(error, returnType, exeContext) {
|
|
542
|
+
// If the field type is non-nullable, then it is resolved without any
|
|
543
|
+
// protection from errors, however it still properly locates the error.
|
|
544
|
+
if ((0, _definition.isNonNullType)(returnType)) {
|
|
545
|
+
throw error;
|
|
546
|
+
} // Otherwise, error protection is applied, logging the error and resolving
|
|
547
|
+
// a null value for this field if one is encountered.
|
|
548
|
+
|
|
549
|
+
exeContext.errors.push(error);
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Implements the instructions for completeValue as defined in the
|
|
554
|
+
* "Value Completion" section of the spec.
|
|
555
|
+
*
|
|
556
|
+
* If the field type is Non-Null, then this recursively completes the value
|
|
557
|
+
* for the inner type. It throws a field error if that completion returns null,
|
|
558
|
+
* as per the "Nullability" section of the spec.
|
|
559
|
+
*
|
|
560
|
+
* If the field type is a List, then this recursively completes the value
|
|
561
|
+
* for the inner type on each item in the list.
|
|
562
|
+
*
|
|
563
|
+
* If the field type is a Scalar or Enum, ensures the completed value is a legal
|
|
564
|
+
* value of the type by calling the `serialize` method of GraphQL type
|
|
565
|
+
* definition.
|
|
566
|
+
*
|
|
567
|
+
* If the field is an abstract type, determine the runtime type of the value
|
|
568
|
+
* and then complete based on that type
|
|
569
|
+
*
|
|
570
|
+
* Otherwise, the field type expects a sub-selection set, and will complete the
|
|
571
|
+
* value by executing all sub-selections.
|
|
572
|
+
*/
|
|
573
|
+
|
|
574
|
+
function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
575
|
+
// If result is an Error, throw a located error.
|
|
576
|
+
if (result instanceof Error) {
|
|
577
|
+
throw result;
|
|
578
|
+
} // If field type is NonNull, complete for inner type, and throw field error
|
|
579
|
+
// if result is null.
|
|
580
|
+
|
|
581
|
+
if ((0, _definition.isNonNullType)(returnType)) {
|
|
582
|
+
const completed = completeValue(
|
|
583
|
+
exeContext,
|
|
584
|
+
returnType.ofType,
|
|
585
|
+
fieldNodes,
|
|
586
|
+
info,
|
|
587
|
+
path,
|
|
588
|
+
result,
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
if (completed === null) {
|
|
592
|
+
throw new Error(
|
|
593
|
+
`Cannot return null for non-nullable field ${info.parentType.name}.${info.fieldName}.`,
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return completed;
|
|
598
|
+
} // If result value is null or undefined then return null.
|
|
599
|
+
|
|
600
|
+
if (result == null) {
|
|
601
|
+
return null;
|
|
602
|
+
} // If field type is List, complete each item in the list with the inner type
|
|
603
|
+
|
|
604
|
+
if ((0, _definition.isListType)(returnType)) {
|
|
605
|
+
return completeListValue(
|
|
606
|
+
exeContext,
|
|
607
|
+
returnType,
|
|
608
|
+
fieldNodes,
|
|
609
|
+
info,
|
|
610
|
+
path,
|
|
611
|
+
result,
|
|
612
|
+
);
|
|
613
|
+
} // If field type is a leaf type, Scalar or Enum, serialize to a valid value,
|
|
614
|
+
// returning null if serialization is not possible.
|
|
615
|
+
|
|
616
|
+
if ((0, _definition.isLeafType)(returnType)) {
|
|
617
|
+
return completeLeafValue(returnType, result);
|
|
618
|
+
} // If field type is an abstract type, Interface or Union, determine the
|
|
619
|
+
// runtime Object type and complete for that type.
|
|
620
|
+
|
|
621
|
+
if ((0, _definition.isAbstractType)(returnType)) {
|
|
622
|
+
return completeAbstractValue(
|
|
623
|
+
exeContext,
|
|
624
|
+
returnType,
|
|
625
|
+
fieldNodes,
|
|
626
|
+
info,
|
|
627
|
+
path,
|
|
628
|
+
result,
|
|
629
|
+
);
|
|
630
|
+
} // If field type is Object, execute and complete all sub-selections.
|
|
631
|
+
|
|
632
|
+
if ((0, _definition.isObjectType)(returnType)) {
|
|
633
|
+
return completeObjectValue(
|
|
634
|
+
exeContext,
|
|
635
|
+
returnType,
|
|
636
|
+
fieldNodes,
|
|
637
|
+
info,
|
|
638
|
+
path,
|
|
639
|
+
result,
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
/* c8 ignore next 6 */
|
|
643
|
+
// Not reachable, all possible output types have been considered.
|
|
644
|
+
|
|
645
|
+
false ||
|
|
646
|
+
(0, _invariant.invariant)(
|
|
647
|
+
false,
|
|
648
|
+
'Cannot complete value of unexpected output type: ' +
|
|
649
|
+
(0, _inspect.inspect)(returnType),
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Complete a list value by completing each item in the list with the
|
|
654
|
+
* inner type
|
|
655
|
+
*/
|
|
656
|
+
|
|
657
|
+
function completeListValue(
|
|
658
|
+
exeContext,
|
|
659
|
+
returnType,
|
|
660
|
+
fieldNodes,
|
|
661
|
+
info,
|
|
662
|
+
path,
|
|
663
|
+
result,
|
|
664
|
+
) {
|
|
665
|
+
if (!(0, _isIterableObject.isIterableObject)(result)) {
|
|
666
|
+
throw new _GraphQLError.GraphQLError(
|
|
667
|
+
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
|
|
668
|
+
);
|
|
669
|
+
} // This is specified as a simple map, however we're optimizing the path
|
|
670
|
+
// where the list contains no Promises by avoiding creating another Promise.
|
|
671
|
+
|
|
672
|
+
const itemType = returnType.ofType;
|
|
673
|
+
let containsPromise = false;
|
|
674
|
+
const completedResults = Array.from(result, (item, index) => {
|
|
675
|
+
// No need to modify the info object containing the path,
|
|
676
|
+
// since from here on it is not ever accessed by resolver functions.
|
|
677
|
+
const itemPath = (0, _Path.addPath)(path, index, undefined);
|
|
678
|
+
|
|
679
|
+
try {
|
|
680
|
+
let completedItem;
|
|
681
|
+
|
|
682
|
+
if ((0, _isPromise.isPromise)(item)) {
|
|
683
|
+
completedItem = item.then((resolved) =>
|
|
684
|
+
completeValue(
|
|
685
|
+
exeContext,
|
|
686
|
+
itemType,
|
|
687
|
+
fieldNodes,
|
|
688
|
+
info,
|
|
689
|
+
itemPath,
|
|
690
|
+
resolved,
|
|
691
|
+
),
|
|
692
|
+
);
|
|
693
|
+
} else {
|
|
694
|
+
completedItem = completeValue(
|
|
695
|
+
exeContext,
|
|
696
|
+
itemType,
|
|
697
|
+
fieldNodes,
|
|
698
|
+
info,
|
|
699
|
+
itemPath,
|
|
700
|
+
item,
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if ((0, _isPromise.isPromise)(completedItem)) {
|
|
705
|
+
containsPromise = true; // Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
706
|
+
// to take a second callback for the error case.
|
|
707
|
+
|
|
708
|
+
return completedItem.then(undefined, (rawError) => {
|
|
709
|
+
const error = (0, _locatedError.locatedError)(
|
|
710
|
+
rawError,
|
|
711
|
+
fieldNodes,
|
|
712
|
+
(0, _Path.pathToArray)(itemPath),
|
|
713
|
+
);
|
|
714
|
+
return handleFieldError(error, itemType, exeContext);
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
return completedItem;
|
|
719
|
+
} catch (rawError) {
|
|
720
|
+
const error = (0, _locatedError.locatedError)(
|
|
721
|
+
rawError,
|
|
722
|
+
fieldNodes,
|
|
723
|
+
(0, _Path.pathToArray)(itemPath),
|
|
724
|
+
);
|
|
725
|
+
return handleFieldError(error, itemType, exeContext);
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Complete a Scalar or Enum by serializing to a valid value, returning
|
|
732
|
+
* null if serialization is not possible.
|
|
733
|
+
*/
|
|
734
|
+
|
|
735
|
+
function completeLeafValue(returnType, result) {
|
|
736
|
+
const serializedResult = returnType.serialize(result);
|
|
737
|
+
|
|
738
|
+
if (serializedResult == null) {
|
|
739
|
+
throw new Error(
|
|
740
|
+
`Expected \`${(0, _inspect.inspect)(returnType)}.serialize(${(0,
|
|
741
|
+
_inspect.inspect)(result)})\` to ` +
|
|
742
|
+
`return non-nullable value, returned: ${(0, _inspect.inspect)(
|
|
743
|
+
serializedResult,
|
|
744
|
+
)}`,
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
return serializedResult;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Complete a value of an abstract type by determining the runtime object type
|
|
752
|
+
* of that value, then complete the value for that type.
|
|
753
|
+
*/
|
|
754
|
+
|
|
755
|
+
function completeAbstractValue(
|
|
756
|
+
exeContext,
|
|
757
|
+
returnType,
|
|
758
|
+
fieldNodes,
|
|
759
|
+
info,
|
|
760
|
+
path,
|
|
761
|
+
result,
|
|
762
|
+
) {
|
|
763
|
+
var _returnType$resolveTy;
|
|
764
|
+
|
|
765
|
+
const resolveTypeFn =
|
|
766
|
+
(_returnType$resolveTy = returnType.resolveType) !== null &&
|
|
767
|
+
_returnType$resolveTy !== void 0
|
|
768
|
+
? _returnType$resolveTy
|
|
769
|
+
: exeContext.typeResolver;
|
|
770
|
+
const contextValue = exeContext.contextValue;
|
|
771
|
+
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
|
|
772
|
+
|
|
773
|
+
if ((0, _isPromise.isPromise)(runtimeType)) {
|
|
774
|
+
return runtimeType.then((resolvedRuntimeType) =>
|
|
775
|
+
completeObjectValue(
|
|
776
|
+
exeContext,
|
|
777
|
+
ensureValidRuntimeType(
|
|
778
|
+
resolvedRuntimeType,
|
|
779
|
+
exeContext,
|
|
780
|
+
returnType,
|
|
781
|
+
fieldNodes,
|
|
782
|
+
info,
|
|
783
|
+
result,
|
|
784
|
+
),
|
|
785
|
+
fieldNodes,
|
|
786
|
+
info,
|
|
787
|
+
path,
|
|
788
|
+
result,
|
|
789
|
+
),
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return completeObjectValue(
|
|
794
|
+
exeContext,
|
|
795
|
+
ensureValidRuntimeType(
|
|
796
|
+
runtimeType,
|
|
797
|
+
exeContext,
|
|
798
|
+
returnType,
|
|
799
|
+
fieldNodes,
|
|
800
|
+
info,
|
|
801
|
+
result,
|
|
802
|
+
),
|
|
803
|
+
fieldNodes,
|
|
804
|
+
info,
|
|
805
|
+
path,
|
|
806
|
+
result,
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
function ensureValidRuntimeType(
|
|
811
|
+
runtimeTypeName,
|
|
812
|
+
exeContext,
|
|
813
|
+
returnType,
|
|
814
|
+
fieldNodes,
|
|
815
|
+
info,
|
|
816
|
+
result,
|
|
817
|
+
) {
|
|
818
|
+
if (runtimeTypeName == null) {
|
|
819
|
+
throw new _GraphQLError.GraphQLError(
|
|
820
|
+
`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}". Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
|
|
821
|
+
fieldNodes,
|
|
822
|
+
);
|
|
823
|
+
} // releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType`
|
|
824
|
+
// TODO: remove in 17.0.0 release
|
|
825
|
+
|
|
826
|
+
if ((0, _definition.isObjectType)(runtimeTypeName)) {
|
|
827
|
+
throw new _GraphQLError.GraphQLError(
|
|
828
|
+
'Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.',
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
if (typeof runtimeTypeName !== 'string') {
|
|
833
|
+
throw new _GraphQLError.GraphQLError(
|
|
834
|
+
`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
|
|
835
|
+
`value ${(0, _inspect.inspect)(result)}, received "${(0,
|
|
836
|
+
_inspect.inspect)(runtimeTypeName)}".`,
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
const runtimeType = exeContext.schema.getType(runtimeTypeName);
|
|
841
|
+
|
|
842
|
+
if (runtimeType == null) {
|
|
843
|
+
throw new _GraphQLError.GraphQLError(
|
|
844
|
+
`Abstract type "${returnType.name}" was resolved to a type "${runtimeTypeName}" that does not exist inside the schema.`,
|
|
845
|
+
fieldNodes,
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
if (!(0, _definition.isObjectType)(runtimeType)) {
|
|
850
|
+
throw new _GraphQLError.GraphQLError(
|
|
851
|
+
`Abstract type "${returnType.name}" was resolved to a non-object type "${runtimeTypeName}".`,
|
|
852
|
+
fieldNodes,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
if (!exeContext.schema.isSubType(returnType, runtimeType)) {
|
|
857
|
+
throw new _GraphQLError.GraphQLError(
|
|
858
|
+
`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`,
|
|
859
|
+
fieldNodes,
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
return runtimeType;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Complete an Object value by executing all sub-selections.
|
|
867
|
+
*/
|
|
868
|
+
|
|
869
|
+
function completeObjectValue(
|
|
870
|
+
exeContext,
|
|
871
|
+
returnType,
|
|
872
|
+
fieldNodes,
|
|
873
|
+
info,
|
|
874
|
+
path,
|
|
875
|
+
result,
|
|
876
|
+
) {
|
|
877
|
+
// Collect sub-fields to execute to complete this value.
|
|
878
|
+
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes); // If there is an isTypeOf predicate function, call it with the
|
|
879
|
+
// current result. If isTypeOf returns false, then raise an error rather
|
|
880
|
+
// than continuing execution.
|
|
881
|
+
|
|
882
|
+
if (returnType.isTypeOf) {
|
|
883
|
+
const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
|
|
884
|
+
|
|
885
|
+
if ((0, _isPromise.isPromise)(isTypeOf)) {
|
|
886
|
+
return isTypeOf.then((resolvedIsTypeOf) => {
|
|
887
|
+
if (!resolvedIsTypeOf) {
|
|
888
|
+
throw invalidReturnTypeError(returnType, result, fieldNodes);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
return executeFields(
|
|
892
|
+
exeContext,
|
|
893
|
+
returnType,
|
|
894
|
+
result,
|
|
895
|
+
path,
|
|
896
|
+
subFieldNodes,
|
|
897
|
+
);
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
if (!isTypeOf) {
|
|
902
|
+
throw invalidReturnTypeError(returnType, result, fieldNodes);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
return executeFields(exeContext, returnType, result, path, subFieldNodes);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
910
|
+
return new _GraphQLError.GraphQLError(
|
|
911
|
+
`Expected value of type "${returnType.name}" but got: ${(0,
|
|
912
|
+
_inspect.inspect)(result)}.`,
|
|
913
|
+
fieldNodes,
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* If a resolveType function is not given, then a default resolve behavior is
|
|
918
|
+
* used which attempts two strategies:
|
|
919
|
+
*
|
|
920
|
+
* First, See if the provided value has a `__typename` field defined, if so, use
|
|
921
|
+
* that value as name of the resolved type.
|
|
922
|
+
*
|
|
923
|
+
* Otherwise, test each possible type for the abstract type by calling
|
|
924
|
+
* isTypeOf for the object being coerced, returning the first type that matches.
|
|
925
|
+
*/
|
|
926
|
+
|
|
927
|
+
const defaultTypeResolver = function (value, contextValue, info, abstractType) {
|
|
928
|
+
// First, look for `__typename`.
|
|
929
|
+
if (
|
|
930
|
+
(0, _isObjectLike.isObjectLike)(value) &&
|
|
931
|
+
typeof value.__typename === 'string'
|
|
932
|
+
) {
|
|
933
|
+
return value.__typename;
|
|
934
|
+
} // Otherwise, test each possible type.
|
|
935
|
+
|
|
936
|
+
const possibleTypes = info.schema.getPossibleTypes(abstractType);
|
|
937
|
+
const promisedIsTypeOfResults = [];
|
|
938
|
+
|
|
939
|
+
for (let i = 0; i < possibleTypes.length; i++) {
|
|
940
|
+
const type = possibleTypes[i];
|
|
941
|
+
|
|
942
|
+
if (type.isTypeOf) {
|
|
943
|
+
const isTypeOfResult = type.isTypeOf(value, contextValue, info);
|
|
944
|
+
|
|
945
|
+
if ((0, _isPromise.isPromise)(isTypeOfResult)) {
|
|
946
|
+
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
947
|
+
} else if (isTypeOfResult) {
|
|
948
|
+
return type.name;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
if (promisedIsTypeOfResults.length) {
|
|
954
|
+
return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
|
|
955
|
+
for (let i = 0; i < isTypeOfResults.length; i++) {
|
|
956
|
+
if (isTypeOfResults[i]) {
|
|
957
|
+
return possibleTypes[i].name;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
/**
|
|
964
|
+
* If a resolve function is not given, then a default resolve behavior is used
|
|
965
|
+
* which takes the property of the source object of the same name as the field
|
|
966
|
+
* and returns it as the result, or if it's a function, returns the result
|
|
967
|
+
* of calling that function while passing along args and context value.
|
|
968
|
+
*/
|
|
969
|
+
|
|
970
|
+
exports.defaultTypeResolver = defaultTypeResolver;
|
|
971
|
+
|
|
972
|
+
const defaultFieldResolver = function (source, args, contextValue, info) {
|
|
973
|
+
// ensure source is a value for which property access is acceptable.
|
|
974
|
+
if ((0, _isObjectLike.isObjectLike)(source) || typeof source === 'function') {
|
|
975
|
+
const property = source[info.fieldName];
|
|
976
|
+
|
|
977
|
+
if (typeof property === 'function') {
|
|
978
|
+
return source[info.fieldName](args, contextValue, info);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
return property;
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
/**
|
|
985
|
+
* This method looks up the field on the given type definition.
|
|
986
|
+
* It has special casing for the three introspection fields,
|
|
987
|
+
* __schema, __type and __typename. __typename is special because
|
|
988
|
+
* it can always be queried as a field, even in situations where no
|
|
989
|
+
* other fields are allowed, like on a Union. __schema and __type
|
|
990
|
+
* could get automatically added to the query type, but that would
|
|
991
|
+
* require mutating type definitions, which would cause issues.
|
|
992
|
+
*
|
|
993
|
+
* @internal
|
|
994
|
+
*/
|
|
995
|
+
|
|
996
|
+
exports.defaultFieldResolver = defaultFieldResolver;
|
|
997
|
+
|
|
998
|
+
function getFieldDef(schema, parentType, fieldNode) {
|
|
999
|
+
const fieldName = fieldNode.name.value;
|
|
1000
|
+
|
|
1001
|
+
if (
|
|
1002
|
+
fieldName === _introspection.SchemaMetaFieldDef.name &&
|
|
1003
|
+
schema.getQueryType() === parentType
|
|
1004
|
+
) {
|
|
1005
|
+
return _introspection.SchemaMetaFieldDef;
|
|
1006
|
+
} else if (
|
|
1007
|
+
fieldName === _introspection.TypeMetaFieldDef.name &&
|
|
1008
|
+
schema.getQueryType() === parentType
|
|
1009
|
+
) {
|
|
1010
|
+
return _introspection.TypeMetaFieldDef;
|
|
1011
|
+
} else if (fieldName === _introspection.TypeNameMetaFieldDef.name) {
|
|
1012
|
+
return _introspection.TypeNameMetaFieldDef;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
return parentType.getFields()[fieldName];
|
|
1016
|
+
}
|