graphql 15.2.0 → 15.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +19 -10
- package/error/GraphQLError.js +8 -8
- package/error/GraphQLError.js.flow +2 -3
- package/error/GraphQLError.mjs +2 -2
- package/error/formatError.js +1 -1
- package/error/formatError.js.flow +0 -1
- package/error/index.js +4 -4
- package/error/index.js.flow +0 -1
- package/error/locatedError.d.ts +2 -2
- package/error/locatedError.js +10 -5
- package/error/locatedError.js.flow +10 -4
- package/error/locatedError.mjs +6 -4
- package/error/syntaxError.js +1 -1
- package/error/syntaxError.js.flow +0 -1
- package/execution/execute.d.ts +11 -15
- package/execution/execute.js +110 -110
- package/execution/execute.js.flow +132 -139
- package/execution/execute.mjs +92 -88
- package/execution/index.d.ts +1 -0
- package/execution/index.js +3 -3
- package/execution/index.js.flow +6 -2
- package/execution/values.js +11 -11
- package/execution/values.js.flow +0 -1
- package/graphql.js +5 -5
- package/graphql.js.flow +0 -1
- package/index.d.ts +2 -0
- package/index.js +9 -9
- package/index.js.flow +5 -2
- package/jsutils/ObjMap.js.flow +0 -1
- package/jsutils/Path.js.flow +0 -1
- package/jsutils/PromiseOrValue.js.flow +0 -1
- package/jsutils/defineInspect.js +2 -2
- package/jsutils/defineInspect.js.flow +0 -1
- package/jsutils/devAssert.js.flow +0 -1
- package/jsutils/didYouMean.js.flow +0 -1
- package/jsutils/identityFunc.js.flow +0 -1
- package/jsutils/inspect.js +1 -2
- package/jsutils/inspect.js.flow +10 -8
- package/jsutils/inspect.mjs +1 -1
- package/jsutils/instanceOf.js.flow +2 -3
- package/jsutils/invariant.js.flow +0 -1
- package/jsutils/isAsyncIterable.js +13 -0
- package/jsutils/isAsyncIterable.js.flow +14 -0
- package/jsutils/isAsyncIterable.mjs +10 -0
- package/jsutils/isObjectLike.js.flow +0 -1
- package/jsutils/isPromise.js.flow +0 -1
- package/jsutils/keyMap.js.flow +0 -1
- package/jsutils/keyValMap.js.flow +0 -1
- package/jsutils/mapValue.js +1 -1
- package/jsutils/mapValue.js.flow +0 -1
- package/jsutils/memoize3.js +2 -5
- package/jsutils/memoize3.js.flow +2 -5
- package/jsutils/memoize3.mjs +2 -5
- package/jsutils/naturalCompare.js +69 -0
- package/jsutils/naturalCompare.js.flow +59 -0
- package/jsutils/naturalCompare.mjs +61 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
- package/jsutils/printPathArray.js.flow +0 -1
- package/jsutils/promiseForObject.js.flow +0 -1
- package/jsutils/promiseReduce.js +1 -1
- package/jsutils/promiseReduce.js.flow +0 -1
- package/jsutils/safeArrayFrom.js +73 -0
- package/jsutils/safeArrayFrom.js.flow +59 -0
- package/jsutils/safeArrayFrom.mjs +66 -0
- package/jsutils/suggestionList.js +5 -1
- package/jsutils/suggestionList.js.flow +3 -2
- package/jsutils/suggestionList.mjs +3 -1
- package/jsutils/toObjMap.js +1 -1
- package/jsutils/toObjMap.js.flow +0 -1
- package/language/ast.js +1 -1
- package/language/ast.js.flow +0 -1
- package/language/blockString.d.ts +1 -1
- package/language/blockString.js +53 -32
- package/language/blockString.js.flow +51 -36
- package/language/blockString.mjs +54 -33
- package/language/directiveLocation.js.flow +0 -1
- package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
- package/language/experimentalOnlineParser/grammar.js +987 -0
- package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
- package/language/experimentalOnlineParser/grammar.mjs +980 -0
- package/language/experimentalOnlineParser/index.d.ts +6 -0
- package/language/experimentalOnlineParser/index.js +31 -0
- package/language/experimentalOnlineParser/index.js.flow +7 -0
- package/language/experimentalOnlineParser/index.mjs +1 -0
- package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
- package/language/experimentalOnlineParser/onlineParser.js +604 -0
- package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
- package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
- package/language/index.js +12 -12
- package/language/index.js.flow +0 -1
- package/language/kinds.js.flow +0 -1
- package/language/lexer.js +242 -183
- package/language/lexer.js.flow +188 -184
- package/language/lexer.mjs +238 -179
- package/language/location.js.flow +0 -1
- package/language/parser.js +73 -68
- package/language/parser.js.flow +62 -57
- package/language/parser.mjs +64 -60
- package/language/predicates.js +1 -1
- package/language/predicates.js.flow +0 -1
- package/language/printLocation.js +1 -1
- package/language/printLocation.js.flow +0 -1
- package/language/printer.js +20 -13
- package/language/printer.js.flow +26 -25
- package/language/printer.mjs +18 -11
- package/language/source.d.ts +12 -6
- package/language/source.js +25 -9
- package/language/source.js.flow +26 -9
- package/language/source.mjs +19 -7
- package/language/tokenKind.js.flow +0 -1
- package/language/visitor.d.ts +3 -3
- package/language/visitor.js +5 -5
- package/language/visitor.js.flow +3 -4
- package/language/visitor.mjs +3 -3
- package/package.json +2 -3
- package/polyfills/arrayFrom.js +2 -2
- package/polyfills/arrayFrom.js.flow +1 -2
- package/polyfills/arrayFrom.mjs +1 -1
- package/polyfills/find.js +1 -1
- package/polyfills/find.js.flow +1 -2
- package/polyfills/find.mjs +1 -1
- package/polyfills/isFinite.js +1 -1
- package/polyfills/isFinite.js.flow +1 -2
- package/polyfills/isFinite.mjs +1 -1
- package/polyfills/isInteger.js +1 -1
- package/polyfills/isInteger.js.flow +1 -2
- package/polyfills/isInteger.mjs +1 -1
- package/polyfills/objectEntries.js +1 -1
- package/polyfills/objectEntries.js.flow +1 -2
- package/polyfills/objectEntries.mjs +1 -1
- package/polyfills/objectValues.js +1 -1
- package/polyfills/objectValues.js.flow +1 -2
- package/polyfills/objectValues.mjs +1 -1
- package/polyfills/symbols.js +3 -5
- package/polyfills/symbols.js.flow +9 -6
- package/polyfills/symbols.mjs +3 -5
- package/subscription/index.js +1 -1
- package/subscription/index.js.flow +0 -1
- package/subscription/mapAsyncIterator.js +2 -2
- package/subscription/mapAsyncIterator.js.flow +8 -9
- package/subscription/mapAsyncIterator.mjs +1 -1
- package/subscription/subscribe.js +61 -73
- package/subscription/subscribe.js.flow +71 -85
- package/subscription/subscribe.mjs +53 -65
- package/type/definition.d.ts +17 -9
- package/type/definition.js +37 -32
- package/type/definition.js.flow +93 -63
- package/type/definition.mjs +19 -14
- package/type/directives.js +17 -16
- package/type/directives.js.flow +20 -13
- package/type/directives.mjs +6 -5
- package/type/index.js +6 -6
- package/type/index.js.flow +0 -1
- package/type/introspection.js +86 -65
- package/type/introspection.js.flow +75 -43
- package/type/introspection.mjs +79 -58
- package/type/scalars.js +9 -9
- package/type/scalars.js.flow +1 -2
- package/type/scalars.mjs +1 -1
- package/type/schema.js +13 -13
- package/type/schema.js.flow +2 -3
- package/type/schema.mjs +1 -1
- package/type/validate.js +52 -19
- package/type/validate.js.flow +54 -8
- package/type/validate.mjs +43 -9
- package/utilities/TypeInfo.js +7 -7
- package/utilities/TypeInfo.js.flow +1 -2
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +0 -1
- package/utilities/astFromValue.js +14 -16
- package/utilities/astFromValue.js.flow +6 -7
- package/utilities/astFromValue.mjs +6 -7
- package/utilities/buildASTSchema.js +17 -27
- package/utilities/buildASTSchema.js.flow +5 -21
- package/utilities/buildASTSchema.mjs +11 -21
- package/utilities/buildClientSchema.js +16 -15
- package/utilities/buildClientSchema.js.flow +28 -12
- package/utilities/buildClientSchema.mjs +5 -4
- package/utilities/coerceInputValue.js +17 -18
- package/utilities/coerceInputValue.js.flow +12 -10
- package/utilities/coerceInputValue.mjs +7 -7
- package/utilities/concatAST.js +9 -8
- package/utilities/concatAST.js.flow +8 -8
- package/utilities/concatAST.mjs +9 -6
- package/utilities/extendSchema.js +26 -19
- package/utilities/extendSchema.js.flow +19 -7
- package/utilities/extendSchema.mjs +8 -1
- package/utilities/findBreakingChanges.js +15 -11
- package/utilities/findBreakingChanges.js.flow +6 -3
- package/utilities/findBreakingChanges.mjs +5 -2
- package/utilities/findDeprecatedUsages.js +2 -2
- package/utilities/findDeprecatedUsages.js.flow +0 -1
- package/utilities/getIntrospectionQuery.d.ts +6 -0
- package/utilities/getIntrospectionQuery.js +8 -2
- package/utilities/getIntrospectionQuery.js.flow +17 -5
- package/utilities/getIntrospectionQuery.mjs +8 -2
- package/utilities/getOperationAST.js +1 -1
- package/utilities/getOperationAST.js.flow +0 -1
- package/utilities/getOperationRootType.js +1 -1
- package/utilities/getOperationRootType.js.flow +0 -1
- package/utilities/index.d.ts +3 -0
- package/utilities/index.js +22 -22
- package/utilities/index.js.flow +0 -1
- package/utilities/introspectionFromSchema.js +7 -5
- package/utilities/introspectionFromSchema.js.flow +2 -1
- package/utilities/introspectionFromSchema.mjs +3 -1
- package/utilities/lexicographicSortSchema.js +13 -9
- package/utilities/lexicographicSortSchema.js.flow +21 -13
- package/utilities/lexicographicSortSchema.mjs +5 -2
- package/utilities/printSchema.js +15 -16
- package/utilities/printSchema.js.flow +23 -16
- package/utilities/printSchema.mjs +5 -6
- package/utilities/separateOperations.js +46 -42
- package/utilities/separateOperations.js.flow +46 -37
- package/utilities/separateOperations.mjs +44 -40
- package/utilities/stripIgnoredCharacters.js +6 -16
- package/utilities/stripIgnoredCharacters.js.flow +4 -13
- package/utilities/stripIgnoredCharacters.mjs +3 -10
- package/utilities/typeComparators.js +1 -1
- package/utilities/typeComparators.js.flow +0 -1
- package/utilities/typeFromAST.js +6 -6
- package/utilities/typeFromAST.js.flow +2 -3
- package/utilities/typeFromAST.mjs +2 -2
- package/utilities/typedQueryDocumentNode.d.ts +20 -0
- package/utilities/valueFromAST.js +6 -6
- package/utilities/valueFromAST.js.flow +4 -2
- package/utilities/valueFromASTUntyped.js +4 -4
- package/utilities/valueFromASTUntyped.js.flow +0 -1
- package/validation/ValidationContext.js +3 -3
- package/validation/ValidationContext.js.flow +3 -4
- package/validation/index.js +38 -38
- package/validation/index.js.flow +0 -1
- package/validation/rules/ExecutableDefinitions.js +1 -1
- package/validation/rules/ExecutableDefinitions.js.flow +0 -1
- package/validation/rules/ExecutableDefinitionsRule.js +3 -3
- package/validation/rules/ExecutableDefinitionsRule.js.flow +0 -1
- package/validation/rules/FieldsOnCorrectTypeRule.js +8 -6
- package/validation/rules/FieldsOnCorrectTypeRule.js.flow +2 -2
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +0 -1
- package/validation/rules/KnownArgumentNamesRule.js +5 -5
- package/validation/rules/KnownArgumentNamesRule.js.flow +1 -1
- package/validation/rules/KnownDirectivesRule.js +6 -6
- package/validation/rules/KnownDirectivesRule.js.flow +4 -3
- package/validation/rules/KnownFragmentNamesRule.js +1 -1
- package/validation/rules/KnownFragmentNamesRule.js.flow +0 -1
- package/validation/rules/KnownTypeNamesRule.js +6 -6
- package/validation/rules/KnownTypeNamesRule.js.flow +1 -2
- package/validation/rules/LoneAnonymousOperationRule.js +2 -2
- package/validation/rules/LoneAnonymousOperationRule.js.flow +0 -1
- package/validation/rules/LoneSchemaDefinition.js +1 -1
- package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
- package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
- package/validation/rules/LoneSchemaDefinitionRule.js.flow +0 -1
- package/validation/rules/NoFragmentCyclesRule.js +1 -1
- package/validation/rules/NoFragmentCyclesRule.js.flow +1 -2
- package/validation/rules/NoUndefinedVariablesRule.js +1 -1
- package/validation/rules/NoUndefinedVariablesRule.js.flow +0 -1
- package/validation/rules/NoUnusedFragmentsRule.js +1 -1
- package/validation/rules/NoUnusedFragmentsRule.js.flow +0 -1
- package/validation/rules/NoUnusedVariablesRule.js +1 -1
- package/validation/rules/NoUnusedVariablesRule.js.flow +0 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +14 -14
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
- package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
- package/validation/rules/PossibleFragmentSpreadsRule.js.flow +5 -2
- package/validation/rules/PossibleTypeExtensions.js +1 -1
- package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
- package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
- package/validation/rules/PossibleTypeExtensionsRule.js.flow +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
- package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +4 -3
- package/validation/rules/ScalarLeafsRule.js +3 -3
- package/validation/rules/ScalarLeafsRule.js.flow +0 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js.flow +0 -1
- package/validation/rules/UniqueArgumentNamesRule.js +1 -1
- package/validation/rules/UniqueArgumentNamesRule.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNames.js +1 -1
- package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.js +2 -2
- package/validation/rules/UniqueDirectiveNamesRule.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.mjs +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +0 -1
- package/validation/rules/UniqueEnumValueNames.js +1 -1
- package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
- package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
- package/validation/rules/UniqueEnumValueNamesRule.js.flow +7 -2
- package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
- package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +13 -4
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js.flow +0 -1
- package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.js.flow +0 -1
- package/validation/rules/UniqueOperationNamesRule.js +1 -1
- package/validation/rules/UniqueOperationNamesRule.js.flow +0 -1
- package/validation/rules/UniqueOperationTypes.js +1 -1
- package/validation/rules/UniqueOperationTypes.js.flow +0 -1
- package/validation/rules/UniqueOperationTypesRule.js +1 -1
- package/validation/rules/UniqueOperationTypesRule.js.flow +7 -2
- package/validation/rules/UniqueTypeNames.js +1 -1
- package/validation/rules/UniqueTypeNames.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.js +2 -2
- package/validation/rules/UniqueTypeNamesRule.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.mjs +1 -1
- package/validation/rules/UniqueVariableNamesRule.js +1 -1
- package/validation/rules/UniqueVariableNamesRule.js.flow +0 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
- package/validation/rules/ValuesOfCorrectTypeRule.js.flow +0 -1
- package/validation/rules/VariablesAreInputTypesRule.js +4 -4
- package/validation/rules/VariablesAreInputTypesRule.js.flow +0 -1
- package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
- package/validation/rules/VariablesInAllowedPositionRule.js.flow +0 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.js +47 -9
- package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +56 -13
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +43 -8
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +3 -3
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +0 -1
- package/validation/specifiedRules.js +33 -33
- package/validation/specifiedRules.js.flow +0 -1
- package/validation/validate.js +7 -7
- package/validation/validate.js.flow +4 -5
- package/version.js +2 -2
- package/version.js.flow +2 -3
- package/version.mjs +2 -2
- package/jsutils/isCollection.js +0 -47
- package/jsutils/isCollection.js.flow +0 -39
- package/jsutils/isCollection.mjs +0 -40
- package/polyfills/flatMap.js +0 -30
- package/polyfills/flatMap.js.flow +0 -28
- package/polyfills/flatMap.mjs +0 -23
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// @flow strict
|
|
2
|
-
|
|
3
|
-
import arrayFrom from '../polyfills/arrayFrom';
|
|
4
|
-
|
|
5
2
|
import type { Path } from '../jsutils/Path';
|
|
6
3
|
import type { ObjMap } from '../jsutils/ObjMap';
|
|
7
4
|
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
|
|
@@ -11,11 +8,12 @@ import invariant from '../jsutils/invariant';
|
|
|
11
8
|
import devAssert from '../jsutils/devAssert';
|
|
12
9
|
import isPromise from '../jsutils/isPromise';
|
|
13
10
|
import isObjectLike from '../jsutils/isObjectLike';
|
|
14
|
-
import
|
|
11
|
+
import safeArrayFrom from '../jsutils/safeArrayFrom';
|
|
15
12
|
import promiseReduce from '../jsutils/promiseReduce';
|
|
16
13
|
import promiseForObject from '../jsutils/promiseForObject';
|
|
17
14
|
import { addPath, pathToArray } from '../jsutils/Path';
|
|
18
15
|
|
|
16
|
+
import type { GraphQLFormattedError } from '../error/formatError';
|
|
19
17
|
import { GraphQLError } from '../error/GraphQLError';
|
|
20
18
|
import { locatedError } from '../error/locatedError';
|
|
21
19
|
|
|
@@ -53,6 +51,7 @@ import {
|
|
|
53
51
|
GraphQLSkipDirective,
|
|
54
52
|
} from '../type/directives';
|
|
55
53
|
import {
|
|
54
|
+
isNamedType,
|
|
56
55
|
isObjectType,
|
|
57
56
|
isAbstractType,
|
|
58
57
|
isLeafType,
|
|
@@ -120,6 +119,12 @@ export type ExecutionResult = {|
|
|
|
120
119
|
extensions?: ObjMap<mixed>,
|
|
121
120
|
|};
|
|
122
121
|
|
|
122
|
+
export type FormattedExecutionResult = {|
|
|
123
|
+
errors?: $ReadOnlyArray<GraphQLFormattedError>,
|
|
124
|
+
data?: ObjMap<mixed> | null,
|
|
125
|
+
extensions?: ObjMap<mixed>,
|
|
126
|
+
|};
|
|
127
|
+
|
|
123
128
|
export type ExecutionArgs = {|
|
|
124
129
|
schema: GraphQLSchema,
|
|
125
130
|
document: DocumentNode,
|
|
@@ -381,8 +386,6 @@ function executeOperation(
|
|
|
381
386
|
// Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
382
387
|
// at which point we still log the error and null the parent field, which
|
|
383
388
|
// in this case is the entire response.
|
|
384
|
-
//
|
|
385
|
-
// Similar to completeValueCatchingError.
|
|
386
389
|
try {
|
|
387
390
|
const result =
|
|
388
391
|
operation.operation === 'mutation'
|
|
@@ -467,7 +470,7 @@ function executeFields(
|
|
|
467
470
|
|
|
468
471
|
if (result !== undefined) {
|
|
469
472
|
results[responseName] = result;
|
|
470
|
-
if (
|
|
473
|
+
if (isPromise(result)) {
|
|
471
474
|
containsPromise = true;
|
|
472
475
|
}
|
|
473
476
|
}
|
|
@@ -638,6 +641,7 @@ function resolveField(
|
|
|
638
641
|
return;
|
|
639
642
|
}
|
|
640
643
|
|
|
644
|
+
const returnType = fieldDef.type;
|
|
641
645
|
const resolveFn = fieldDef.resolve ?? exeContext.fieldResolver;
|
|
642
646
|
|
|
643
647
|
const info = buildResolveInfo(
|
|
@@ -648,67 +652,7 @@ function resolveField(
|
|
|
648
652
|
path,
|
|
649
653
|
);
|
|
650
654
|
|
|
651
|
-
// Get the resolve function, regardless of if its result is normal
|
|
652
|
-
// or abrupt (error).
|
|
653
|
-
const result = resolveFieldValueOrError(
|
|
654
|
-
exeContext,
|
|
655
|
-
fieldDef,
|
|
656
|
-
fieldNodes,
|
|
657
|
-
resolveFn,
|
|
658
|
-
source,
|
|
659
|
-
info,
|
|
660
|
-
);
|
|
661
|
-
|
|
662
|
-
return completeValueCatchingError(
|
|
663
|
-
exeContext,
|
|
664
|
-
fieldDef.type,
|
|
665
|
-
fieldNodes,
|
|
666
|
-
info,
|
|
667
|
-
path,
|
|
668
|
-
result,
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* @internal
|
|
674
|
-
*/
|
|
675
|
-
export function buildResolveInfo(
|
|
676
|
-
exeContext: ExecutionContext,
|
|
677
|
-
fieldDef: GraphQLField<mixed, mixed>,
|
|
678
|
-
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
679
|
-
parentType: GraphQLObjectType,
|
|
680
|
-
path: Path,
|
|
681
|
-
): GraphQLResolveInfo {
|
|
682
|
-
// The resolve function's optional fourth argument is a collection of
|
|
683
|
-
// information about the current execution state.
|
|
684
|
-
return {
|
|
685
|
-
fieldName: fieldDef.name,
|
|
686
|
-
fieldNodes,
|
|
687
|
-
returnType: fieldDef.type,
|
|
688
|
-
parentType,
|
|
689
|
-
path,
|
|
690
|
-
schema: exeContext.schema,
|
|
691
|
-
fragments: exeContext.fragments,
|
|
692
|
-
rootValue: exeContext.rootValue,
|
|
693
|
-
operation: exeContext.operation,
|
|
694
|
-
variableValues: exeContext.variableValues,
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
* Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
|
|
700
|
-
* function. Returns the result of resolveFn or the abrupt-return Error object.
|
|
701
|
-
*
|
|
702
|
-
* @internal
|
|
703
|
-
*/
|
|
704
|
-
export function resolveFieldValueOrError(
|
|
705
|
-
exeContext: ExecutionContext,
|
|
706
|
-
fieldDef: GraphQLField<mixed, mixed>,
|
|
707
|
-
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
708
|
-
resolveFn: GraphQLFieldResolver<mixed, mixed>,
|
|
709
|
-
source: mixed,
|
|
710
|
-
info: GraphQLResolveInfo,
|
|
711
|
-
): Error | mixed {
|
|
655
|
+
// Get the resolve function, regardless of if its result is normal or abrupt (error).
|
|
712
656
|
try {
|
|
713
657
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
714
658
|
// variables scope to fulfill any variable references.
|
|
@@ -725,32 +669,7 @@ export function resolveFieldValueOrError(
|
|
|
725
669
|
const contextValue = exeContext.contextValue;
|
|
726
670
|
|
|
727
671
|
const result = resolveFn(source, args, contextValue, info);
|
|
728
|
-
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
|
|
729
|
-
} catch (error) {
|
|
730
|
-
return asErrorInstance(error);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
// Sometimes a non-error is thrown, wrap it as an Error instance to ensure a
|
|
735
|
-
// consistent Error interface.
|
|
736
|
-
function asErrorInstance(error: mixed): Error {
|
|
737
|
-
if (error instanceof Error) {
|
|
738
|
-
return error;
|
|
739
|
-
}
|
|
740
|
-
return new Error('Unexpected error value: ' + inspect(error));
|
|
741
|
-
}
|
|
742
672
|
|
|
743
|
-
// This is a small wrapper around completeValue which detects and logs errors
|
|
744
|
-
// in the execution context.
|
|
745
|
-
function completeValueCatchingError(
|
|
746
|
-
exeContext: ExecutionContext,
|
|
747
|
-
returnType: GraphQLOutputType,
|
|
748
|
-
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
749
|
-
info: GraphQLResolveInfo,
|
|
750
|
-
path: Path,
|
|
751
|
-
result: mixed,
|
|
752
|
-
): PromiseOrValue<mixed> {
|
|
753
|
-
try {
|
|
754
673
|
let completed;
|
|
755
674
|
if (isPromise(result)) {
|
|
756
675
|
completed = result.then((resolved) =>
|
|
@@ -770,23 +689,49 @@ function completeValueCatchingError(
|
|
|
770
689
|
if (isPromise(completed)) {
|
|
771
690
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
772
691
|
// to take a second callback for the error case.
|
|
773
|
-
return completed.then(undefined, (
|
|
774
|
-
|
|
775
|
-
|
|
692
|
+
return completed.then(undefined, (rawError) => {
|
|
693
|
+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
|
|
694
|
+
return handleFieldError(error, returnType, exeContext);
|
|
695
|
+
});
|
|
776
696
|
}
|
|
777
697
|
return completed;
|
|
778
|
-
} catch (
|
|
779
|
-
|
|
698
|
+
} catch (rawError) {
|
|
699
|
+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
|
|
700
|
+
return handleFieldError(error, returnType, exeContext);
|
|
780
701
|
}
|
|
781
702
|
}
|
|
782
703
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
704
|
+
/**
|
|
705
|
+
* @internal
|
|
706
|
+
*/
|
|
707
|
+
export function buildResolveInfo(
|
|
708
|
+
exeContext: ExecutionContext,
|
|
709
|
+
fieldDef: GraphQLField<mixed, mixed>,
|
|
710
|
+
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
711
|
+
parentType: GraphQLObjectType,
|
|
712
|
+
path: Path,
|
|
713
|
+
): GraphQLResolveInfo {
|
|
714
|
+
// The resolve function's optional fourth argument is a collection of
|
|
715
|
+
// information about the current execution state.
|
|
716
|
+
return {
|
|
717
|
+
fieldName: fieldDef.name,
|
|
786
718
|
fieldNodes,
|
|
787
|
-
|
|
788
|
-
|
|
719
|
+
returnType: fieldDef.type,
|
|
720
|
+
parentType,
|
|
721
|
+
path,
|
|
722
|
+
schema: exeContext.schema,
|
|
723
|
+
fragments: exeContext.fragments,
|
|
724
|
+
rootValue: exeContext.rootValue,
|
|
725
|
+
operation: exeContext.operation,
|
|
726
|
+
variableValues: exeContext.variableValues,
|
|
727
|
+
};
|
|
728
|
+
}
|
|
789
729
|
|
|
730
|
+
function handleFieldError(
|
|
731
|
+
error: GraphQLError,
|
|
732
|
+
returnType: GraphQLOutputType,
|
|
733
|
+
exeContext: ExecutionContext,
|
|
734
|
+
): null {
|
|
790
735
|
// If the field type is non-nullable, then it is resolved without any
|
|
791
736
|
// protection from errors, however it still properly locates the error.
|
|
792
737
|
if (isNonNullType(returnType)) {
|
|
@@ -921,36 +866,64 @@ function completeListValue(
|
|
|
921
866
|
path: Path,
|
|
922
867
|
result: mixed,
|
|
923
868
|
): PromiseOrValue<$ReadOnlyArray<mixed>> {
|
|
924
|
-
if (!isCollection(result)) {
|
|
925
|
-
throw new GraphQLError(
|
|
926
|
-
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
|
|
927
|
-
);
|
|
928
|
-
}
|
|
929
|
-
|
|
930
869
|
// This is specified as a simple map, however we're optimizing the path
|
|
931
870
|
// where the list contains no Promises by avoiding creating another Promise.
|
|
932
871
|
const itemType = returnType.ofType;
|
|
933
872
|
let containsPromise = false;
|
|
934
|
-
const completedResults =
|
|
873
|
+
const completedResults = safeArrayFrom(result, (item, index) => {
|
|
935
874
|
// No need to modify the info object containing the path,
|
|
936
875
|
// since from here on it is not ever accessed by resolver functions.
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
876
|
+
const itemPath = addPath(path, index, undefined);
|
|
877
|
+
try {
|
|
878
|
+
let completedItem;
|
|
879
|
+
if (isPromise(item)) {
|
|
880
|
+
completedItem = item.then((resolved) =>
|
|
881
|
+
completeValue(
|
|
882
|
+
exeContext,
|
|
883
|
+
itemType,
|
|
884
|
+
fieldNodes,
|
|
885
|
+
info,
|
|
886
|
+
itemPath,
|
|
887
|
+
resolved,
|
|
888
|
+
),
|
|
889
|
+
);
|
|
890
|
+
} else {
|
|
891
|
+
completedItem = completeValue(
|
|
892
|
+
exeContext,
|
|
893
|
+
itemType,
|
|
894
|
+
fieldNodes,
|
|
895
|
+
info,
|
|
896
|
+
itemPath,
|
|
897
|
+
item,
|
|
898
|
+
);
|
|
899
|
+
}
|
|
946
900
|
|
|
947
|
-
|
|
948
|
-
|
|
901
|
+
if (isPromise(completedItem)) {
|
|
902
|
+
containsPromise = true;
|
|
903
|
+
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
904
|
+
// to take a second callback for the error case.
|
|
905
|
+
return completedItem.then(undefined, (rawError) => {
|
|
906
|
+
const error = locatedError(
|
|
907
|
+
rawError,
|
|
908
|
+
fieldNodes,
|
|
909
|
+
pathToArray(itemPath),
|
|
910
|
+
);
|
|
911
|
+
return handleFieldError(error, itemType, exeContext);
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
return completedItem;
|
|
915
|
+
} catch (rawError) {
|
|
916
|
+
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
|
|
917
|
+
return handleFieldError(error, itemType, exeContext);
|
|
949
918
|
}
|
|
950
|
-
|
|
951
|
-
return completedItem;
|
|
952
919
|
});
|
|
953
920
|
|
|
921
|
+
if (completedResults == null) {
|
|
922
|
+
throw new GraphQLError(
|
|
923
|
+
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
|
|
954
927
|
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
955
928
|
}
|
|
956
929
|
|
|
@@ -1023,23 +996,43 @@ function completeAbstractValue(
|
|
|
1023
996
|
}
|
|
1024
997
|
|
|
1025
998
|
function ensureValidRuntimeType(
|
|
1026
|
-
runtimeTypeOrName:
|
|
999
|
+
runtimeTypeOrName: mixed,
|
|
1027
1000
|
exeContext: ExecutionContext,
|
|
1028
1001
|
returnType: GraphQLAbstractType,
|
|
1029
1002
|
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
1030
1003
|
info: GraphQLResolveInfo,
|
|
1031
1004
|
result: mixed,
|
|
1032
1005
|
): GraphQLObjectType {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1006
|
+
if (runtimeTypeOrName == null) {
|
|
1007
|
+
throw new GraphQLError(
|
|
1008
|
+
`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.`,
|
|
1009
|
+
fieldNodes,
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1037
1012
|
|
|
1038
|
-
|
|
1013
|
+
// FIXME: temporary workaround until support for passing object types would be removed in v16.0.0
|
|
1014
|
+
const runtimeTypeName = isNamedType(runtimeTypeOrName)
|
|
1015
|
+
? runtimeTypeOrName.name
|
|
1016
|
+
: runtimeTypeOrName;
|
|
1017
|
+
|
|
1018
|
+
if (typeof runtimeTypeName !== 'string') {
|
|
1039
1019
|
throw new GraphQLError(
|
|
1040
1020
|
`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
|
|
1041
|
-
`value ${inspect(result)}, received "${inspect(
|
|
1042
|
-
|
|
1021
|
+
`value ${inspect(result)}, received "${inspect(runtimeTypeOrName)}".`,
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
const runtimeType = exeContext.schema.getType(runtimeTypeName);
|
|
1026
|
+
if (runtimeType == null) {
|
|
1027
|
+
throw new GraphQLError(
|
|
1028
|
+
`Abstract type "${returnType.name}" was resolve to a type "${runtimeTypeName}" that does not exist inside schema.`,
|
|
1029
|
+
fieldNodes,
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (!isObjectType(runtimeType)) {
|
|
1034
|
+
throw new GraphQLError(
|
|
1035
|
+
`Abstract type "${returnType.name}" was resolve to a non-object type "${runtimeTypeName}".`,
|
|
1043
1036
|
fieldNodes,
|
|
1044
1037
|
);
|
|
1045
1038
|
}
|
|
@@ -1184,7 +1177,7 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
|
|
|
1184
1177
|
if (isPromise(isTypeOfResult)) {
|
|
1185
1178
|
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
1186
1179
|
} else if (isTypeOfResult) {
|
|
1187
|
-
return type;
|
|
1180
|
+
return type.name;
|
|
1188
1181
|
}
|
|
1189
1182
|
}
|
|
1190
1183
|
}
|
|
@@ -1193,7 +1186,7 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
|
|
|
1193
1186
|
return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
|
|
1194
1187
|
for (let i = 0; i < isTypeOfResults.length; i++) {
|
|
1195
1188
|
if (isTypeOfResults[i]) {
|
|
1196
|
-
return possibleTypes[i];
|
|
1189
|
+
return possibleTypes[i].name;
|
|
1197
1190
|
}
|
|
1198
1191
|
}
|
|
1199
1192
|
});
|
|
@@ -1222,12 +1215,12 @@ export const defaultFieldResolver: GraphQLFieldResolver<
|
|
|
1222
1215
|
|
|
1223
1216
|
/**
|
|
1224
1217
|
* This method looks up the field on the given type definition.
|
|
1225
|
-
* It has special casing for the
|
|
1226
|
-
* and __typename. __typename is special because
|
|
1227
|
-
* queried as a field, even in situations where no
|
|
1228
|
-
* are allowed, like on a Union. __schema
|
|
1229
|
-
* added to the query type, but that would
|
|
1230
|
-
* definitions, which would cause issues.
|
|
1218
|
+
* It has special casing for the three introspection fields,
|
|
1219
|
+
* __schema, __type and __typename. __typename is special because
|
|
1220
|
+
* it can always be queried as a field, even in situations where no
|
|
1221
|
+
* other fields are allowed, like on a Union. __schema and __type
|
|
1222
|
+
* could get automatically added to the query type, but that would
|
|
1223
|
+
* require mutating type definitions, which would cause issues.
|
|
1231
1224
|
*
|
|
1232
1225
|
* @internal
|
|
1233
1226
|
*/
|
package/execution/execute.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import arrayFrom from "../polyfills/arrayFrom.mjs";
|
|
2
1
|
import inspect from "../jsutils/inspect.mjs";
|
|
3
2
|
import memoize3 from "../jsutils/memoize3.mjs";
|
|
4
3
|
import invariant from "../jsutils/invariant.mjs";
|
|
5
4
|
import devAssert from "../jsutils/devAssert.mjs";
|
|
6
5
|
import isPromise from "../jsutils/isPromise.mjs";
|
|
7
6
|
import isObjectLike from "../jsutils/isObjectLike.mjs";
|
|
8
|
-
import
|
|
7
|
+
import safeArrayFrom from "../jsutils/safeArrayFrom.mjs";
|
|
9
8
|
import promiseReduce from "../jsutils/promiseReduce.mjs";
|
|
10
9
|
import promiseForObject from "../jsutils/promiseForObject.mjs";
|
|
11
10
|
import { addPath, pathToArray } from "../jsutils/Path.mjs";
|
|
@@ -15,7 +14,7 @@ import { Kind } from "../language/kinds.mjs";
|
|
|
15
14
|
import { assertValidSchema } from "../type/validate.mjs";
|
|
16
15
|
import { SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef } from "../type/introspection.mjs";
|
|
17
16
|
import { GraphQLIncludeDirective, GraphQLSkipDirective } from "../type/directives.mjs";
|
|
18
|
-
import { isObjectType, isAbstractType, isLeafType, isListType, isNonNullType } from "../type/definition.mjs";
|
|
17
|
+
import { isNamedType, isObjectType, isAbstractType, isLeafType, isListType, isNonNullType } from "../type/definition.mjs";
|
|
19
18
|
import { typeFromAST } from "../utilities/typeFromAST.mjs";
|
|
20
19
|
import { getOperationRootType } from "../utilities/getOperationRootType.mjs";
|
|
21
20
|
import { getVariableValues, getArgumentValues, getDirectiveValues } from "./values.mjs";
|
|
@@ -220,8 +219,6 @@ function executeOperation(exeContext, operation, rootValue) {
|
|
|
220
219
|
var path = undefined; // Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
221
220
|
// at which point we still log the error and null the parent field, which
|
|
222
221
|
// in this case is the entire response.
|
|
223
|
-
//
|
|
224
|
-
// Similar to completeValueCatchingError.
|
|
225
222
|
|
|
226
223
|
try {
|
|
227
224
|
var result = operation.operation === 'mutation' ? executeFieldsSerially(exeContext, type, rootValue, path, fields) : executeFields(exeContext, type, rootValue, path, fields);
|
|
@@ -285,7 +282,7 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
|
|
|
285
282
|
if (result !== undefined) {
|
|
286
283
|
results[responseName] = result;
|
|
287
284
|
|
|
288
|
-
if (
|
|
285
|
+
if (isPromise(result)) {
|
|
289
286
|
containsPromise = true;
|
|
290
287
|
}
|
|
291
288
|
}
|
|
@@ -438,42 +435,10 @@ function resolveField(exeContext, parentType, source, fieldNodes, path) {
|
|
|
438
435
|
return;
|
|
439
436
|
}
|
|
440
437
|
|
|
438
|
+
var returnType = fieldDef.type;
|
|
441
439
|
var resolveFn = (_fieldDef$resolve = fieldDef.resolve) !== null && _fieldDef$resolve !== void 0 ? _fieldDef$resolve : exeContext.fieldResolver;
|
|
442
|
-
var info = buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path); // Get the resolve function, regardless of if its result is normal
|
|
443
|
-
// or abrupt (error).
|
|
444
|
-
|
|
445
|
-
var result = resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resolveFn, source, info);
|
|
446
|
-
return completeValueCatchingError(exeContext, fieldDef.type, fieldNodes, info, path, result);
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* @internal
|
|
450
|
-
*/
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
export function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
|
|
454
|
-
// The resolve function's optional fourth argument is a collection of
|
|
455
|
-
// information about the current execution state.
|
|
456
|
-
return {
|
|
457
|
-
fieldName: fieldDef.name,
|
|
458
|
-
fieldNodes: fieldNodes,
|
|
459
|
-
returnType: fieldDef.type,
|
|
460
|
-
parentType: parentType,
|
|
461
|
-
path: path,
|
|
462
|
-
schema: exeContext.schema,
|
|
463
|
-
fragments: exeContext.fragments,
|
|
464
|
-
rootValue: exeContext.rootValue,
|
|
465
|
-
operation: exeContext.operation,
|
|
466
|
-
variableValues: exeContext.variableValues
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
|
|
471
|
-
* function. Returns the result of resolveFn or the abrupt-return Error object.
|
|
472
|
-
*
|
|
473
|
-
* @internal
|
|
474
|
-
*/
|
|
440
|
+
var info = buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path); // Get the resolve function, regardless of if its result is normal or abrupt (error).
|
|
475
441
|
|
|
476
|
-
export function resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resolveFn, source, info) {
|
|
477
442
|
try {
|
|
478
443
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
479
444
|
// variables scope to fulfill any variable references.
|
|
@@ -484,25 +449,6 @@ export function resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resol
|
|
|
484
449
|
|
|
485
450
|
var _contextValue = exeContext.contextValue;
|
|
486
451
|
var result = resolveFn(source, args, _contextValue, info);
|
|
487
|
-
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
|
|
488
|
-
} catch (error) {
|
|
489
|
-
return asErrorInstance(error);
|
|
490
|
-
}
|
|
491
|
-
} // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a
|
|
492
|
-
// consistent Error interface.
|
|
493
|
-
|
|
494
|
-
function asErrorInstance(error) {
|
|
495
|
-
if (error instanceof Error) {
|
|
496
|
-
return error;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
return new Error('Unexpected error value: ' + inspect(error));
|
|
500
|
-
} // This is a small wrapper around completeValue which detects and logs errors
|
|
501
|
-
// in the execution context.
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
function completeValueCatchingError(exeContext, returnType, fieldNodes, info, path, result) {
|
|
505
|
-
try {
|
|
506
452
|
var completed;
|
|
507
453
|
|
|
508
454
|
if (isPromise(result)) {
|
|
@@ -516,21 +462,43 @@ function completeValueCatchingError(exeContext, returnType, fieldNodes, info, pa
|
|
|
516
462
|
if (isPromise(completed)) {
|
|
517
463
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
518
464
|
// to take a second callback for the error case.
|
|
519
|
-
return completed.then(undefined, function (
|
|
520
|
-
|
|
465
|
+
return completed.then(undefined, function (rawError) {
|
|
466
|
+
var error = locatedError(rawError, fieldNodes, pathToArray(path));
|
|
467
|
+
return handleFieldError(error, returnType, exeContext);
|
|
521
468
|
});
|
|
522
469
|
}
|
|
523
470
|
|
|
524
471
|
return completed;
|
|
525
|
-
} catch (
|
|
526
|
-
|
|
472
|
+
} catch (rawError) {
|
|
473
|
+
var error = locatedError(rawError, fieldNodes, pathToArray(path));
|
|
474
|
+
return handleFieldError(error, returnType, exeContext);
|
|
527
475
|
}
|
|
528
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* @internal
|
|
479
|
+
*/
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
export function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path) {
|
|
483
|
+
// The resolve function's optional fourth argument is a collection of
|
|
484
|
+
// information about the current execution state.
|
|
485
|
+
return {
|
|
486
|
+
fieldName: fieldDef.name,
|
|
487
|
+
fieldNodes: fieldNodes,
|
|
488
|
+
returnType: fieldDef.type,
|
|
489
|
+
parentType: parentType,
|
|
490
|
+
path: path,
|
|
491
|
+
schema: exeContext.schema,
|
|
492
|
+
fragments: exeContext.fragments,
|
|
493
|
+
rootValue: exeContext.rootValue,
|
|
494
|
+
operation: exeContext.operation,
|
|
495
|
+
variableValues: exeContext.variableValues
|
|
496
|
+
};
|
|
497
|
+
}
|
|
529
498
|
|
|
530
|
-
function handleFieldError(
|
|
531
|
-
|
|
499
|
+
function handleFieldError(error, returnType, exeContext) {
|
|
500
|
+
// If the field type is non-nullable, then it is resolved without any
|
|
532
501
|
// protection from errors, however it still properly locates the error.
|
|
533
|
-
|
|
534
502
|
if (isNonNullType(returnType)) {
|
|
535
503
|
throw error;
|
|
536
504
|
} // Otherwise, error protection is applied, logging the error and resolving
|
|
@@ -619,26 +587,47 @@ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
|
619
587
|
|
|
620
588
|
|
|
621
589
|
function completeListValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
622
|
-
|
|
623
|
-
throw new GraphQLError("Expected Iterable, but did not find one for field \"".concat(info.parentType.name, ".").concat(info.fieldName, "\"."));
|
|
624
|
-
} // This is specified as a simple map, however we're optimizing the path
|
|
590
|
+
// This is specified as a simple map, however we're optimizing the path
|
|
625
591
|
// where the list contains no Promises by avoiding creating another Promise.
|
|
626
|
-
|
|
627
|
-
|
|
628
592
|
var itemType = returnType.ofType;
|
|
629
593
|
var containsPromise = false;
|
|
630
|
-
var completedResults =
|
|
594
|
+
var completedResults = safeArrayFrom(result, function (item, index) {
|
|
631
595
|
// No need to modify the info object containing the path,
|
|
632
596
|
// since from here on it is not ever accessed by resolver functions.
|
|
633
|
-
var
|
|
634
|
-
var completedItem = completeValueCatchingError(exeContext, itemType, fieldNodes, info, fieldPath, item);
|
|
597
|
+
var itemPath = addPath(path, index, undefined);
|
|
635
598
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
599
|
+
try {
|
|
600
|
+
var completedItem;
|
|
601
|
+
|
|
602
|
+
if (isPromise(item)) {
|
|
603
|
+
completedItem = item.then(function (resolved) {
|
|
604
|
+
return completeValue(exeContext, itemType, fieldNodes, info, itemPath, resolved);
|
|
605
|
+
});
|
|
606
|
+
} else {
|
|
607
|
+
completedItem = completeValue(exeContext, itemType, fieldNodes, info, itemPath, item);
|
|
608
|
+
}
|
|
639
609
|
|
|
640
|
-
|
|
610
|
+
if (isPromise(completedItem)) {
|
|
611
|
+
containsPromise = true; // Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
612
|
+
// to take a second callback for the error case.
|
|
613
|
+
|
|
614
|
+
return completedItem.then(undefined, function (rawError) {
|
|
615
|
+
var error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
|
|
616
|
+
return handleFieldError(error, itemType, exeContext);
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return completedItem;
|
|
621
|
+
} catch (rawError) {
|
|
622
|
+
var error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
|
|
623
|
+
return handleFieldError(error, itemType, exeContext);
|
|
624
|
+
}
|
|
641
625
|
});
|
|
626
|
+
|
|
627
|
+
if (completedResults == null) {
|
|
628
|
+
throw new GraphQLError("Expected Iterable, but did not find one for field \"".concat(info.parentType.name, ".").concat(info.fieldName, "\"."));
|
|
629
|
+
}
|
|
630
|
+
|
|
642
631
|
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
643
632
|
}
|
|
644
633
|
/**
|
|
@@ -679,10 +668,25 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
679
668
|
}
|
|
680
669
|
|
|
681
670
|
function ensureValidRuntimeType(runtimeTypeOrName, exeContext, returnType, fieldNodes, info, result) {
|
|
682
|
-
|
|
671
|
+
if (runtimeTypeOrName == null) {
|
|
672
|
+
throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" must resolve to an Object type at runtime for field \"").concat(info.parentType.name, ".").concat(info.fieldName, "\". Either the \"").concat(returnType.name, "\" type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."), fieldNodes);
|
|
673
|
+
} // FIXME: temporary workaround until support for passing object types would be removed in v16.0.0
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
var runtimeTypeName = isNamedType(runtimeTypeOrName) ? runtimeTypeOrName.name : runtimeTypeOrName;
|
|
677
|
+
|
|
678
|
+
if (typeof runtimeTypeName !== 'string') {
|
|
679
|
+
throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" must resolve to an Object type at runtime for field \"").concat(info.parentType.name, ".").concat(info.fieldName, "\" with ") + "value ".concat(inspect(result), ", received \"").concat(inspect(runtimeTypeOrName), "\"."));
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
var runtimeType = exeContext.schema.getType(runtimeTypeName);
|
|
683
|
+
|
|
684
|
+
if (runtimeType == null) {
|
|
685
|
+
throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" was resolve to a type \"").concat(runtimeTypeName, "\" that does not exist inside schema."), fieldNodes);
|
|
686
|
+
}
|
|
683
687
|
|
|
684
688
|
if (!isObjectType(runtimeType)) {
|
|
685
|
-
throw new GraphQLError("Abstract type \"".concat(returnType.name, "\"
|
|
689
|
+
throw new GraphQLError("Abstract type \"".concat(returnType.name, "\" was resolve to a non-object type \"").concat(runtimeTypeName, "\"."), fieldNodes);
|
|
686
690
|
}
|
|
687
691
|
|
|
688
692
|
if (!exeContext.schema.isSubType(returnType, runtimeType)) {
|
|
@@ -784,7 +788,7 @@ export var defaultTypeResolver = function defaultTypeResolver(value, contextValu
|
|
|
784
788
|
if (isPromise(isTypeOfResult)) {
|
|
785
789
|
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
786
790
|
} else if (isTypeOfResult) {
|
|
787
|
-
return type;
|
|
791
|
+
return type.name;
|
|
788
792
|
}
|
|
789
793
|
}
|
|
790
794
|
}
|
|
@@ -793,7 +797,7 @@ export var defaultTypeResolver = function defaultTypeResolver(value, contextValu
|
|
|
793
797
|
return Promise.all(promisedIsTypeOfResults).then(function (isTypeOfResults) {
|
|
794
798
|
for (var _i9 = 0; _i9 < isTypeOfResults.length; _i9++) {
|
|
795
799
|
if (isTypeOfResults[_i9]) {
|
|
796
|
-
return possibleTypes[_i9];
|
|
800
|
+
return possibleTypes[_i9].name;
|
|
797
801
|
}
|
|
798
802
|
}
|
|
799
803
|
});
|
|
@@ -820,12 +824,12 @@ export var defaultFieldResolver = function defaultFieldResolver(source, args, co
|
|
|
820
824
|
};
|
|
821
825
|
/**
|
|
822
826
|
* This method looks up the field on the given type definition.
|
|
823
|
-
* It has special casing for the
|
|
824
|
-
* and __typename. __typename is special because
|
|
825
|
-
* queried as a field, even in situations where no
|
|
826
|
-
* are allowed, like on a Union. __schema
|
|
827
|
-
* added to the query type, but that would
|
|
828
|
-
* definitions, which would cause issues.
|
|
827
|
+
* It has special casing for the three introspection fields,
|
|
828
|
+
* __schema, __type and __typename. __typename is special because
|
|
829
|
+
* it can always be queried as a field, even in situations where no
|
|
830
|
+
* other fields are allowed, like on a Union. __schema and __type
|
|
831
|
+
* could get automatically added to the query type, but that would
|
|
832
|
+
* require mutating type definitions, which would cause issues.
|
|
829
833
|
*
|
|
830
834
|
* @internal
|
|
831
835
|
*/
|