graphql 16.14.0 → 16.14.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/error/GraphQLError.d.ts +151 -15
- package/error/GraphQLError.js +143 -12
- package/error/GraphQLError.mjs +143 -12
- package/error/index.d.ts +6 -0
- package/error/index.mjs +6 -0
- package/error/locatedError.d.ts +20 -0
- package/error/locatedError.js +21 -0
- package/error/locatedError.mjs +20 -0
- package/error/syntaxError.d.ts +15 -0
- package/error/syntaxError.js +16 -0
- package/error/syntaxError.mjs +15 -0
- package/execution/collectFields.js +6 -0
- package/execution/collectFields.mjs +6 -0
- package/execution/execute.d.ts +211 -12
- package/execution/execute.js +214 -23
- package/execution/execute.mjs +213 -23
- package/execution/index.d.ts +6 -0
- package/execution/index.mjs +6 -0
- package/execution/mapAsyncIterator.d.ts +2 -0
- package/execution/mapAsyncIterator.js +2 -0
- package/execution/mapAsyncIterator.mjs +2 -0
- package/execution/subscribe.d.ts +195 -5
- package/execution/subscribe.js +154 -11
- package/execution/subscribe.mjs +153 -11
- package/execution/values.d.ts +167 -10
- package/execution/values.js +149 -5
- package/execution/values.mjs +148 -5
- package/graphql.d.ts +163 -41
- package/graphql.js +126 -4
- package/graphql.mjs +131 -41
- package/index.d.ts +11 -17
- package/index.mjs +13 -19
- package/jsutils/Maybe.d.ts +5 -1
- package/jsutils/ObjMap.d.ts +4 -0
- package/jsutils/Path.d.ts +30 -0
- package/jsutils/Path.js +29 -0
- package/jsutils/Path.mjs +29 -0
- package/jsutils/PromiseOrValue.d.ts +1 -0
- package/jsutils/devAssert.d.ts +1 -0
- package/jsutils/devAssert.js +1 -0
- package/jsutils/devAssert.mjs +1 -0
- package/jsutils/didYouMean.d.ts +4 -1
- package/jsutils/didYouMean.js +4 -1
- package/jsutils/didYouMean.mjs +4 -1
- package/jsutils/groupBy.d.ts +2 -0
- package/jsutils/groupBy.js +2 -0
- package/jsutils/groupBy.mjs +2 -0
- package/jsutils/identityFunc.d.ts +2 -0
- package/jsutils/identityFunc.js +2 -0
- package/jsutils/identityFunc.mjs +2 -0
- package/jsutils/inspect.d.ts +2 -0
- package/jsutils/inspect.js +2 -0
- package/jsutils/inspect.mjs +2 -0
- package/jsutils/instanceOf.d.ts +2 -0
- package/jsutils/instanceOf.js +2 -0
- package/jsutils/instanceOf.mjs +2 -0
- package/jsutils/invariant.d.ts +1 -0
- package/jsutils/invariant.js +1 -0
- package/jsutils/invariant.mjs +1 -0
- package/jsutils/isAsyncIterable.d.ts +2 -0
- package/jsutils/isAsyncIterable.js +2 -0
- package/jsutils/isAsyncIterable.mjs +2 -0
- package/jsutils/isIterableObject.d.ts +6 -5
- package/jsutils/isIterableObject.js +6 -5
- package/jsutils/isIterableObject.mjs +6 -5
- package/jsutils/isObjectLike.d.ts +2 -0
- package/jsutils/isObjectLike.js +2 -0
- package/jsutils/isObjectLike.mjs +2 -0
- package/jsutils/isPromise.d.ts +2 -0
- package/jsutils/isPromise.js +2 -0
- package/jsutils/isPromise.mjs +2 -0
- package/jsutils/keyMap.d.ts +7 -14
- package/jsutils/keyMap.js +7 -14
- package/jsutils/keyMap.mjs +7 -14
- package/jsutils/keyValMap.d.ts +9 -6
- package/jsutils/keyValMap.js +9 -6
- package/jsutils/keyValMap.mjs +9 -6
- package/jsutils/mapValue.d.ts +2 -0
- package/jsutils/mapValue.js +2 -0
- package/jsutils/mapValue.mjs +2 -0
- package/jsutils/memoize3.d.ts +2 -0
- package/jsutils/memoize3.js +2 -0
- package/jsutils/memoize3.mjs +2 -0
- package/jsutils/naturalCompare.d.ts +2 -0
- package/jsutils/naturalCompare.js +2 -0
- package/jsutils/naturalCompare.mjs +2 -0
- package/jsutils/printPathArray.d.ts +2 -0
- package/jsutils/printPathArray.js +2 -0
- package/jsutils/printPathArray.mjs +2 -0
- package/jsutils/promiseForObject.d.ts +2 -0
- package/jsutils/promiseForObject.js +2 -0
- package/jsutils/promiseForObject.mjs +2 -0
- package/jsutils/promiseReduce.d.ts +2 -0
- package/jsutils/promiseReduce.js +2 -0
- package/jsutils/promiseReduce.mjs +2 -0
- package/jsutils/suggestionList.d.ts +2 -0
- package/jsutils/suggestionList.js +4 -0
- package/jsutils/suggestionList.mjs +4 -0
- package/jsutils/toError.d.ts +2 -0
- package/jsutils/toError.js +2 -0
- package/jsutils/toError.mjs +2 -0
- package/jsutils/toObjMap.d.ts +1 -0
- package/jsutils/toObjMap.js +1 -0
- package/jsutils/toObjMap.mjs +1 -0
- package/language/ast.d.ts +412 -54
- package/language/ast.js +95 -38
- package/language/ast.mjs +95 -38
- package/language/blockString.d.ts +1 -3
- package/language/blockString.js +1 -3
- package/language/blockString.mjs +1 -3
- package/language/directiveLocation.d.ts +28 -8
- package/language/directiveLocation.js +9 -6
- package/language/directiveLocation.mjs +9 -6
- package/language/index.d.ts +6 -0
- package/language/index.mjs +6 -0
- package/language/kinds.d.ts +57 -18
- package/language/kinds.js +9 -6
- package/language/kinds.mjs +9 -6
- package/language/lexer.d.ts +47 -14
- package/language/lexer.js +71 -13
- package/language/lexer.mjs +70 -13
- package/language/location.d.ts +16 -3
- package/language/location.js +14 -3
- package/language/location.mjs +14 -3
- package/language/parser.d.ts +236 -13
- package/language/parser.js +224 -0
- package/language/parser.mjs +224 -3
- package/language/predicates.d.ts +169 -0
- package/language/predicates.js +170 -0
- package/language/predicates.mjs +180 -0
- package/language/printLocation.d.ts +28 -0
- package/language/printLocation.js +29 -0
- package/language/printLocation.mjs +28 -0
- package/language/printString.d.ts +2 -0
- package/language/printString.js +5 -1
- package/language/printString.mjs +5 -1
- package/language/printer.d.ts +12 -0
- package/language/printer.js +19 -0
- package/language/printer.mjs +18 -0
- package/language/schemaCoordinateLexer.d.ts +8 -6
- package/language/schemaCoordinateLexer.js +10 -6
- package/language/schemaCoordinateLexer.mjs +10 -6
- package/language/source.d.ts +28 -0
- package/language/source.js +32 -0
- package/language/source.mjs +31 -0
- package/language/tokenKind.d.ts +30 -3
- package/language/tokenKind.js +8 -3
- package/language/tokenKind.mjs +8 -3
- package/language/visitor.d.ts +200 -72
- package/language/visitor.js +122 -50
- package/language/visitor.mjs +122 -54
- package/package.json +1 -1
- package/subscription/index.d.ts +9 -3
- package/subscription/index.mjs +9 -3
- package/type/assertName.d.ts +18 -1
- package/type/assertName.js +19 -1
- package/type/assertName.mjs +18 -1
- package/type/definition.d.ts +2540 -79
- package/type/definition.js +2214 -61
- package/type/definition.mjs +2241 -60
- package/type/directives.d.ts +193 -18
- package/type/directives.js +196 -19
- package/type/directives.mjs +196 -19
- package/type/index.d.ts +6 -0
- package/type/index.mjs +6 -0
- package/type/introspection.d.ts +36 -0
- package/type/introspection.js +33 -0
- package/type/introspection.mjs +41 -0
- package/type/scalars.d.ts +29 -2
- package/type/scalars.js +37 -2
- package/type/scalars.mjs +36 -2
- package/type/schema.d.ts +490 -28
- package/type/schema.js +484 -26
- package/type/schema.mjs +484 -26
- package/type/validate.d.ts +31 -0
- package/type/validate.js +32 -0
- package/type/validate.mjs +31 -0
- package/utilities/TypeInfo.d.ts +441 -1
- package/utilities/TypeInfo.js +444 -1
- package/utilities/TypeInfo.mjs +443 -1
- package/utilities/assertValidName.d.ts +27 -2
- package/utilities/assertValidName.js +28 -2
- package/utilities/assertValidName.mjs +27 -2
- package/utilities/astFromValue.d.ts +33 -3
- package/utilities/astFromValue.js +36 -3
- package/utilities/astFromValue.mjs +35 -3
- package/utilities/buildASTSchema.d.ts +65 -6
- package/utilities/buildASTSchema.js +65 -6
- package/utilities/buildASTSchema.mjs +65 -6
- package/utilities/buildClientSchema.d.ts +15 -0
- package/utilities/buildClientSchema.js +16 -0
- package/utilities/buildClientSchema.mjs +15 -0
- package/utilities/coerceInputValue.d.ts +46 -0
- package/utilities/coerceInputValue.js +47 -0
- package/utilities/coerceInputValue.mjs +46 -0
- package/utilities/concatAST.d.ts +12 -0
- package/utilities/concatAST.js +13 -0
- package/utilities/concatAST.mjs +12 -0
- package/utilities/extendSchema.d.ts +56 -3
- package/utilities/extendSchema.js +63 -3
- package/utilities/extendSchema.mjs +62 -3
- package/utilities/findBreakingChanges.d.ts +95 -0
- package/utilities/findBreakingChanges.js +68 -0
- package/utilities/findBreakingChanges.mjs +70 -0
- package/utilities/getIntrospectionQuery.d.ts +132 -0
- package/utilities/getIntrospectionQuery.js +41 -0
- package/utilities/getIntrospectionQuery.mjs +41 -0
- package/utilities/getOperationAST.d.ts +15 -0
- package/utilities/getOperationAST.js +16 -0
- package/utilities/getOperationAST.mjs +15 -0
- package/utilities/getOperationRootType.d.ts +18 -1
- package/utilities/getOperationRootType.js +19 -1
- package/utilities/getOperationRootType.mjs +18 -1
- package/utilities/index.d.ts +7 -0
- package/utilities/index.mjs +7 -0
- package/utilities/introspectionFromSchema.d.ts +54 -0
- package/utilities/introspectionFromSchema.js +55 -0
- package/utilities/introspectionFromSchema.mjs +54 -0
- package/utilities/lexicographicSortSchema.d.ts +35 -0
- package/utilities/lexicographicSortSchema.js +36 -0
- package/utilities/lexicographicSortSchema.mjs +35 -0
- package/utilities/printSchema.d.ts +63 -0
- package/utilities/printSchema.js +66 -0
- package/utilities/printSchema.mjs +67 -0
- package/utilities/resolveSchemaCoordinate.d.ts +62 -0
- package/utilities/resolveSchemaCoordinate.js +64 -0
- package/utilities/resolveSchemaCoordinate.mjs +63 -0
- package/utilities/separateOperations.d.ts +30 -0
- package/utilities/separateOperations.js +31 -0
- package/utilities/separateOperations.mjs +30 -0
- package/utilities/stripIgnoredCharacters.d.ts +13 -6
- package/utilities/stripIgnoredCharacters.js +16 -6
- package/utilities/stripIgnoredCharacters.mjs +15 -6
- package/utilities/typeComparators.d.ts +84 -0
- package/utilities/typeComparators.js +85 -0
- package/utilities/typeComparators.mjs +84 -0
- package/utilities/typeFromAST.d.ts +86 -0
- package/utilities/typeFromAST.js +3 -0
- package/utilities/typeFromAST.mjs +3 -0
- package/utilities/typedQueryDocumentNode.d.ts +4 -0
- package/utilities/valueFromAST.d.ts +38 -0
- package/utilities/valueFromAST.js +39 -0
- package/utilities/valueFromAST.mjs +38 -0
- package/utilities/valueFromASTUntyped.d.ts +15 -2
- package/utilities/valueFromASTUntyped.js +16 -2
- package/utilities/valueFromASTUntyped.mjs +15 -2
- package/validation/ValidationContext.d.ts +399 -0
- package/validation/ValidationContext.js +400 -0
- package/validation/ValidationContext.mjs +401 -0
- package/validation/index.d.ts +6 -0
- package/validation/index.mjs +6 -0
- package/validation/rules/ExecutableDefinitionsRule.d.ts +28 -0
- package/validation/rules/ExecutableDefinitionsRule.js +29 -0
- package/validation/rules/ExecutableDefinitionsRule.mjs +28 -0
- package/validation/rules/FieldsOnCorrectTypeRule.d.ts +28 -0
- package/validation/rules/FieldsOnCorrectTypeRule.js +33 -0
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +32 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +28 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.js +29 -0
- package/validation/rules/FragmentsOnCompositeTypesRule.mjs +28 -0
- package/validation/rules/KnownArgumentNamesRule.d.ts +29 -3
- package/validation/rules/KnownArgumentNamesRule.js +30 -3
- package/validation/rules/KnownArgumentNamesRule.mjs +29 -3
- package/validation/rules/KnownDirectivesRule.d.ts +28 -0
- package/validation/rules/KnownDirectivesRule.js +29 -0
- package/validation/rules/KnownDirectivesRule.mjs +28 -0
- package/validation/rules/KnownFragmentNamesRule.d.ts +28 -0
- package/validation/rules/KnownFragmentNamesRule.js +29 -0
- package/validation/rules/KnownFragmentNamesRule.mjs +28 -0
- package/validation/rules/KnownTypeNamesRule.d.ts +28 -0
- package/validation/rules/KnownTypeNamesRule.js +29 -0
- package/validation/rules/KnownTypeNamesRule.mjs +28 -0
- package/validation/rules/LoneAnonymousOperationRule.d.ts +28 -0
- package/validation/rules/LoneAnonymousOperationRule.js +29 -0
- package/validation/rules/LoneAnonymousOperationRule.mjs +28 -0
- package/validation/rules/LoneSchemaDefinitionRule.d.ts +21 -0
- package/validation/rules/LoneSchemaDefinitionRule.js +22 -0
- package/validation/rules/LoneSchemaDefinitionRule.mjs +21 -0
- package/validation/rules/MaxIntrospectionDepthRule.d.ts +31 -0
- package/validation/rules/MaxIntrospectionDepthRule.js +33 -0
- package/validation/rules/MaxIntrospectionDepthRule.mjs +34 -0
- package/validation/rules/NoFragmentCyclesRule.d.ts +28 -0
- package/validation/rules/NoFragmentCyclesRule.js +29 -0
- package/validation/rules/NoFragmentCyclesRule.mjs +28 -0
- package/validation/rules/NoUndefinedVariablesRule.d.ts +28 -0
- package/validation/rules/NoUndefinedVariablesRule.js +29 -0
- package/validation/rules/NoUndefinedVariablesRule.mjs +28 -0
- package/validation/rules/NoUnusedFragmentsRule.d.ts +28 -0
- package/validation/rules/NoUnusedFragmentsRule.js +29 -0
- package/validation/rules/NoUnusedFragmentsRule.mjs +28 -0
- package/validation/rules/NoUnusedVariablesRule.d.ts +29 -0
- package/validation/rules/NoUnusedVariablesRule.js +30 -0
- package/validation/rules/NoUnusedVariablesRule.mjs +29 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +33 -0
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +45 -6
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +45 -6
- package/validation/rules/PossibleFragmentSpreadsRule.d.ts +36 -0
- package/validation/rules/PossibleFragmentSpreadsRule.js +37 -0
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +36 -0
- package/validation/rules/PossibleTypeExtensionsRule.d.ts +21 -0
- package/validation/rules/PossibleTypeExtensionsRule.js +22 -0
- package/validation/rules/PossibleTypeExtensionsRule.mjs +21 -0
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +29 -3
- package/validation/rules/ProvidedRequiredArgumentsRule.js +30 -3
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +29 -3
- package/validation/rules/ScalarLeafsRule.d.ts +28 -0
- package/validation/rules/ScalarLeafsRule.js +29 -0
- package/validation/rules/ScalarLeafsRule.mjs +28 -0
- package/validation/rules/SingleFieldSubscriptionsRule.d.ts +33 -0
- package/validation/rules/SingleFieldSubscriptionsRule.js +34 -0
- package/validation/rules/SingleFieldSubscriptionsRule.mjs +33 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.d.ts +21 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.js +22 -0
- package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +21 -0
- package/validation/rules/UniqueArgumentNamesRule.d.ts +28 -0
- package/validation/rules/UniqueArgumentNamesRule.js +29 -0
- package/validation/rules/UniqueArgumentNamesRule.mjs +28 -0
- package/validation/rules/UniqueDirectiveNamesRule.d.ts +21 -0
- package/validation/rules/UniqueDirectiveNamesRule.js +22 -0
- package/validation/rules/UniqueDirectiveNamesRule.mjs +21 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +28 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.js +29 -0
- package/validation/rules/UniqueDirectivesPerLocationRule.mjs +28 -0
- package/validation/rules/UniqueEnumValueNamesRule.d.ts +21 -0
- package/validation/rules/UniqueEnumValueNamesRule.js +22 -0
- package/validation/rules/UniqueEnumValueNamesRule.mjs +21 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.d.ts +21 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +22 -0
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +21 -0
- package/validation/rules/UniqueFragmentNamesRule.d.ts +28 -0
- package/validation/rules/UniqueFragmentNamesRule.js +29 -0
- package/validation/rules/UniqueFragmentNamesRule.mjs +28 -0
- package/validation/rules/UniqueInputFieldNamesRule.d.ts +32 -0
- package/validation/rules/UniqueInputFieldNamesRule.js +33 -0
- package/validation/rules/UniqueInputFieldNamesRule.mjs +32 -0
- package/validation/rules/UniqueOperationNamesRule.d.ts +28 -0
- package/validation/rules/UniqueOperationNamesRule.js +29 -0
- package/validation/rules/UniqueOperationNamesRule.mjs +28 -0
- package/validation/rules/UniqueOperationTypesRule.d.ts +21 -0
- package/validation/rules/UniqueOperationTypesRule.js +22 -0
- package/validation/rules/UniqueOperationTypesRule.mjs +21 -0
- package/validation/rules/UniqueTypeNamesRule.d.ts +21 -0
- package/validation/rules/UniqueTypeNamesRule.js +22 -0
- package/validation/rules/UniqueTypeNamesRule.mjs +21 -0
- package/validation/rules/UniqueVariableNamesRule.d.ts +28 -0
- package/validation/rules/UniqueVariableNamesRule.js +29 -0
- package/validation/rules/UniqueVariableNamesRule.mjs +28 -0
- package/validation/rules/ValuesOfCorrectTypeRule.d.ts +28 -0
- package/validation/rules/ValuesOfCorrectTypeRule.js +31 -0
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +30 -0
- package/validation/rules/VariablesAreInputTypesRule.d.ts +32 -0
- package/validation/rules/VariablesAreInputTypesRule.js +33 -0
- package/validation/rules/VariablesAreInputTypesRule.mjs +32 -0
- package/validation/rules/VariablesInAllowedPositionRule.d.ts +28 -0
- package/validation/rules/VariablesInAllowedPositionRule.js +35 -1
- package/validation/rules/VariablesInAllowedPositionRule.mjs +34 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +41 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.js +42 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +41 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +28 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +29 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +28 -0
- package/validation/specifiedRules.d.ts +2 -3
- package/validation/specifiedRules.js +2 -3
- package/validation/specifiedRules.mjs +2 -3
- package/validation/validate.d.ts +70 -9
- package/validation/validate.js +63 -7
- package/validation/validate.mjs +63 -7
- package/version.d.ts +3 -6
- package/version.js +6 -8
- package/version.mjs +5 -8
package/execution/execute.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @category Execution */
|
|
1
2
|
import { devAssert } from '../jsutils/devAssert.mjs';
|
|
2
3
|
import { inspect } from '../jsutils/inspect.mjs';
|
|
3
4
|
import { invariant } from '../jsutils/invariant.mjs';
|
|
@@ -34,6 +35,8 @@ import { getArgumentValues, getVariableValues } from './values.mjs';
|
|
|
34
35
|
* A memoized collection of relevant subfields with regard to the return
|
|
35
36
|
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
36
37
|
* saves overhead when resolving lists of values.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
37
40
|
*/
|
|
38
41
|
|
|
39
42
|
const collectSubfields = memoize3((exeContext, returnType, fieldNodes) =>
|
|
@@ -70,11 +73,10 @@ const collectSubfields = memoize3((exeContext, returnType, fieldNodes) =>
|
|
|
70
73
|
*
|
|
71
74
|
* Namely, schema of the type system that is currently executing,
|
|
72
75
|
* and the fragments defined in the query document
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
+
*
|
|
76
77
|
* @internal
|
|
77
78
|
*/
|
|
79
|
+
|
|
78
80
|
class CollectedErrors {
|
|
79
81
|
constructor() {
|
|
80
82
|
this._errorPositions = new Set();
|
|
@@ -114,11 +116,9 @@ class CollectedErrors {
|
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* - `data` is the result of a successful execution of the query.
|
|
121
|
-
* - `extensions` is reserved for adding non-standard properties.
|
|
119
|
+
* Represents the response produced by executing a GraphQL operation.
|
|
120
|
+
* @typeParam TData - Shape of the execution data payload.
|
|
121
|
+
* @typeParam TExtensions - Shape of the extensions payload.
|
|
122
122
|
*/
|
|
123
123
|
|
|
124
124
|
/**
|
|
@@ -130,6 +130,139 @@ class CollectedErrors {
|
|
|
130
130
|
*
|
|
131
131
|
* If the arguments to this function do not result in a legal execution context,
|
|
132
132
|
* a GraphQLError will be thrown immediately explaining the invalid input.
|
|
133
|
+
*
|
|
134
|
+
* Field errors are collected into the response instead of rejecting the
|
|
135
|
+
* returned promise. Only the field that produced the error and its descendants
|
|
136
|
+
* are omitted; sibling fields continue to execute. Errors from fields of
|
|
137
|
+
* non-null type may propagate to the nearest nullable parent, which can be the
|
|
138
|
+
* entire response data.
|
|
139
|
+
* @param args - The arguments used to perform the operation.
|
|
140
|
+
* @returns A completed execution result, or a promise resolving to one when execution is asynchronous.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* // Execute an asynchronous operation with variables.
|
|
144
|
+
* import { parse } from 'graphql/language';
|
|
145
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
146
|
+
* import { execute } from 'graphql/execution';
|
|
147
|
+
*
|
|
148
|
+
* const schema = buildSchema(`
|
|
149
|
+
* type Query {
|
|
150
|
+
* greeting(name: String!): String
|
|
151
|
+
* }
|
|
152
|
+
* `);
|
|
153
|
+
*
|
|
154
|
+
* const result = await execute({
|
|
155
|
+
* schema,
|
|
156
|
+
* document: parse('query ($name: String!) { greeting(name: $name) }'),
|
|
157
|
+
* rootValue: {
|
|
158
|
+
* greeting: ({ name }) => `Hello, ${name}!`,
|
|
159
|
+
* },
|
|
160
|
+
* variableValues: { name: 'Ada' },
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* result; // => { data: { greeting: 'Hello, Ada!' } }
|
|
164
|
+
* ```
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* // This variant supplies context plus custom field and type resolvers.
|
|
168
|
+
* import { parse } from 'graphql/language';
|
|
169
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
170
|
+
* import { execute } from 'graphql/execution';
|
|
171
|
+
*
|
|
172
|
+
* const schema = buildSchema(`
|
|
173
|
+
* interface Named {
|
|
174
|
+
* name: String!
|
|
175
|
+
* }
|
|
176
|
+
*
|
|
177
|
+
* type User implements Named {
|
|
178
|
+
* name: String!
|
|
179
|
+
* }
|
|
180
|
+
*
|
|
181
|
+
* type Query {
|
|
182
|
+
* viewer: Named
|
|
183
|
+
* }
|
|
184
|
+
* `);
|
|
185
|
+
*
|
|
186
|
+
* const result = await execute({
|
|
187
|
+
* schema,
|
|
188
|
+
* document: parse('query Viewer { viewer { __typename name } }'),
|
|
189
|
+
* rootValue: { viewer: { kind: 'user', name: 'Ada' } },
|
|
190
|
+
* contextValue: { locale: 'en' },
|
|
191
|
+
* operationName: 'Viewer',
|
|
192
|
+
* fieldResolver: (source, _args, contextValue, info) => {
|
|
193
|
+
* contextValue.locale; // => 'en'
|
|
194
|
+
* return source[info.fieldName];
|
|
195
|
+
* },
|
|
196
|
+
* typeResolver: (value) => {
|
|
197
|
+
* return value.kind === 'user' ? 'User' : undefined;
|
|
198
|
+
* },
|
|
199
|
+
* });
|
|
200
|
+
*
|
|
201
|
+
* result; // => { data: { viewer: { __typename: 'User', name: 'Ada' } } }
|
|
202
|
+
* ```
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* // This variant shows how resolver errors become field errors in the result.
|
|
206
|
+
* import { parse } from 'graphql/language';
|
|
207
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
208
|
+
* import { execute } from 'graphql/execution';
|
|
209
|
+
*
|
|
210
|
+
* const schema = buildSchema(`
|
|
211
|
+
* type Query {
|
|
212
|
+
* broken: String
|
|
213
|
+
* }
|
|
214
|
+
* `);
|
|
215
|
+
* const document = parse('{ broken }');
|
|
216
|
+
*
|
|
217
|
+
* const result = await execute({
|
|
218
|
+
* schema,
|
|
219
|
+
* document,
|
|
220
|
+
* rootValue: {
|
|
221
|
+
* broken: () => {
|
|
222
|
+
* throw new Error('Resolver failed.');
|
|
223
|
+
* },
|
|
224
|
+
* },
|
|
225
|
+
* });
|
|
226
|
+
*
|
|
227
|
+
* result.data.broken; // => null
|
|
228
|
+
* result.errors[0].message; // => 'Resolver failed.'
|
|
229
|
+
* ```
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* // This variant limits how many variable coercion errors are reported.
|
|
233
|
+
* import { parse } from 'graphql/language';
|
|
234
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
235
|
+
* import { execute } from 'graphql/execution';
|
|
236
|
+
*
|
|
237
|
+
* const schema = buildSchema(`
|
|
238
|
+
* input ReviewInput {
|
|
239
|
+
* stars: Int!
|
|
240
|
+
* }
|
|
241
|
+
*
|
|
242
|
+
* type Query {
|
|
243
|
+
* review(input: ReviewInput!): String
|
|
244
|
+
* }
|
|
245
|
+
* `);
|
|
246
|
+
* const document = parse(`
|
|
247
|
+
* query ($first: ReviewInput!, $second: ReviewInput!) {
|
|
248
|
+
* first: review(input: $first)
|
|
249
|
+
* second: review(input: $second)
|
|
250
|
+
* }
|
|
251
|
+
* `);
|
|
252
|
+
*
|
|
253
|
+
* const result = await execute({
|
|
254
|
+
* schema,
|
|
255
|
+
* document,
|
|
256
|
+
* variableValues: {
|
|
257
|
+
* first: { stars: 'bad' },
|
|
258
|
+
* second: { stars: 'also bad' },
|
|
259
|
+
* },
|
|
260
|
+
* options: { maxCoercionErrors: 1 },
|
|
261
|
+
* });
|
|
262
|
+
*
|
|
263
|
+
* result.errors.length; // => 2
|
|
264
|
+
* result.errors[1].message; // matches /error limit reached/
|
|
265
|
+
* ```
|
|
133
266
|
*/
|
|
134
267
|
export function execute(args) {
|
|
135
268
|
// Temporary for v15 to v16 migration. Remove in v17
|
|
@@ -149,17 +282,7 @@ export function execute(args) {
|
|
|
149
282
|
return {
|
|
150
283
|
errors: exeContext,
|
|
151
284
|
};
|
|
152
|
-
}
|
|
153
|
-
// The "Response" section of the GraphQL specification.
|
|
154
|
-
//
|
|
155
|
-
// If errors are encountered while executing a GraphQL field, only that
|
|
156
|
-
// field and its descendants will be omitted, and sibling fields will still
|
|
157
|
-
// be executed. An execution which encounters errors will still result in a
|
|
158
|
-
// resolved Promise.
|
|
159
|
-
//
|
|
160
|
-
// Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
161
|
-
// at which point we still log the error and null the parent field, which
|
|
162
|
-
// in this case is the entire response.
|
|
285
|
+
}
|
|
163
286
|
|
|
164
287
|
try {
|
|
165
288
|
const { operation } = exeContext;
|
|
@@ -185,6 +308,53 @@ export function execute(args) {
|
|
|
185
308
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
|
186
309
|
* However, it guarantees to complete synchronously (or throw an error) assuming
|
|
187
310
|
* that all field resolvers are also synchronous.
|
|
311
|
+
* @param args - The arguments used to perform the operation.
|
|
312
|
+
* @returns Completed execution output for a synchronous operation.
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* // Execute an operation synchronously when all resolvers are synchronous.
|
|
316
|
+
* import { parse } from 'graphql/language';
|
|
317
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
318
|
+
* import { executeSync } from 'graphql/execution';
|
|
319
|
+
*
|
|
320
|
+
* const schema = buildSchema(`
|
|
321
|
+
* type Query {
|
|
322
|
+
* greeting: String
|
|
323
|
+
* }
|
|
324
|
+
* `);
|
|
325
|
+
* const document = parse('{ greeting }');
|
|
326
|
+
*
|
|
327
|
+
* const result = executeSync({
|
|
328
|
+
* schema,
|
|
329
|
+
* document,
|
|
330
|
+
* rootValue: {
|
|
331
|
+
* greeting: 'Hello',
|
|
332
|
+
* },
|
|
333
|
+
* });
|
|
334
|
+
*
|
|
335
|
+
* result; // => { data: { greeting: 'Hello' } }
|
|
336
|
+
* ```
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* // This variant shows executeSync throwing when a resolver returns a promise.
|
|
340
|
+
* import { parse } from 'graphql/language';
|
|
341
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
342
|
+
* import { executeSync } from 'graphql/execution';
|
|
343
|
+
*
|
|
344
|
+
* const schema = buildSchema(`
|
|
345
|
+
* type Query {
|
|
346
|
+
* greeting: String
|
|
347
|
+
* }
|
|
348
|
+
* `);
|
|
349
|
+
*
|
|
350
|
+
* executeSync({
|
|
351
|
+
* schema,
|
|
352
|
+
* document: parse('{ greeting }'),
|
|
353
|
+
* rootValue: {
|
|
354
|
+
* greeting: async () => 'Hello',
|
|
355
|
+
* },
|
|
356
|
+
* }); // throws an error
|
|
357
|
+
* ```
|
|
188
358
|
*/
|
|
189
359
|
|
|
190
360
|
export function executeSync(args) {
|
|
@@ -199,6 +369,8 @@ export function executeSync(args) {
|
|
|
199
369
|
/**
|
|
200
370
|
* Given a completed execution context and data, build the `{ errors, data }`
|
|
201
371
|
* response defined by the "Response" section of the GraphQL specification.
|
|
372
|
+
*
|
|
373
|
+
* @internal
|
|
202
374
|
*/
|
|
203
375
|
|
|
204
376
|
function buildResponse(data, errors) {
|
|
@@ -213,7 +385,9 @@ function buildResponse(data, errors) {
|
|
|
213
385
|
}
|
|
214
386
|
/**
|
|
215
387
|
* Essential assertions before executing to provide developer feedback for
|
|
216
|
-
* improper use of the GraphQL library.
|
|
388
|
+
* improper use of the GraphQL library. This deprecated internal helper will be
|
|
389
|
+
* removed in v17; call `assertValidSchema()` and rely on TypeScript checks
|
|
390
|
+
* instead.
|
|
217
391
|
*
|
|
218
392
|
* @deprecated will be removed in v17 in favor of assertValidSchema() and TS checks
|
|
219
393
|
* @internal
|
|
@@ -355,6 +529,8 @@ export function buildExecutionContext(args) {
|
|
|
355
529
|
}
|
|
356
530
|
/**
|
|
357
531
|
* Implements the "Executing operations" section of the spec.
|
|
532
|
+
*
|
|
533
|
+
* @internal
|
|
358
534
|
*/
|
|
359
535
|
|
|
360
536
|
function executeOperation(exeContext, operation, rootValue) {
|
|
@@ -400,6 +576,8 @@ function executeOperation(exeContext, operation, rootValue) {
|
|
|
400
576
|
/**
|
|
401
577
|
* Implements the "Executing selection sets" section of the spec
|
|
402
578
|
* for fields that must be executed serially.
|
|
579
|
+
*
|
|
580
|
+
* @internal
|
|
403
581
|
*/
|
|
404
582
|
|
|
405
583
|
function executeFieldsSerially(
|
|
@@ -441,6 +619,8 @@ function executeFieldsSerially(
|
|
|
441
619
|
/**
|
|
442
620
|
* Implements the "Executing selection sets" section of the spec
|
|
443
621
|
* for fields that may be executed in parallel.
|
|
622
|
+
*
|
|
623
|
+
* @internal
|
|
444
624
|
*/
|
|
445
625
|
|
|
446
626
|
function executeFields(exeContext, parentType, sourceValue, path, fields) {
|
|
@@ -490,6 +670,8 @@ function executeFields(exeContext, parentType, sourceValue, path, fields) {
|
|
|
490
670
|
* In particular, this function figures out the value that the field returns by
|
|
491
671
|
* calling its resolve function, then calls completeValue to complete promises,
|
|
492
672
|
* serialize scalars, or execute the sub-selection-set for objects.
|
|
673
|
+
*
|
|
674
|
+
* @internal
|
|
493
675
|
*/
|
|
494
676
|
|
|
495
677
|
function executeField(exeContext, parentType, source, fieldNodes, path) {
|
|
@@ -561,9 +743,7 @@ function executeField(exeContext, parentType, source, fieldNodes, path) {
|
|
|
561
743
|
return handleFieldError(error, returnType, path, exeContext);
|
|
562
744
|
}
|
|
563
745
|
}
|
|
564
|
-
/**
|
|
565
|
-
* @internal
|
|
566
|
-
*/
|
|
746
|
+
/** @internal */
|
|
567
747
|
|
|
568
748
|
export function buildResolveInfo(
|
|
569
749
|
exeContext,
|
|
@@ -619,6 +799,8 @@ function handleFieldError(error, returnType, path, exeContext) {
|
|
|
619
799
|
*
|
|
620
800
|
* Otherwise, the field type expects a sub-selection set, and will complete the
|
|
621
801
|
* value by executing all sub-selections.
|
|
802
|
+
*
|
|
803
|
+
* @internal
|
|
622
804
|
*/
|
|
623
805
|
|
|
624
806
|
function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
@@ -701,6 +883,8 @@ function completeValue(exeContext, returnType, fieldNodes, info, path, result) {
|
|
|
701
883
|
/**
|
|
702
884
|
* Complete a list value by completing each item in the list with the
|
|
703
885
|
* inner type
|
|
886
|
+
*
|
|
887
|
+
* @internal
|
|
704
888
|
*/
|
|
705
889
|
|
|
706
890
|
function completeListValue(
|
|
@@ -775,6 +959,8 @@ function completeListValue(
|
|
|
775
959
|
/**
|
|
776
960
|
* Complete a Scalar or Enum by serializing to a valid value, returning
|
|
777
961
|
* null if serialization is not possible.
|
|
962
|
+
*
|
|
963
|
+
* @internal
|
|
778
964
|
*/
|
|
779
965
|
|
|
780
966
|
function completeLeafValue(returnType, result) {
|
|
@@ -792,6 +978,8 @@ function completeLeafValue(returnType, result) {
|
|
|
792
978
|
/**
|
|
793
979
|
* Complete a value of an abstract type by determining the runtime object type
|
|
794
980
|
* of that value, then complete the value for that type.
|
|
981
|
+
*
|
|
982
|
+
* @internal
|
|
795
983
|
*/
|
|
796
984
|
|
|
797
985
|
function completeAbstractValue(
|
|
@@ -911,6 +1099,8 @@ function ensureValidRuntimeType(
|
|
|
911
1099
|
}
|
|
912
1100
|
/**
|
|
913
1101
|
* Complete an Object value by executing all sub-selections.
|
|
1102
|
+
*
|
|
1103
|
+
* @internal
|
|
914
1104
|
*/
|
|
915
1105
|
|
|
916
1106
|
function completeObjectValue(
|
package/execution/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute GraphQL operations and produce GraphQL execution results.
|
|
3
|
+
*
|
|
4
|
+
* These exports are also available from the root `graphql` package.
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
1
7
|
export { pathToArray as responsePathAsArray } from '../jsutils/Path';
|
|
2
8
|
export {
|
|
3
9
|
execute,
|
package/execution/index.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute GraphQL operations and produce GraphQL execution results.
|
|
3
|
+
*
|
|
4
|
+
* These exports are also available from the root `graphql` package.
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
1
7
|
export { pathToArray as responsePathAsArray } from '../jsutils/Path.mjs';
|
|
2
8
|
export {
|
|
3
9
|
execute,
|
|
@@ -2,6 +2,8 @@ import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
|
|
|
2
2
|
/**
|
|
3
3
|
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
|
4
4
|
* which produces values mapped via calling the callback function.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
5
7
|
*/
|
|
6
8
|
export declare function mapAsyncIterator<T, U, R = undefined>(
|
|
7
9
|
iterable: AsyncGenerator<T, R, void> | AsyncIterable<T>,
|
|
@@ -8,6 +8,8 @@ exports.mapAsyncIterator = mapAsyncIterator;
|
|
|
8
8
|
/**
|
|
9
9
|
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
|
10
10
|
* which produces values mapped via calling the callback function.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
11
13
|
*/
|
|
12
14
|
function mapAsyncIterator(iterable, callback) {
|
|
13
15
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
|
3
3
|
* which produces values mapped via calling the callback function.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
4
6
|
*/
|
|
5
7
|
export function mapAsyncIterator(iterable, callback) {
|
|
6
8
|
const iterator = iterable[Symbol.asyncIterator]();
|
package/execution/subscribe.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @category Subscriptions */
|
|
1
2
|
import type { Maybe } from '../jsutils/Maybe';
|
|
2
3
|
import type { DocumentNode } from '../language/ast';
|
|
3
4
|
import type { GraphQLFieldResolver } from '../type/definition';
|
|
@@ -6,7 +7,7 @@ import type { ExecutionArgs, ExecutionResult } from './execute';
|
|
|
6
7
|
/**
|
|
7
8
|
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
8
9
|
*
|
|
9
|
-
* Returns a Promise
|
|
10
|
+
* Returns a Promise that resolves to either an AsyncIterator (if successful)
|
|
10
11
|
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
11
12
|
* other arguments to this function are invalid, or if the resolved event stream
|
|
12
13
|
* is not an async iterable.
|
|
@@ -22,7 +23,122 @@ import type { ExecutionArgs, ExecutionResult } from './execute';
|
|
|
22
23
|
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
23
24
|
* yields a stream of ExecutionResults representing the response stream.
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
+
* Each payload yielded by the source event stream is executed with the payload
|
|
27
|
+
* as the root value. This maps the subscription source stream into the response
|
|
28
|
+
* stream described by the GraphQL specification.
|
|
29
|
+
*
|
|
30
|
+
* Accepts an object with named arguments.
|
|
31
|
+
* @param args - The arguments used to perform the operation.
|
|
32
|
+
* @returns A source stream mapped to execution results, or an execution result
|
|
33
|
+
* containing subscription errors.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Use a same-named rootValue function to provide the source event stream.
|
|
37
|
+
* import assert from 'node:assert';
|
|
38
|
+
* import { parse } from 'graphql/language';
|
|
39
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
40
|
+
* import { subscribe } from 'graphql/execution';
|
|
41
|
+
*
|
|
42
|
+
* async function* greetings() {
|
|
43
|
+
* yield { greeting: 'Hello' };
|
|
44
|
+
* yield { greeting: 'Bonjour' };
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* const schema = buildSchema(`
|
|
48
|
+
* type Query {
|
|
49
|
+
* noop: String
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* type Subscription {
|
|
53
|
+
* greeting: String
|
|
54
|
+
* }
|
|
55
|
+
* `);
|
|
56
|
+
*
|
|
57
|
+
* const result = await subscribe({
|
|
58
|
+
* schema,
|
|
59
|
+
* document: parse('subscription { greeting }'),
|
|
60
|
+
* rootValue: { greeting: () => greetings() },
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* assert('next' in result);
|
|
64
|
+
*
|
|
65
|
+
* const firstPayload = await result.next();
|
|
66
|
+
* firstPayload.value; // => { data: { greeting: 'Hello' } }
|
|
67
|
+
* ```
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // This variant supplies events through a custom subscribeFieldResolver.
|
|
71
|
+
* import assert from 'node:assert';
|
|
72
|
+
* import { parse } from 'graphql/language';
|
|
73
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
74
|
+
* import { subscribe } from 'graphql/execution';
|
|
75
|
+
*
|
|
76
|
+
* async function* defaultGreetings() {
|
|
77
|
+
* yield { greeting: 'Hello' };
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* async function* frenchGreetings() {
|
|
81
|
+
* yield { greeting: 'Bonjour' };
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* const schema = buildSchema(`
|
|
85
|
+
* type Query {
|
|
86
|
+
* noop: String
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* type Subscription {
|
|
90
|
+
* greeting(locale: String): String
|
|
91
|
+
* }
|
|
92
|
+
* `);
|
|
93
|
+
*
|
|
94
|
+
* const result = await subscribe({
|
|
95
|
+
* schema,
|
|
96
|
+
* document: parse(
|
|
97
|
+
* 'subscription Greeting($locale: String) { greeting(locale: $locale) }',
|
|
98
|
+
* ),
|
|
99
|
+
* rootValue: {
|
|
100
|
+
* greeting: (args, contextValue) => {
|
|
101
|
+
* const locale = args.locale ?? contextValue.defaultLocale;
|
|
102
|
+
* return locale === 'fr' ? frenchGreetings() : defaultGreetings();
|
|
103
|
+
* },
|
|
104
|
+
* },
|
|
105
|
+
* contextValue: { defaultLocale: 'fr' },
|
|
106
|
+
* variableValues: { locale: 'fr' },
|
|
107
|
+
* operationName: 'Greeting',
|
|
108
|
+
* subscribeFieldResolver: (rootValue, args, contextValue, info) => {
|
|
109
|
+
* args.locale; // => 'fr'
|
|
110
|
+
* return rootValue[info.fieldName](args, contextValue);
|
|
111
|
+
* },
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* assert('next' in result);
|
|
115
|
+
*
|
|
116
|
+
* const firstPayload = await result.next();
|
|
117
|
+
* firstPayload.value; // => { data: { greeting: 'Bonjour' } }
|
|
118
|
+
* ```
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* // This variant shows the error result when the schema has no subscription root.
|
|
122
|
+
* import assert from 'node:assert';
|
|
123
|
+
* import { parse } from 'graphql/language';
|
|
124
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
125
|
+
* import { subscribe } from 'graphql/execution';
|
|
126
|
+
*
|
|
127
|
+
* const schema = buildSchema(`
|
|
128
|
+
* type Query {
|
|
129
|
+
* noop: String
|
|
130
|
+
* }
|
|
131
|
+
* `);
|
|
132
|
+
*
|
|
133
|
+
* const result = await subscribe({
|
|
134
|
+
* schema,
|
|
135
|
+
* document: parse('subscription { greeting }'),
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* assert('errors' in result);
|
|
139
|
+
*
|
|
140
|
+
* result.errors[0].message; // => 'Schema is not configured to execute subscription operation.'
|
|
141
|
+
* ```
|
|
26
142
|
*/
|
|
27
143
|
export declare function subscribe(
|
|
28
144
|
args: ExecutionArgs,
|
|
@@ -31,7 +147,7 @@ export declare function subscribe(
|
|
|
31
147
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
32
148
|
* GraphQL specification, resolving the subscription source event stream.
|
|
33
149
|
*
|
|
34
|
-
* Returns a Promise
|
|
150
|
+
* Returns a Promise that resolves to either an AsyncIterable (if successful)
|
|
35
151
|
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
36
152
|
* other arguments to this function are invalid, or if the resolved event stream
|
|
37
153
|
* is not an async iterable.
|
|
@@ -40,7 +156,7 @@ export declare function subscribe(
|
|
|
40
156
|
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
41
157
|
* descriptive errors and no data will be returned.
|
|
42
158
|
*
|
|
43
|
-
* If the
|
|
159
|
+
* If the source stream could not be created due to faulty subscription
|
|
44
160
|
* resolver logic or underlying systems, the promise will resolve to a single
|
|
45
161
|
* ExecutionResult containing `errors` and no `data`.
|
|
46
162
|
*
|
|
@@ -54,11 +170,85 @@ export declare function subscribe(
|
|
|
54
170
|
* different process or machine than the stateless GraphQL execution engine,
|
|
55
171
|
* or otherwise separating these two steps. For more on this, see the
|
|
56
172
|
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
173
|
+
* @param args - The arguments used to perform the operation.
|
|
174
|
+
* @returns The source event stream, or an execution result containing subscription errors.
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { parse } from 'graphql/language';
|
|
178
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
179
|
+
* import { createSourceEventStream } from 'graphql/execution';
|
|
180
|
+
*
|
|
181
|
+
* async function* greetings() {
|
|
182
|
+
* yield { greeting: 'Hello' };
|
|
183
|
+
* }
|
|
184
|
+
*
|
|
185
|
+
* const schema = buildSchema(`
|
|
186
|
+
* type Query {
|
|
187
|
+
* noop: String
|
|
188
|
+
* }
|
|
189
|
+
*
|
|
190
|
+
* type Subscription {
|
|
191
|
+
* greeting: String
|
|
192
|
+
* }
|
|
193
|
+
* `);
|
|
194
|
+
*
|
|
195
|
+
* const stream = await createSourceEventStream({
|
|
196
|
+
* schema,
|
|
197
|
+
* document: parse('subscription { greeting }'),
|
|
198
|
+
* rootValue: { greeting: () => greetings() },
|
|
199
|
+
* });
|
|
200
|
+
*
|
|
201
|
+
* Symbol.asyncIterator in stream; // => true
|
|
202
|
+
* ```
|
|
57
203
|
*/
|
|
58
204
|
export declare function createSourceEventStream(
|
|
59
205
|
args: ExecutionArgs,
|
|
60
206
|
): Promise<AsyncIterable<unknown> | ExecutionResult>;
|
|
61
|
-
/**
|
|
207
|
+
/**
|
|
208
|
+
* Creates the source event stream for a subscription operation using the legacy
|
|
209
|
+
* positional argument overload. This deprecated overload will be removed in the
|
|
210
|
+
* next major version; use the args object overload instead.
|
|
211
|
+
* @param schema - GraphQL schema to use.
|
|
212
|
+
* @param document - The parsed GraphQL document containing the subscription
|
|
213
|
+
* operation.
|
|
214
|
+
* @param rootValue - Initial root value passed to the subscription resolver.
|
|
215
|
+
* @param contextValue - Application context value passed to resolvers.
|
|
216
|
+
* @param variableValues - Runtime variable values keyed by variable name.
|
|
217
|
+
* @param operationName - Name of the subscription operation to execute when
|
|
218
|
+
* the document contains multiple operations.
|
|
219
|
+
* @param subscribeFieldResolver - Resolver used for the root subscription
|
|
220
|
+
* field.
|
|
221
|
+
* @returns The source event stream, or an execution result containing
|
|
222
|
+
* subscription errors.
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* import { parse } from 'graphql/language';
|
|
226
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
227
|
+
* import { createSourceEventStream } from 'graphql/execution';
|
|
228
|
+
*
|
|
229
|
+
* async function* greetings() {
|
|
230
|
+
* yield { greeting: 'Hello' };
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* const schema = buildSchema(`
|
|
234
|
+
* type Query {
|
|
235
|
+
* noop: String
|
|
236
|
+
* }
|
|
237
|
+
*
|
|
238
|
+
* type Subscription {
|
|
239
|
+
* greeting: String
|
|
240
|
+
* }
|
|
241
|
+
* `);
|
|
242
|
+
* const document = parse('subscription { greeting }');
|
|
243
|
+
*
|
|
244
|
+
* const stream = await createSourceEventStream(schema, document, {
|
|
245
|
+
* greeting: () => greetings(),
|
|
246
|
+
* });
|
|
247
|
+
*
|
|
248
|
+
* Symbol.asyncIterator in stream; // => true
|
|
249
|
+
* ```
|
|
250
|
+
* @deprecated Will be removed in next major version in favor of named arguments.
|
|
251
|
+
*/
|
|
62
252
|
export declare function createSourceEventStream(
|
|
63
253
|
schema: GraphQLSchema,
|
|
64
254
|
document: DocumentNode,
|