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/subscribe.js
CHANGED
|
@@ -26,10 +26,12 @@ var _mapAsyncIterator = require('./mapAsyncIterator.js');
|
|
|
26
26
|
|
|
27
27
|
var _values = require('./values.js');
|
|
28
28
|
|
|
29
|
+
/** @category Subscriptions */
|
|
30
|
+
|
|
29
31
|
/**
|
|
30
32
|
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
31
33
|
*
|
|
32
|
-
* Returns a Promise
|
|
34
|
+
* Returns a Promise that resolves to either an AsyncIterator (if successful)
|
|
33
35
|
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
34
36
|
* other arguments to this function are invalid, or if the resolved event stream
|
|
35
37
|
* is not an async iterable.
|
|
@@ -45,7 +47,122 @@ var _values = require('./values.js');
|
|
|
45
47
|
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
46
48
|
* yields a stream of ExecutionResults representing the response stream.
|
|
47
49
|
*
|
|
48
|
-
*
|
|
50
|
+
* Each payload yielded by the source event stream is executed with the payload
|
|
51
|
+
* as the root value. This maps the subscription source stream into the response
|
|
52
|
+
* stream described by the GraphQL specification.
|
|
53
|
+
*
|
|
54
|
+
* Accepts an object with named arguments.
|
|
55
|
+
* @param args - The arguments used to perform the operation.
|
|
56
|
+
* @returns A source stream mapped to execution results, or an execution result
|
|
57
|
+
* containing subscription errors.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* // Use a same-named rootValue function to provide the source event stream.
|
|
61
|
+
* import assert from 'node:assert';
|
|
62
|
+
* import { parse } from 'graphql/language';
|
|
63
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
64
|
+
* import { subscribe } from 'graphql/execution';
|
|
65
|
+
*
|
|
66
|
+
* async function* greetings() {
|
|
67
|
+
* yield { greeting: 'Hello' };
|
|
68
|
+
* yield { greeting: 'Bonjour' };
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* const schema = buildSchema(`
|
|
72
|
+
* type Query {
|
|
73
|
+
* noop: String
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* type Subscription {
|
|
77
|
+
* greeting: String
|
|
78
|
+
* }
|
|
79
|
+
* `);
|
|
80
|
+
*
|
|
81
|
+
* const result = await subscribe({
|
|
82
|
+
* schema,
|
|
83
|
+
* document: parse('subscription { greeting }'),
|
|
84
|
+
* rootValue: { greeting: () => greetings() },
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* assert('next' in result);
|
|
88
|
+
*
|
|
89
|
+
* const firstPayload = await result.next();
|
|
90
|
+
* firstPayload.value; // => { data: { greeting: 'Hello' } }
|
|
91
|
+
* ```
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // This variant supplies events through a custom subscribeFieldResolver.
|
|
95
|
+
* import assert from 'node:assert';
|
|
96
|
+
* import { parse } from 'graphql/language';
|
|
97
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
98
|
+
* import { subscribe } from 'graphql/execution';
|
|
99
|
+
*
|
|
100
|
+
* async function* defaultGreetings() {
|
|
101
|
+
* yield { greeting: 'Hello' };
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* async function* frenchGreetings() {
|
|
105
|
+
* yield { greeting: 'Bonjour' };
|
|
106
|
+
* }
|
|
107
|
+
*
|
|
108
|
+
* const schema = buildSchema(`
|
|
109
|
+
* type Query {
|
|
110
|
+
* noop: String
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* type Subscription {
|
|
114
|
+
* greeting(locale: String): String
|
|
115
|
+
* }
|
|
116
|
+
* `);
|
|
117
|
+
*
|
|
118
|
+
* const result = await subscribe({
|
|
119
|
+
* schema,
|
|
120
|
+
* document: parse(
|
|
121
|
+
* 'subscription Greeting($locale: String) { greeting(locale: $locale) }',
|
|
122
|
+
* ),
|
|
123
|
+
* rootValue: {
|
|
124
|
+
* greeting: (args, contextValue) => {
|
|
125
|
+
* const locale = args.locale ?? contextValue.defaultLocale;
|
|
126
|
+
* return locale === 'fr' ? frenchGreetings() : defaultGreetings();
|
|
127
|
+
* },
|
|
128
|
+
* },
|
|
129
|
+
* contextValue: { defaultLocale: 'fr' },
|
|
130
|
+
* variableValues: { locale: 'fr' },
|
|
131
|
+
* operationName: 'Greeting',
|
|
132
|
+
* subscribeFieldResolver: (rootValue, args, contextValue, info) => {
|
|
133
|
+
* args.locale; // => 'fr'
|
|
134
|
+
* return rootValue[info.fieldName](args, contextValue);
|
|
135
|
+
* },
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* assert('next' in result);
|
|
139
|
+
*
|
|
140
|
+
* const firstPayload = await result.next();
|
|
141
|
+
* firstPayload.value; // => { data: { greeting: 'Bonjour' } }
|
|
142
|
+
* ```
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* // This variant shows the error result when the schema has no subscription root.
|
|
146
|
+
* import assert from 'node:assert';
|
|
147
|
+
* import { parse } from 'graphql/language';
|
|
148
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
149
|
+
* import { subscribe } from 'graphql/execution';
|
|
150
|
+
*
|
|
151
|
+
* const schema = buildSchema(`
|
|
152
|
+
* type Query {
|
|
153
|
+
* noop: String
|
|
154
|
+
* }
|
|
155
|
+
* `);
|
|
156
|
+
*
|
|
157
|
+
* const result = await subscribe({
|
|
158
|
+
* schema,
|
|
159
|
+
* document: parse('subscription { greeting }'),
|
|
160
|
+
* });
|
|
161
|
+
*
|
|
162
|
+
* assert('errors' in result);
|
|
163
|
+
*
|
|
164
|
+
* result.errors[0].message; // => 'Schema is not configured to execute subscription operation.'
|
|
165
|
+
* ```
|
|
49
166
|
*/
|
|
50
167
|
async function subscribe(args) {
|
|
51
168
|
// Temporary for v15 to v16 migration. Remove in v17
|
|
@@ -58,15 +175,10 @@ async function subscribe(args) {
|
|
|
58
175
|
|
|
59
176
|
if (!(0, _isAsyncIterable.isAsyncIterable)(resultOrStream)) {
|
|
60
177
|
return resultOrStream;
|
|
61
|
-
}
|
|
62
|
-
// GraphQL `execute` function, with `payload` as the rootValue.
|
|
63
|
-
// This implements the "MapSourceToResponseEvent" algorithm described in
|
|
64
|
-
// the GraphQL specification. The `execute` function provides the
|
|
65
|
-
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
66
|
-
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
178
|
+
}
|
|
67
179
|
|
|
68
180
|
const mapSourceToResponse = (payload) =>
|
|
69
|
-
(0, _execute.execute)({ ...args, rootValue: payload });
|
|
181
|
+
(0, _execute.execute)({ ...args, rootValue: payload });
|
|
70
182
|
|
|
71
183
|
return (0, _mapAsyncIterator.mapAsyncIterator)(
|
|
72
184
|
resultOrStream,
|
|
@@ -96,7 +208,7 @@ function toNormalizedArgs(args) {
|
|
|
96
208
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
97
209
|
* GraphQL specification, resolving the subscription source event stream.
|
|
98
210
|
*
|
|
99
|
-
* Returns a Promise
|
|
211
|
+
* Returns a Promise that resolves to either an AsyncIterable (if successful)
|
|
100
212
|
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
101
213
|
* other arguments to this function are invalid, or if the resolved event stream
|
|
102
214
|
* is not an async iterable.
|
|
@@ -105,7 +217,7 @@ function toNormalizedArgs(args) {
|
|
|
105
217
|
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
106
218
|
* descriptive errors and no data will be returned.
|
|
107
219
|
*
|
|
108
|
-
* If the
|
|
220
|
+
* If the source stream could not be created due to faulty subscription
|
|
109
221
|
* resolver logic or underlying systems, the promise will resolve to a single
|
|
110
222
|
* ExecutionResult containing `errors` and no `data`.
|
|
111
223
|
*
|
|
@@ -119,8 +231,39 @@ function toNormalizedArgs(args) {
|
|
|
119
231
|
* different process or machine than the stateless GraphQL execution engine,
|
|
120
232
|
* or otherwise separating these two steps. For more on this, see the
|
|
121
233
|
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
234
|
+
* @param args - The arguments used to perform the operation.
|
|
235
|
+
* @returns The source event stream, or an execution result containing subscription errors.
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { parse } from 'graphql/language';
|
|
239
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
240
|
+
* import { createSourceEventStream } from 'graphql/execution';
|
|
241
|
+
*
|
|
242
|
+
* async function* greetings() {
|
|
243
|
+
* yield { greeting: 'Hello' };
|
|
244
|
+
* }
|
|
245
|
+
*
|
|
246
|
+
* const schema = buildSchema(`
|
|
247
|
+
* type Query {
|
|
248
|
+
* noop: String
|
|
249
|
+
* }
|
|
250
|
+
*
|
|
251
|
+
* type Subscription {
|
|
252
|
+
* greeting: String
|
|
253
|
+
* }
|
|
254
|
+
* `);
|
|
255
|
+
*
|
|
256
|
+
* const stream = await createSourceEventStream({
|
|
257
|
+
* schema,
|
|
258
|
+
* document: parse('subscription { greeting }'),
|
|
259
|
+
* rootValue: { greeting: () => greetings() },
|
|
260
|
+
* });
|
|
261
|
+
*
|
|
262
|
+
* Symbol.asyncIterator in stream; // => true
|
|
263
|
+
* ```
|
|
122
264
|
*/
|
|
123
265
|
|
|
266
|
+
/** @internal */
|
|
124
267
|
async function createSourceEventStream(...rawArgs) {
|
|
125
268
|
const args = toNormalizedArgs(rawArgs);
|
|
126
269
|
const { schema, document, variableValues } = args; // If arguments are missing or incorrectly typed, this is an internal
|
package/execution/subscribe.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @category Subscriptions */
|
|
1
2
|
import { devAssert } from '../jsutils/devAssert.mjs';
|
|
2
3
|
import { inspect } from '../jsutils/inspect.mjs';
|
|
3
4
|
import { isAsyncIterable } from '../jsutils/isAsyncIterable.mjs';
|
|
@@ -18,7 +19,7 @@ import { getArgumentValues } from './values.mjs';
|
|
|
18
19
|
/**
|
|
19
20
|
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
20
21
|
*
|
|
21
|
-
* Returns a Promise
|
|
22
|
+
* Returns a Promise that resolves to either an AsyncIterator (if successful)
|
|
22
23
|
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
23
24
|
* other arguments to this function are invalid, or if the resolved event stream
|
|
24
25
|
* is not an async iterable.
|
|
@@ -34,7 +35,122 @@ import { getArgumentValues } from './values.mjs';
|
|
|
34
35
|
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
35
36
|
* yields a stream of ExecutionResults representing the response stream.
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
+
* Each payload yielded by the source event stream is executed with the payload
|
|
39
|
+
* as the root value. This maps the subscription source stream into the response
|
|
40
|
+
* stream described by the GraphQL specification.
|
|
41
|
+
*
|
|
42
|
+
* Accepts an object with named arguments.
|
|
43
|
+
* @param args - The arguments used to perform the operation.
|
|
44
|
+
* @returns A source stream mapped to execution results, or an execution result
|
|
45
|
+
* containing subscription errors.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // Use a same-named rootValue function to provide the source event stream.
|
|
49
|
+
* import assert from 'node:assert';
|
|
50
|
+
* import { parse } from 'graphql/language';
|
|
51
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
52
|
+
* import { subscribe } from 'graphql/execution';
|
|
53
|
+
*
|
|
54
|
+
* async function* greetings() {
|
|
55
|
+
* yield { greeting: 'Hello' };
|
|
56
|
+
* yield { greeting: 'Bonjour' };
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const schema = buildSchema(`
|
|
60
|
+
* type Query {
|
|
61
|
+
* noop: String
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* type Subscription {
|
|
65
|
+
* greeting: String
|
|
66
|
+
* }
|
|
67
|
+
* `);
|
|
68
|
+
*
|
|
69
|
+
* const result = await subscribe({
|
|
70
|
+
* schema,
|
|
71
|
+
* document: parse('subscription { greeting }'),
|
|
72
|
+
* rootValue: { greeting: () => greetings() },
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* assert('next' in result);
|
|
76
|
+
*
|
|
77
|
+
* const firstPayload = await result.next();
|
|
78
|
+
* firstPayload.value; // => { data: { greeting: 'Hello' } }
|
|
79
|
+
* ```
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* // This variant supplies events through a custom subscribeFieldResolver.
|
|
83
|
+
* import assert from 'node:assert';
|
|
84
|
+
* import { parse } from 'graphql/language';
|
|
85
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
86
|
+
* import { subscribe } from 'graphql/execution';
|
|
87
|
+
*
|
|
88
|
+
* async function* defaultGreetings() {
|
|
89
|
+
* yield { greeting: 'Hello' };
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* async function* frenchGreetings() {
|
|
93
|
+
* yield { greeting: 'Bonjour' };
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* const schema = buildSchema(`
|
|
97
|
+
* type Query {
|
|
98
|
+
* noop: String
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
* type Subscription {
|
|
102
|
+
* greeting(locale: String): String
|
|
103
|
+
* }
|
|
104
|
+
* `);
|
|
105
|
+
*
|
|
106
|
+
* const result = await subscribe({
|
|
107
|
+
* schema,
|
|
108
|
+
* document: parse(
|
|
109
|
+
* 'subscription Greeting($locale: String) { greeting(locale: $locale) }',
|
|
110
|
+
* ),
|
|
111
|
+
* rootValue: {
|
|
112
|
+
* greeting: (args, contextValue) => {
|
|
113
|
+
* const locale = args.locale ?? contextValue.defaultLocale;
|
|
114
|
+
* return locale === 'fr' ? frenchGreetings() : defaultGreetings();
|
|
115
|
+
* },
|
|
116
|
+
* },
|
|
117
|
+
* contextValue: { defaultLocale: 'fr' },
|
|
118
|
+
* variableValues: { locale: 'fr' },
|
|
119
|
+
* operationName: 'Greeting',
|
|
120
|
+
* subscribeFieldResolver: (rootValue, args, contextValue, info) => {
|
|
121
|
+
* args.locale; // => 'fr'
|
|
122
|
+
* return rootValue[info.fieldName](args, contextValue);
|
|
123
|
+
* },
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* assert('next' in result);
|
|
127
|
+
*
|
|
128
|
+
* const firstPayload = await result.next();
|
|
129
|
+
* firstPayload.value; // => { data: { greeting: 'Bonjour' } }
|
|
130
|
+
* ```
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* // This variant shows the error result when the schema has no subscription root.
|
|
134
|
+
* import assert from 'node:assert';
|
|
135
|
+
* import { parse } from 'graphql/language';
|
|
136
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
137
|
+
* import { subscribe } from 'graphql/execution';
|
|
138
|
+
*
|
|
139
|
+
* const schema = buildSchema(`
|
|
140
|
+
* type Query {
|
|
141
|
+
* noop: String
|
|
142
|
+
* }
|
|
143
|
+
* `);
|
|
144
|
+
*
|
|
145
|
+
* const result = await subscribe({
|
|
146
|
+
* schema,
|
|
147
|
+
* document: parse('subscription { greeting }'),
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* assert('errors' in result);
|
|
151
|
+
*
|
|
152
|
+
* result.errors[0].message; // => 'Schema is not configured to execute subscription operation.'
|
|
153
|
+
* ```
|
|
38
154
|
*/
|
|
39
155
|
|
|
40
156
|
export async function subscribe(args) {
|
|
@@ -48,15 +164,10 @@ export async function subscribe(args) {
|
|
|
48
164
|
|
|
49
165
|
if (!isAsyncIterable(resultOrStream)) {
|
|
50
166
|
return resultOrStream;
|
|
51
|
-
}
|
|
52
|
-
// GraphQL `execute` function, with `payload` as the rootValue.
|
|
53
|
-
// This implements the "MapSourceToResponseEvent" algorithm described in
|
|
54
|
-
// the GraphQL specification. The `execute` function provides the
|
|
55
|
-
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
56
|
-
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
167
|
+
}
|
|
57
168
|
|
|
58
169
|
const mapSourceToResponse = (payload) =>
|
|
59
|
-
execute({ ...args, rootValue: payload });
|
|
170
|
+
execute({ ...args, rootValue: payload });
|
|
60
171
|
|
|
61
172
|
return mapAsyncIterator(resultOrStream, mapSourceToResponse);
|
|
62
173
|
}
|
|
@@ -83,7 +194,7 @@ function toNormalizedArgs(args) {
|
|
|
83
194
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
84
195
|
* GraphQL specification, resolving the subscription source event stream.
|
|
85
196
|
*
|
|
86
|
-
* Returns a Promise
|
|
197
|
+
* Returns a Promise that resolves to either an AsyncIterable (if successful)
|
|
87
198
|
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
88
199
|
* other arguments to this function are invalid, or if the resolved event stream
|
|
89
200
|
* is not an async iterable.
|
|
@@ -92,7 +203,7 @@ function toNormalizedArgs(args) {
|
|
|
92
203
|
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
93
204
|
* descriptive errors and no data will be returned.
|
|
94
205
|
*
|
|
95
|
-
* If the
|
|
206
|
+
* If the source stream could not be created due to faulty subscription
|
|
96
207
|
* resolver logic or underlying systems, the promise will resolve to a single
|
|
97
208
|
* ExecutionResult containing `errors` and no `data`.
|
|
98
209
|
*
|
|
@@ -106,8 +217,39 @@ function toNormalizedArgs(args) {
|
|
|
106
217
|
* different process or machine than the stateless GraphQL execution engine,
|
|
107
218
|
* or otherwise separating these two steps. For more on this, see the
|
|
108
219
|
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
220
|
+
* @param args - The arguments used to perform the operation.
|
|
221
|
+
* @returns The source event stream, or an execution result containing subscription errors.
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* import { parse } from 'graphql/language';
|
|
225
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
226
|
+
* import { createSourceEventStream } from 'graphql/execution';
|
|
227
|
+
*
|
|
228
|
+
* async function* greetings() {
|
|
229
|
+
* yield { greeting: 'Hello' };
|
|
230
|
+
* }
|
|
231
|
+
*
|
|
232
|
+
* const schema = buildSchema(`
|
|
233
|
+
* type Query {
|
|
234
|
+
* noop: String
|
|
235
|
+
* }
|
|
236
|
+
*
|
|
237
|
+
* type Subscription {
|
|
238
|
+
* greeting: String
|
|
239
|
+
* }
|
|
240
|
+
* `);
|
|
241
|
+
*
|
|
242
|
+
* const stream = await createSourceEventStream({
|
|
243
|
+
* schema,
|
|
244
|
+
* document: parse('subscription { greeting }'),
|
|
245
|
+
* rootValue: { greeting: () => greetings() },
|
|
246
|
+
* });
|
|
247
|
+
*
|
|
248
|
+
* Symbol.asyncIterator in stream; // => true
|
|
249
|
+
* ```
|
|
109
250
|
*/
|
|
110
251
|
|
|
252
|
+
/** @internal */
|
|
111
253
|
export async function createSourceEventStream(...rawArgs) {
|
|
112
254
|
const args = toNormalizedArgs(rawArgs);
|
|
113
255
|
const { schema, document, variableValues } = args; // If arguments are missing or incorrectly typed, this is an internal
|
package/execution/values.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @category Values */
|
|
1
2
|
import type { Maybe } from '../jsutils/Maybe';
|
|
2
3
|
import type { ObjMap } from '../jsutils/ObjMap';
|
|
3
4
|
import { GraphQLError } from '../error/GraphQLError';
|
|
@@ -20,14 +21,91 @@ declare type CoercedVariableValues =
|
|
|
20
21
|
};
|
|
21
22
|
errors?: never;
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Options used when coercing variable values before execution.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export interface GetVariableValuesOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Maximum number of variable coercion errors before coercion stops.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
maxErrors?: number;
|
|
34
|
+
}
|
|
23
35
|
/**
|
|
24
36
|
* Prepares an object map of variableValues of the correct type based on the
|
|
25
37
|
* provided variable definitions and arbitrary input. If the input cannot be
|
|
26
|
-
* parsed to match the variable definitions,
|
|
38
|
+
* parsed to match the variable definitions, GraphQLError values are returned.
|
|
27
39
|
*
|
|
28
|
-
* Note:
|
|
40
|
+
* Note: Returned value is a plain Object with a prototype, since it is
|
|
29
41
|
* exposed to user code. Care should be taken to not pull values from the
|
|
30
42
|
* Object prototype.
|
|
43
|
+
* @param schema - GraphQL schema to use.
|
|
44
|
+
* @param varDefNodes - The variable definition AST nodes to coerce.
|
|
45
|
+
* @param inputs - The runtime variable values keyed by variable name.
|
|
46
|
+
* @param options - Optional variable coercion options, including error limits.
|
|
47
|
+
* @returns Coerced variable values, or request errors.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // Coerce provided variables and apply operation defaults.
|
|
51
|
+
* import { parse } from 'graphql/language';
|
|
52
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
53
|
+
* import { getVariableValues } from 'graphql/execution';
|
|
54
|
+
*
|
|
55
|
+
* const schema = buildSchema(`
|
|
56
|
+
* type Query {
|
|
57
|
+
* reviews(stars: Int!, limit: Int = 10): [String]
|
|
58
|
+
* }
|
|
59
|
+
* `);
|
|
60
|
+
* const document = parse(`
|
|
61
|
+
* query ($stars: Int!, $limit: Int = 10) {
|
|
62
|
+
* reviews(stars: $stars, limit: $limit)
|
|
63
|
+
* }
|
|
64
|
+
* `);
|
|
65
|
+
* const operation = document.definitions[0];
|
|
66
|
+
*
|
|
67
|
+
* const result = getVariableValues(
|
|
68
|
+
* schema,
|
|
69
|
+
* operation.variableDefinitions,
|
|
70
|
+
* { stars: '5' },
|
|
71
|
+
* );
|
|
72
|
+
*
|
|
73
|
+
* result; // => { coerced: { stars: 5, limit: 10 } }
|
|
74
|
+
* ```
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* // This variant uses maxErrors to cap reported coercion errors.
|
|
78
|
+
* import { parse } from 'graphql/language';
|
|
79
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
80
|
+
* import { getVariableValues } from 'graphql/execution';
|
|
81
|
+
*
|
|
82
|
+
* const schema = buildSchema(`
|
|
83
|
+
* input ReviewInput {
|
|
84
|
+
* stars: Int!
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* type Query {
|
|
88
|
+
* review(input: ReviewInput!): String
|
|
89
|
+
* }
|
|
90
|
+
* `);
|
|
91
|
+
* const document = parse(`
|
|
92
|
+
* query ($first: ReviewInput!, $second: ReviewInput!) {
|
|
93
|
+
* first: review(input: $first)
|
|
94
|
+
* second: review(input: $second)
|
|
95
|
+
* }
|
|
96
|
+
* `);
|
|
97
|
+
* const operation = document.definitions[0];
|
|
98
|
+
*
|
|
99
|
+
* const result = getVariableValues(
|
|
100
|
+
* schema,
|
|
101
|
+
* operation.variableDefinitions,
|
|
102
|
+
* { first: { stars: 'bad' }, second: { stars: 'also bad' } },
|
|
103
|
+
* { maxErrors: 1 },
|
|
104
|
+
* );
|
|
105
|
+
*
|
|
106
|
+
* result.errors.length; // => 2
|
|
107
|
+
* result.errors[1].message; // matches /error limit reached/
|
|
108
|
+
* ```
|
|
31
109
|
*/
|
|
32
110
|
export declare function getVariableValues(
|
|
33
111
|
schema: GraphQLSchema,
|
|
@@ -35,17 +113,56 @@ export declare function getVariableValues(
|
|
|
35
113
|
inputs: {
|
|
36
114
|
readonly [variable: string]: unknown;
|
|
37
115
|
},
|
|
38
|
-
options?:
|
|
39
|
-
maxErrors?: number;
|
|
40
|
-
},
|
|
116
|
+
options?: GetVariableValuesOptions,
|
|
41
117
|
): CoercedVariableValues;
|
|
42
118
|
/**
|
|
43
119
|
* Prepares an object map of argument values given a list of argument
|
|
44
120
|
* definitions and list of argument AST nodes.
|
|
45
121
|
*
|
|
46
|
-
* Note:
|
|
122
|
+
* Note: Returned value is a plain Object with a prototype, since it is
|
|
47
123
|
* exposed to user code. Care should be taken to not pull values from the
|
|
48
124
|
* Object prototype.
|
|
125
|
+
* @param def - The field or directive definition whose arguments should be coerced.
|
|
126
|
+
* @param node - The AST node to inspect.
|
|
127
|
+
* @param variableValues - The runtime variable values keyed by variable name.
|
|
128
|
+
* @returns Coerced argument values keyed by argument name.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* // Read literal argument values and defaults.
|
|
132
|
+
* import { parse } from 'graphql/language';
|
|
133
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
134
|
+
* import { getArgumentValues } from 'graphql/execution';
|
|
135
|
+
*
|
|
136
|
+
* const schema = buildSchema(`
|
|
137
|
+
* type Query {
|
|
138
|
+
* reviews(stars: Int!, limit: Int = 10): [String]
|
|
139
|
+
* }
|
|
140
|
+
* `);
|
|
141
|
+
* const fieldDef = schema.getQueryType().getFields().reviews;
|
|
142
|
+
* const document = parse('{ reviews(stars: 5) }');
|
|
143
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
144
|
+
*
|
|
145
|
+
* getArgumentValues(fieldDef, fieldNode); // => { stars: 5, limit: 10 }
|
|
146
|
+
* ```
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* // This variant resolves argument values from operation variables.
|
|
150
|
+
* import { parse } from 'graphql/language';
|
|
151
|
+
* import { buildSchema } from 'graphql/utilities';
|
|
152
|
+
* import { getArgumentValues } from 'graphql/execution';
|
|
153
|
+
*
|
|
154
|
+
* const schema = buildSchema(`
|
|
155
|
+
* type Query {
|
|
156
|
+
* reviews(stars: Int!): [String]
|
|
157
|
+
* }
|
|
158
|
+
* `);
|
|
159
|
+
* const fieldDef = schema.getQueryType().getFields().reviews;
|
|
160
|
+
* const document = parse('query ($stars: Int!) { reviews(stars: $stars) }');
|
|
161
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
162
|
+
*
|
|
163
|
+
* getArgumentValues(fieldDef, fieldNode, { stars: 5 }); // => { stars: 5 }
|
|
164
|
+
* getArgumentValues(fieldDef, fieldNode, {}); // throws an error
|
|
165
|
+
* ```
|
|
49
166
|
*/
|
|
50
167
|
export declare function getArgumentValues(
|
|
51
168
|
def: GraphQLField<unknown, unknown> | GraphQLDirective,
|
|
@@ -54,6 +171,17 @@ export declare function getArgumentValues(
|
|
|
54
171
|
): {
|
|
55
172
|
[argument: string]: unknown;
|
|
56
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* AST node shape accepted by getDirectiveValues.
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
export interface DirectiveValuesNode {
|
|
179
|
+
/**
|
|
180
|
+
* Directives attached to the AST node.
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
readonly directives?: ReadonlyArray<DirectiveNode>;
|
|
184
|
+
}
|
|
57
185
|
/**
|
|
58
186
|
* Prepares an object map of argument values given a directive definition
|
|
59
187
|
* and a AST node which may contain directives. Optionally also accepts a map
|
|
@@ -61,15 +189,44 @@ export declare function getArgumentValues(
|
|
|
61
189
|
*
|
|
62
190
|
* If the directive does not exist on the node, returns undefined.
|
|
63
191
|
*
|
|
64
|
-
* Note:
|
|
192
|
+
* Note: Returned value is a plain Object with a prototype, since it is
|
|
65
193
|
* exposed to user code. Care should be taken to not pull values from the
|
|
66
194
|
* Object prototype.
|
|
195
|
+
* @param directiveDef - The directive definition whose arguments should be coerced.
|
|
196
|
+
* @param node - The AST node to inspect.
|
|
197
|
+
* @param variableValues - The runtime variable values keyed by variable name.
|
|
198
|
+
* @returns Coerced directive argument values keyed by argument name.
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* // Read literal directive arguments from a node.
|
|
202
|
+
* import { parse } from 'graphql/language';
|
|
203
|
+
* import { GraphQLSkipDirective } from 'graphql/type';
|
|
204
|
+
* import { getDirectiveValues } from 'graphql/execution';
|
|
205
|
+
*
|
|
206
|
+
* const document = parse('{ name @skip(if: true) }');
|
|
207
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
208
|
+
*
|
|
209
|
+
* getDirectiveValues(GraphQLSkipDirective, fieldNode); // => { if: true }
|
|
210
|
+
* ```
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* // This variant resolves directive arguments from variables and handles absent directives.
|
|
214
|
+
* import { parse } from 'graphql/language';
|
|
215
|
+
* import { GraphQLIncludeDirective } from 'graphql/type';
|
|
216
|
+
* import { getDirectiveValues } from 'graphql/execution';
|
|
217
|
+
*
|
|
218
|
+
* const document = parse('query ($includeName: Boolean!) { name @include(if: $includeName) }');
|
|
219
|
+
* const fieldNode = document.definitions[0].selectionSet.selections[0];
|
|
220
|
+
*
|
|
221
|
+
* getDirectiveValues(GraphQLIncludeDirective, fieldNode, {
|
|
222
|
+
* includeName: false,
|
|
223
|
+
* }); // => { if: false }
|
|
224
|
+
* getDirectiveValues(GraphQLIncludeDirective, { directives: [] }); // => undefined
|
|
225
|
+
* ```
|
|
67
226
|
*/
|
|
68
227
|
export declare function getDirectiveValues(
|
|
69
228
|
directiveDef: GraphQLDirective,
|
|
70
|
-
node:
|
|
71
|
-
readonly directives?: ReadonlyArray<DirectiveNode>;
|
|
72
|
-
},
|
|
229
|
+
node: DirectiveValuesNode,
|
|
73
230
|
variableValues?: Maybe<ObjMap<unknown>>,
|
|
74
231
|
):
|
|
75
232
|
| undefined
|