graphql 15.3.0 → 15.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +10 -0
- 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 +0 -15
- package/execution/execute.js +104 -104
- package/execution/execute.js.flow +119 -133
- package/execution/execute.mjs +86 -82
- package/execution/index.js +3 -3
- package/execution/index.js.flow +0 -1
- 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 +1 -0
- package/index.js +9 -9
- package/index.js.flow +0 -1
- 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 +15 -9
- package/jsutils/instanceOf.js.flow +13 -7
- package/jsutils/instanceOf.mjs +13 -5
- 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 +7 -0
- package/language/source.js +20 -3
- package/language/source.js.flow +21 -3
- package/language/source.mjs +14 -1
- package/language/tokenKind.js.flow +0 -1
- package/language/visitor.js +2 -2
- package/language/visitor.js.flow +0 -1
- 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 +16 -6
- 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 +3 -3
- package/version.js.flow +3 -4
- package/version.mjs +3 -3
- 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,7 +8,7 @@ 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';
|
|
@@ -54,6 +51,7 @@ import {
|
|
|
54
51
|
GraphQLSkipDirective,
|
|
55
52
|
} from '../type/directives';
|
|
56
53
|
import {
|
|
54
|
+
isNamedType,
|
|
57
55
|
isObjectType,
|
|
58
56
|
isAbstractType,
|
|
59
57
|
isLeafType,
|
|
@@ -388,8 +386,6 @@ function executeOperation(
|
|
|
388
386
|
// Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
389
387
|
// at which point we still log the error and null the parent field, which
|
|
390
388
|
// in this case is the entire response.
|
|
391
|
-
//
|
|
392
|
-
// Similar to completeValueCatchingError.
|
|
393
389
|
try {
|
|
394
390
|
const result =
|
|
395
391
|
operation.operation === 'mutation'
|
|
@@ -474,7 +470,7 @@ function executeFields(
|
|
|
474
470
|
|
|
475
471
|
if (result !== undefined) {
|
|
476
472
|
results[responseName] = result;
|
|
477
|
-
if (
|
|
473
|
+
if (isPromise(result)) {
|
|
478
474
|
containsPromise = true;
|
|
479
475
|
}
|
|
480
476
|
}
|
|
@@ -645,6 +641,7 @@ function resolveField(
|
|
|
645
641
|
return;
|
|
646
642
|
}
|
|
647
643
|
|
|
644
|
+
const returnType = fieldDef.type;
|
|
648
645
|
const resolveFn = fieldDef.resolve ?? exeContext.fieldResolver;
|
|
649
646
|
|
|
650
647
|
const info = buildResolveInfo(
|
|
@@ -655,67 +652,7 @@ function resolveField(
|
|
|
655
652
|
path,
|
|
656
653
|
);
|
|
657
654
|
|
|
658
|
-
// Get the resolve function, regardless of if its result is normal
|
|
659
|
-
// or abrupt (error).
|
|
660
|
-
const result = resolveFieldValueOrError(
|
|
661
|
-
exeContext,
|
|
662
|
-
fieldDef,
|
|
663
|
-
fieldNodes,
|
|
664
|
-
resolveFn,
|
|
665
|
-
source,
|
|
666
|
-
info,
|
|
667
|
-
);
|
|
668
|
-
|
|
669
|
-
return completeValueCatchingError(
|
|
670
|
-
exeContext,
|
|
671
|
-
fieldDef.type,
|
|
672
|
-
fieldNodes,
|
|
673
|
-
info,
|
|
674
|
-
path,
|
|
675
|
-
result,
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* @internal
|
|
681
|
-
*/
|
|
682
|
-
export function buildResolveInfo(
|
|
683
|
-
exeContext: ExecutionContext,
|
|
684
|
-
fieldDef: GraphQLField<mixed, mixed>,
|
|
685
|
-
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
686
|
-
parentType: GraphQLObjectType,
|
|
687
|
-
path: Path,
|
|
688
|
-
): GraphQLResolveInfo {
|
|
689
|
-
// The resolve function's optional fourth argument is a collection of
|
|
690
|
-
// information about the current execution state.
|
|
691
|
-
return {
|
|
692
|
-
fieldName: fieldDef.name,
|
|
693
|
-
fieldNodes,
|
|
694
|
-
returnType: fieldDef.type,
|
|
695
|
-
parentType,
|
|
696
|
-
path,
|
|
697
|
-
schema: exeContext.schema,
|
|
698
|
-
fragments: exeContext.fragments,
|
|
699
|
-
rootValue: exeContext.rootValue,
|
|
700
|
-
operation: exeContext.operation,
|
|
701
|
-
variableValues: exeContext.variableValues,
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
|
|
707
|
-
* function. Returns the result of resolveFn or the abrupt-return Error object.
|
|
708
|
-
*
|
|
709
|
-
* @internal
|
|
710
|
-
*/
|
|
711
|
-
export function resolveFieldValueOrError(
|
|
712
|
-
exeContext: ExecutionContext,
|
|
713
|
-
fieldDef: GraphQLField<mixed, mixed>,
|
|
714
|
-
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
715
|
-
resolveFn: GraphQLFieldResolver<mixed, mixed>,
|
|
716
|
-
source: mixed,
|
|
717
|
-
info: GraphQLResolveInfo,
|
|
718
|
-
): Error | mixed {
|
|
655
|
+
// Get the resolve function, regardless of if its result is normal or abrupt (error).
|
|
719
656
|
try {
|
|
720
657
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
721
658
|
// variables scope to fulfill any variable references.
|
|
@@ -732,32 +669,7 @@ export function resolveFieldValueOrError(
|
|
|
732
669
|
const contextValue = exeContext.contextValue;
|
|
733
670
|
|
|
734
671
|
const result = resolveFn(source, args, contextValue, info);
|
|
735
|
-
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
|
|
736
|
-
} catch (error) {
|
|
737
|
-
return asErrorInstance(error);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
672
|
|
|
741
|
-
// Sometimes a non-error is thrown, wrap it as an Error instance to ensure a
|
|
742
|
-
// consistent Error interface.
|
|
743
|
-
function asErrorInstance(error: mixed): Error {
|
|
744
|
-
if (error instanceof Error) {
|
|
745
|
-
return error;
|
|
746
|
-
}
|
|
747
|
-
return new Error('Unexpected error value: ' + inspect(error));
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// This is a small wrapper around completeValue which detects and logs errors
|
|
751
|
-
// in the execution context.
|
|
752
|
-
function completeValueCatchingError(
|
|
753
|
-
exeContext: ExecutionContext,
|
|
754
|
-
returnType: GraphQLOutputType,
|
|
755
|
-
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
756
|
-
info: GraphQLResolveInfo,
|
|
757
|
-
path: Path,
|
|
758
|
-
result: mixed,
|
|
759
|
-
): PromiseOrValue<mixed> {
|
|
760
|
-
try {
|
|
761
673
|
let completed;
|
|
762
674
|
if (isPromise(result)) {
|
|
763
675
|
completed = result.then((resolved) =>
|
|
@@ -777,23 +689,49 @@ function completeValueCatchingError(
|
|
|
777
689
|
if (isPromise(completed)) {
|
|
778
690
|
// Note: we don't rely on a `catch` method, but we do expect "thenable"
|
|
779
691
|
// to take a second callback for the error case.
|
|
780
|
-
return completed.then(undefined, (
|
|
781
|
-
|
|
782
|
-
|
|
692
|
+
return completed.then(undefined, (rawError) => {
|
|
693
|
+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
|
|
694
|
+
return handleFieldError(error, returnType, exeContext);
|
|
695
|
+
});
|
|
783
696
|
}
|
|
784
697
|
return completed;
|
|
785
|
-
} catch (
|
|
786
|
-
|
|
698
|
+
} catch (rawError) {
|
|
699
|
+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
|
|
700
|
+
return handleFieldError(error, returnType, exeContext);
|
|
787
701
|
}
|
|
788
702
|
}
|
|
789
703
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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,
|
|
793
718
|
fieldNodes,
|
|
794
|
-
|
|
795
|
-
|
|
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
|
+
}
|
|
796
729
|
|
|
730
|
+
function handleFieldError(
|
|
731
|
+
error: GraphQLError,
|
|
732
|
+
returnType: GraphQLOutputType,
|
|
733
|
+
exeContext: ExecutionContext,
|
|
734
|
+
): null {
|
|
797
735
|
// If the field type is non-nullable, then it is resolved without any
|
|
798
736
|
// protection from errors, however it still properly locates the error.
|
|
799
737
|
if (isNonNullType(returnType)) {
|
|
@@ -928,36 +866,64 @@ function completeListValue(
|
|
|
928
866
|
path: Path,
|
|
929
867
|
result: mixed,
|
|
930
868
|
): PromiseOrValue<$ReadOnlyArray<mixed>> {
|
|
931
|
-
if (!isCollection(result)) {
|
|
932
|
-
throw new GraphQLError(
|
|
933
|
-
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
|
|
934
|
-
);
|
|
935
|
-
}
|
|
936
|
-
|
|
937
869
|
// This is specified as a simple map, however we're optimizing the path
|
|
938
870
|
// where the list contains no Promises by avoiding creating another Promise.
|
|
939
871
|
const itemType = returnType.ofType;
|
|
940
872
|
let containsPromise = false;
|
|
941
|
-
const completedResults =
|
|
873
|
+
const completedResults = safeArrayFrom(result, (item, index) => {
|
|
942
874
|
// No need to modify the info object containing the path,
|
|
943
875
|
// since from here on it is not ever accessed by resolver functions.
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
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
|
+
}
|
|
953
900
|
|
|
954
|
-
|
|
955
|
-
|
|
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);
|
|
956
918
|
}
|
|
957
|
-
|
|
958
|
-
return completedItem;
|
|
959
919
|
});
|
|
960
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
|
+
|
|
961
927
|
return containsPromise ? Promise.all(completedResults) : completedResults;
|
|
962
928
|
}
|
|
963
929
|
|
|
@@ -1030,23 +996,43 @@ function completeAbstractValue(
|
|
|
1030
996
|
}
|
|
1031
997
|
|
|
1032
998
|
function ensureValidRuntimeType(
|
|
1033
|
-
runtimeTypeOrName:
|
|
999
|
+
runtimeTypeOrName: mixed,
|
|
1034
1000
|
exeContext: ExecutionContext,
|
|
1035
1001
|
returnType: GraphQLAbstractType,
|
|
1036
1002
|
fieldNodes: $ReadOnlyArray<FieldNode>,
|
|
1037
1003
|
info: GraphQLResolveInfo,
|
|
1038
1004
|
result: mixed,
|
|
1039
1005
|
): GraphQLObjectType {
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
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
|
+
}
|
|
1044
1012
|
|
|
1045
|
-
|
|
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') {
|
|
1046
1019
|
throw new GraphQLError(
|
|
1047
1020
|
`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
|
|
1048
|
-
`value ${inspect(result)}, received "${inspect(
|
|
1049
|
-
|
|
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}".`,
|
|
1050
1036
|
fieldNodes,
|
|
1051
1037
|
);
|
|
1052
1038
|
}
|
|
@@ -1191,7 +1177,7 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
|
|
|
1191
1177
|
if (isPromise(isTypeOfResult)) {
|
|
1192
1178
|
promisedIsTypeOfResults[i] = isTypeOfResult;
|
|
1193
1179
|
} else if (isTypeOfResult) {
|
|
1194
|
-
return type;
|
|
1180
|
+
return type.name;
|
|
1195
1181
|
}
|
|
1196
1182
|
}
|
|
1197
1183
|
}
|
|
@@ -1200,7 +1186,7 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
|
|
|
1200
1186
|
return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
|
|
1201
1187
|
for (let i = 0; i < isTypeOfResults.length; i++) {
|
|
1202
1188
|
if (isTypeOfResults[i]) {
|
|
1203
|
-
return possibleTypes[i];
|
|
1189
|
+
return possibleTypes[i].name;
|
|
1204
1190
|
}
|
|
1205
1191
|
}
|
|
1206
1192
|
});
|
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
|
});
|
package/execution/index.js
CHANGED
|
@@ -40,8 +40,8 @@ Object.defineProperty(exports, "getDirectiveValues", {
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
var _Path = require("../jsutils/Path");
|
|
43
|
+
var _Path = require("../jsutils/Path.js");
|
|
44
44
|
|
|
45
|
-
var _execute = require("./execute");
|
|
45
|
+
var _execute = require("./execute.js");
|
|
46
46
|
|
|
47
|
-
var _values = require("./values");
|
|
47
|
+
var _values = require("./values.js");
|