graphql 14.4.2 → 14.5.3
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/README.md +5 -10
- package/error/GraphQLError.d.ts +87 -0
- package/error/GraphQLError.js +7 -45
- package/error/GraphQLError.js.flow +1 -0
- package/error/GraphQLError.mjs +7 -45
- package/error/formatError.d.ts +39 -0
- package/error/formatError.js +5 -2
- package/error/formatError.js.flow +27 -3
- package/error/formatError.mjs +5 -2
- package/error/index.d.ts +4 -0
- package/error/locatedError.d.ts +13 -0
- package/error/locatedError.js.flow +2 -1
- package/error/locatedError.mjs +1 -1
- package/error/syntaxError.d.ts +12 -0
- package/error/syntaxError.js.flow +1 -0
- package/execution/execute.d.ts +190 -0
- package/execution/execute.js +55 -89
- package/execution/execute.js.flow +95 -133
- package/execution/execute.mjs +75 -80
- package/execution/index.d.ts +11 -0
- package/execution/index.js +8 -6
- package/execution/index.js.flow +3 -6
- package/execution/index.mjs +2 -1
- package/execution/values.d.ts +68 -0
- package/execution/values.js +119 -128
- package/execution/values.js.flow +150 -127
- package/execution/values.mjs +117 -125
- package/graphql.d.ts +88 -0
- package/graphql.js +5 -5
- package/graphql.js.flow +9 -5
- package/graphql.mjs +41 -1
- package/index.d.ts +446 -0
- package/index.js +6 -0
- package/index.js.flow +3 -1
- package/index.mjs +2 -1
- package/jsutils/ObjMap.js.flow +6 -0
- package/jsutils/Path.d.ts +14 -0
- package/jsutils/Path.js +33 -0
- package/jsutils/Path.js.flow +26 -0
- package/jsutils/Path.mjs +24 -0
- package/jsutils/PromiseOrValue.d.ts +1 -0
- package/jsutils/dedent.js +6 -24
- package/jsutils/dedent.mjs +6 -24
- package/jsutils/defineToStringTag.js.flow +1 -1
- package/jsutils/devAssert.js +14 -0
- package/jsutils/devAssert.js.flow +8 -0
- package/jsutils/devAssert.mjs +7 -0
- package/jsutils/inspect.js +1 -1
- package/jsutils/inspect.js.flow +1 -1
- package/jsutils/inspect.mjs +1 -1
- package/jsutils/invariant.js +1 -2
- package/jsutils/invariant.js.flow +2 -3
- package/jsutils/invariant.mjs +1 -2
- package/jsutils/mapValue.js +6 -24
- package/jsutils/mapValue.js.flow +2 -1
- package/jsutils/mapValue.mjs +6 -24
- package/jsutils/printPathArray.js +15 -0
- package/jsutils/printPathArray.js.flow +14 -0
- package/jsutils/printPathArray.mjs +8 -0
- package/jsutils/suggestionList.js +14 -34
- package/jsutils/suggestionList.js.flow +4 -6
- package/jsutils/suggestionList.mjs +14 -34
- package/jsutils/toObjMap.js +28 -0
- package/jsutils/toObjMap.js.flow +26 -0
- package/jsutils/toObjMap.mjs +18 -0
- package/language/ast.d.ts +573 -0
- package/language/blockString.d.ts +21 -0
- package/language/directiveLocation.d.ts +35 -0
- package/language/index.d.ts +96 -0
- package/language/kinds.d.ts +77 -0
- package/language/lexer.d.ts +60 -0
- package/language/lexer.js +2 -12
- package/language/lexer.js.flow +6 -12
- package/language/lexer.mjs +1 -9
- package/language/location.d.ts +15 -0
- package/language/parser.d.ts +89 -0
- package/language/parser.js +1329 -1302
- package/language/parser.js.flow +1289 -1298
- package/language/parser.mjs +1326 -1297
- package/language/predicates.d.ts +36 -0
- package/language/predicates.js.flow +1 -1
- package/language/printLocation.d.ts +16 -0
- package/language/printLocation.js.flow +1 -1
- package/language/printer.d.ts +7 -0
- package/language/printer.js.flow +1 -1
- package/language/source.d.ts +19 -0
- package/language/source.js +3 -3
- package/language/source.js.flow +3 -3
- package/language/source.mjs +3 -3
- package/language/tokenKind.d.ts +35 -0
- package/language/visitor.d.ts +264 -0
- package/language/visitor.js +2 -2
- package/language/visitor.js.flow +3 -1
- package/language/visitor.mjs +2 -2
- package/package.json +1 -1
- package/polyfills/find.js +2 -2
- package/polyfills/find.js.flow +1 -2
- package/polyfills/find.mjs +2 -2
- package/polyfills/flatMap.js +3 -3
- package/polyfills/flatMap.js.flow +2 -3
- package/polyfills/flatMap.mjs +3 -3
- package/subscription/asyncIteratorReject.d.ts +6 -0
- package/subscription/index.d.ts +5 -0
- package/subscription/mapAsyncIterator.d.ts +9 -0
- package/subscription/mapAsyncIterator.js.flow +1 -0
- package/subscription/subscribe.d.ts +86 -0
- package/subscription/subscribe.js +29 -10
- package/subscription/subscribe.js.flow +45 -24
- package/subscription/subscribe.mjs +27 -9
- package/tsutils/Maybe.d.ts +4 -0
- package/type/definition.d.ts +805 -0
- package/type/definition.js +154 -70
- package/type/definition.js.flow +217 -160
- package/type/definition.mjs +149 -66
- package/type/directives.d.ts +72 -0
- package/type/directives.js +20 -12
- package/type/directives.js.flow +34 -19
- package/type/directives.mjs +17 -10
- package/type/index.d.ts +155 -0
- package/type/index.js.flow +2 -2
- package/type/introspection.d.ts +40 -0
- package/type/introspection.js +24 -10
- package/type/introspection.js.flow +29 -8
- package/type/introspection.mjs +23 -10
- package/type/scalars.d.ts +11 -0
- package/type/scalars.js +2 -2
- package/type/scalars.js.flow +4 -1
- package/type/scalars.mjs +2 -2
- package/type/schema.d.ts +108 -0
- package/type/schema.js +74 -151
- package/type/schema.js.flow +75 -73
- package/type/schema.mjs +75 -149
- package/type/validate.d.ts +19 -0
- package/type/validate.js +227 -486
- package/type/validate.js.flow +13 -8
- package/type/validate.mjs +218 -477
- package/utilities/TypeInfo.d.ts +49 -0
- package/utilities/TypeInfo.js.flow +9 -6
- package/utilities/assertValidName.d.ts +15 -0
- package/utilities/assertValidName.js +3 -3
- package/utilities/assertValidName.js.flow +3 -2
- package/utilities/assertValidName.mjs +2 -2
- package/utilities/astFromValue.d.ts +25 -0
- package/utilities/astFromValue.js +22 -38
- package/utilities/astFromValue.js.flow +7 -4
- package/utilities/astFromValue.mjs +19 -36
- package/utilities/buildASTSchema.d.ts +114 -0
- package/utilities/buildASTSchema.js +37 -68
- package/utilities/buildASTSchema.js.flow +32 -30
- package/utilities/buildASTSchema.mjs +32 -64
- package/utilities/buildClientSchema.d.ts +21 -0
- package/utilities/buildClientSchema.js +23 -15
- package/utilities/buildClientSchema.js.flow +17 -16
- package/utilities/buildClientSchema.mjs +20 -12
- package/utilities/coerceInputValue.d.ts +17 -0
- package/utilities/coerceInputValue.js +161 -0
- package/utilities/coerceInputValue.js.flow +214 -0
- package/utilities/coerceInputValue.mjs +142 -0
- package/utilities/coerceValue.d.ts +23 -0
- package/utilities/coerceValue.js +21 -199
- package/utilities/coerceValue.js.flow +31 -223
- package/utilities/coerceValue.mjs +20 -195
- package/utilities/concatAST.d.ts +8 -0
- package/utilities/concatAST.js.flow +1 -0
- package/utilities/extendSchema.d.ts +45 -0
- package/utilities/extendSchema.js +64 -131
- package/utilities/extendSchema.js.flow +27 -24
- package/utilities/extendSchema.mjs +61 -129
- package/utilities/findBreakingChanges.d.ts +64 -0
- package/utilities/findBreakingChanges.js +194 -619
- package/utilities/findBreakingChanges.js.flow +8 -5
- package/utilities/findBreakingChanges.mjs +194 -619
- package/utilities/findDeprecatedUsages.d.ts +13 -0
- package/utilities/findDeprecatedUsages.js.flow +4 -1
- package/utilities/getOperationAST.d.ts +12 -0
- package/utilities/getOperationAST.js +13 -31
- package/utilities/getOperationAST.mjs +13 -31
- package/utilities/getOperationRootType.d.ts +14 -0
- package/utilities/getOperationRootType.js.flow +2 -0
- package/utilities/index.d.ts +127 -0
- package/utilities/index.js +8 -0
- package/utilities/index.js.flow +4 -1
- package/utilities/index.mjs +3 -1
- package/utilities/introspectionFromSchema.d.ts +16 -0
- package/utilities/introspectionFromSchema.js +5 -3
- package/utilities/introspectionFromSchema.js.flow +4 -2
- package/utilities/introspectionFromSchema.mjs +4 -2
- package/utilities/introspectionQuery.d.ts +177 -0
- package/utilities/isValidJSValue.d.ts +8 -0
- package/utilities/isValidJSValue.js +1 -1
- package/utilities/isValidJSValue.js.flow +3 -2
- package/utilities/isValidJSValue.mjs +2 -2
- package/utilities/isValidLiteralValue.d.ts +15 -0
- package/utilities/isValidLiteralValue.js +4 -4
- package/utilities/isValidLiteralValue.js.flow +8 -4
- package/utilities/isValidLiteralValue.mjs +2 -2
- package/utilities/lexicographicSortSchema.d.ts +6 -0
- package/utilities/lexicographicSortSchema.js +11 -8
- package/utilities/lexicographicSortSchema.js.flow +5 -3
- package/utilities/lexicographicSortSchema.mjs +9 -7
- package/utilities/schemaPrinter.d.ts +30 -0
- package/utilities/schemaPrinter.js +15 -32
- package/utilities/schemaPrinter.js.flow +14 -10
- package/utilities/schemaPrinter.mjs +14 -32
- package/utilities/separateOperations.d.ts +11 -0
- package/utilities/separateOperations.js +6 -6
- package/utilities/separateOperations.js.flow +2 -1
- package/utilities/separateOperations.mjs +6 -6
- package/utilities/stripIgnoredCharacters.d.ts +55 -0
- package/utilities/stripIgnoredCharacters.js.flow +1 -0
- package/utilities/typeComparators.d.ts +32 -0
- package/utilities/typeComparators.js.flow +1 -1
- package/utilities/typeComparators.mjs +1 -1
- package/utilities/typeFromAST.d.ts +29 -0
- package/utilities/typeFromAST.js +5 -3
- package/utilities/typeFromAST.js.flow +5 -3
- package/utilities/typeFromAST.mjs +14 -3
- package/utilities/valueFromAST.d.ts +29 -0
- package/utilities/valueFromAST.js +40 -74
- package/utilities/valueFromAST.js.flow +7 -4
- package/utilities/valueFromAST.mjs +39 -74
- package/utilities/valueFromASTUntyped.d.ts +23 -0
- package/utilities/valueFromASTUntyped.js +4 -3
- package/utilities/valueFromASTUntyped.js.flow +3 -2
- package/utilities/valueFromASTUntyped.mjs +3 -3
- package/validation/ValidationContext.d.ts +96 -0
- package/validation/ValidationContext.js +38 -86
- package/validation/ValidationContext.js.flow +22 -7
- package/validation/ValidationContext.mjs +37 -85
- package/validation/index.d.ts +126 -0
- package/validation/rules/ExecutableDefinitions.d.ts +14 -0
- package/validation/rules/ExecutableDefinitions.js +4 -23
- package/validation/rules/ExecutableDefinitions.js.flow +4 -2
- package/validation/rules/ExecutableDefinitions.mjs +4 -23
- package/validation/rules/FieldsOnCorrectType.d.ts +17 -0
- package/validation/rules/FieldsOnCorrectType.js +21 -57
- package/validation/rules/FieldsOnCorrectType.js.flow +7 -3
- package/validation/rules/FieldsOnCorrectType.mjs +21 -57
- package/validation/rules/FragmentsOnCompositeTypes.d.ts +20 -0
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +5 -1
- package/validation/rules/KnownArgumentNames.d.ts +28 -0
- package/validation/rules/KnownArgumentNames.js +26 -79
- package/validation/rules/KnownArgumentNames.js.flow +10 -6
- package/validation/rules/KnownArgumentNames.mjs +22 -75
- package/validation/rules/KnownDirectives.d.ts +19 -0
- package/validation/rules/KnownDirectives.js +12 -48
- package/validation/rules/KnownDirectives.js.flow +8 -5
- package/validation/rules/KnownDirectives.mjs +12 -48
- package/validation/rules/KnownFragmentNames.d.ts +12 -0
- package/validation/rules/KnownFragmentNames.js.flow +2 -1
- package/validation/rules/KnownTypeNames.d.ts +15 -0
- package/validation/rules/KnownTypeNames.js +6 -24
- package/validation/rules/KnownTypeNames.js.flow +10 -6
- package/validation/rules/KnownTypeNames.mjs +6 -24
- package/validation/rules/LoneAnonymousOperation.d.ts +14 -0
- package/validation/rules/LoneAnonymousOperation.js.flow +3 -1
- package/validation/rules/LoneSchemaDefinition.d.ts +13 -0
- package/validation/rules/LoneSchemaDefinition.js.flow +2 -1
- package/validation/rules/NoFragmentCycles.d.ts +9 -0
- package/validation/rules/NoFragmentCycles.js +17 -35
- package/validation/rules/NoFragmentCycles.js.flow +4 -2
- package/validation/rules/NoFragmentCycles.mjs +17 -35
- package/validation/rules/NoUndefinedVariables.d.ts +16 -0
- package/validation/rules/NoUndefinedVariables.js +6 -24
- package/validation/rules/NoUndefinedVariables.js.flow +2 -1
- package/validation/rules/NoUndefinedVariables.mjs +6 -24
- package/validation/rules/NoUnusedFragments.d.ts +12 -0
- package/validation/rules/NoUnusedFragments.js +7 -25
- package/validation/rules/NoUnusedFragments.js.flow +2 -1
- package/validation/rules/NoUnusedFragments.mjs +7 -25
- package/validation/rules/NoUnusedVariables.d.ts +16 -0
- package/validation/rules/NoUnusedVariables.js +6 -24
- package/validation/rules/NoUnusedVariables.js.flow +2 -1
- package/validation/rules/NoUnusedVariables.mjs +6 -24
- package/validation/rules/OverlappingFieldsCanBeMerged.d.ts +24 -0
- package/validation/rules/OverlappingFieldsCanBeMerged.js +27 -46
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +17 -8
- package/validation/rules/OverlappingFieldsCanBeMerged.mjs +25 -44
- package/validation/rules/PossibleFragmentSpreads.d.ts +22 -0
- package/validation/rules/PossibleFragmentSpreads.js +2 -2
- package/validation/rules/PossibleFragmentSpreads.js.flow +8 -3
- package/validation/rules/PossibleFragmentSpreads.mjs +2 -2
- package/validation/rules/PossibleTypeExtensions.d.ts +21 -0
- package/validation/rules/PossibleTypeExtensions.js +4 -22
- package/validation/rules/PossibleTypeExtensions.js.flow +6 -2
- package/validation/rules/PossibleTypeExtensions.mjs +4 -22
- package/validation/rules/ProvidedRequiredArguments.d.ts +29 -0
- package/validation/rules/ProvidedRequiredArguments.js +27 -79
- package/validation/rules/ProvidedRequiredArguments.js.flow +12 -8
- package/validation/rules/ProvidedRequiredArguments.mjs +25 -77
- package/validation/rules/ScalarLeafs.d.ts +20 -0
- package/validation/rules/ScalarLeafs.js.flow +6 -2
- package/validation/rules/SingleFieldSubscriptions.d.ts +14 -0
- package/validation/rules/SingleFieldSubscriptions.js.flow +4 -2
- package/validation/rules/UniqueArgumentNames.d.ts +12 -0
- package/validation/rules/UniqueArgumentNames.js.flow +2 -1
- package/validation/rules/UniqueDirectiveNames.d.ts +13 -0
- package/validation/rules/UniqueDirectiveNames.js.flow +2 -1
- package/validation/rules/UniqueDirectivesPerLocation.d.ts +14 -0
- package/validation/rules/UniqueDirectivesPerLocation.js +15 -69
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +7 -4
- package/validation/rules/UniqueDirectivesPerLocation.mjs +15 -69
- package/validation/rules/UniqueEnumValueNames.d.ts +19 -0
- package/validation/rules/UniqueEnumValueNames.js +10 -28
- package/validation/rules/UniqueEnumValueNames.js.flow +2 -1
- package/validation/rules/UniqueEnumValueNames.mjs +10 -28
- package/validation/rules/UniqueFieldDefinitionNames.d.ts +21 -0
- package/validation/rules/UniqueFieldDefinitionNames.js +9 -27
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +2 -1
- package/validation/rules/UniqueFieldDefinitionNames.mjs +9 -27
- package/validation/rules/UniqueFragmentNames.d.ts +11 -0
- package/validation/rules/UniqueFragmentNames.js.flow +2 -1
- package/validation/rules/UniqueInputFieldNames.d.ts +14 -0
- package/validation/rules/UniqueInputFieldNames.js.flow +2 -1
- package/validation/rules/UniqueOperationNames.d.ts +11 -0
- package/validation/rules/UniqueOperationNames.js.flow +2 -1
- package/validation/rules/UniqueOperationTypes.d.ts +13 -0
- package/validation/rules/UniqueOperationTypes.js +11 -30
- package/validation/rules/UniqueOperationTypes.js.flow +2 -1
- package/validation/rules/UniqueOperationTypes.mjs +10 -29
- package/validation/rules/UniqueTypeNames.d.ts +13 -0
- package/validation/rules/UniqueTypeNames.js.flow +3 -1
- package/validation/rules/UniqueVariableNames.d.ts +11 -0
- package/validation/rules/UniqueVariableNames.js.flow +4 -2
- package/validation/rules/ValuesOfCorrectType.d.ts +34 -0
- package/validation/rules/ValuesOfCorrectType.js +16 -34
- package/validation/rules/ValuesOfCorrectType.js.flow +11 -6
- package/validation/rules/ValuesOfCorrectType.mjs +12 -30
- package/validation/rules/VariablesAreInputTypes.d.ts +15 -0
- package/validation/rules/VariablesAreInputTypes.js.flow +6 -2
- package/validation/rules/VariablesInAllowedPosition.d.ts +15 -0
- package/validation/rules/VariablesInAllowedPosition.js +22 -40
- package/validation/rules/VariablesInAllowedPosition.js.flow +8 -3
- package/validation/rules/VariablesInAllowedPosition.mjs +18 -36
- package/validation/specifiedRules.d.ts +98 -0
- package/validation/validate.d.ts +56 -0
- package/validation/validate.js +35 -7
- package/validation/validate.js.flow +51 -9
- package/validation/validate.mjs +30 -7
- package/version.d.ts +14 -0
- package/version.js +3 -3
- package/version.js.flow +3 -3
- package/version.mjs +3 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import Maybe from '../tsutils/Maybe';
|
|
2
|
+
import { DocumentNode } from '../language/ast';
|
|
3
|
+
import {
|
|
4
|
+
ExecutionResult,
|
|
5
|
+
ExecutionResultDataDefault,
|
|
6
|
+
} from '../execution/execute';
|
|
7
|
+
import { GraphQLSchema } from '../type/schema';
|
|
8
|
+
import { GraphQLFieldResolver } from '../type/definition';
|
|
9
|
+
|
|
10
|
+
export interface SubscriptionArgs {
|
|
11
|
+
schema: GraphQLSchema;
|
|
12
|
+
document: DocumentNode;
|
|
13
|
+
rootValue?: any;
|
|
14
|
+
contextValue?: any;
|
|
15
|
+
variableValues?: Maybe<Record<string, any>>;
|
|
16
|
+
operationName?: Maybe<string>;
|
|
17
|
+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
|
18
|
+
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
23
|
+
*
|
|
24
|
+
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
25
|
+
* or an ExecutionResult (client error). The promise will be rejected if a
|
|
26
|
+
* server error occurs.
|
|
27
|
+
*
|
|
28
|
+
* If the client-provided arguments to this function do not result in a
|
|
29
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
30
|
+
* descriptive errors and no data will be returned.
|
|
31
|
+
*
|
|
32
|
+
* If the the source stream could not be created due to faulty subscription
|
|
33
|
+
* resolver logic or underlying systems, the promise will resolve to a single
|
|
34
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
35
|
+
*
|
|
36
|
+
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
37
|
+
* yields a stream of ExecutionResults representing the response stream.
|
|
38
|
+
*
|
|
39
|
+
* Accepts either an object with named arguments, or individual arguments.
|
|
40
|
+
*/
|
|
41
|
+
export function subscribe<TData = ExecutionResultDataDefault>(
|
|
42
|
+
args: SubscriptionArgs,
|
|
43
|
+
): Promise<
|
|
44
|
+
AsyncIterableIterator<ExecutionResult<TData>> | ExecutionResult<TData>
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
export function subscribe<TData = ExecutionResultDataDefault>(
|
|
48
|
+
schema: GraphQLSchema,
|
|
49
|
+
document: DocumentNode,
|
|
50
|
+
rootValue?: any,
|
|
51
|
+
contextValue?: any,
|
|
52
|
+
variableValues?: Maybe<{ [key: string]: any }>,
|
|
53
|
+
operationName?: Maybe<string>,
|
|
54
|
+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
|
55
|
+
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
|
56
|
+
): Promise<
|
|
57
|
+
AsyncIterableIterator<ExecutionResult<TData>> | ExecutionResult<TData>
|
|
58
|
+
>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
62
|
+
* GraphQL specification, resolving the subscription source event stream.
|
|
63
|
+
*
|
|
64
|
+
* Returns a Promise<AsyncIterable>.
|
|
65
|
+
*
|
|
66
|
+
* If the client-provided invalid arguments, the source stream could not be
|
|
67
|
+
* created, or the resolver did not return an AsyncIterable, this function will
|
|
68
|
+
* will throw an error, which should be caught and handled by the caller.
|
|
69
|
+
*
|
|
70
|
+
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
71
|
+
* a GraphQL execution for that event.
|
|
72
|
+
*
|
|
73
|
+
* This may be useful when hosting the stateful subscription service in a
|
|
74
|
+
* different process or machine than the stateless GraphQL execution engine,
|
|
75
|
+
* or otherwise separating these two steps. For more on this, see the
|
|
76
|
+
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
77
|
+
*/
|
|
78
|
+
export function createSourceEventStream<TData = ExecutionResultDataDefault>(
|
|
79
|
+
schema: GraphQLSchema,
|
|
80
|
+
document: DocumentNode,
|
|
81
|
+
rootValue?: any,
|
|
82
|
+
contextValue?: any,
|
|
83
|
+
variableValues?: { [key: string]: any },
|
|
84
|
+
operationName?: Maybe<string>,
|
|
85
|
+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
|
86
|
+
): Promise<AsyncIterable<any> | ExecutionResult<TData>>;
|
|
@@ -10,16 +10,18 @@ var _iterall = require("iterall");
|
|
|
10
10
|
|
|
11
11
|
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
|
12
12
|
|
|
13
|
+
var _Path = require("../jsutils/Path");
|
|
14
|
+
|
|
13
15
|
var _GraphQLError = require("../error/GraphQLError");
|
|
14
16
|
|
|
15
17
|
var _locatedError = require("../error/locatedError");
|
|
16
18
|
|
|
17
19
|
var _execute = require("../execution/execute");
|
|
18
20
|
|
|
19
|
-
var _mapAsyncIterator = _interopRequireDefault(require("./mapAsyncIterator"));
|
|
20
|
-
|
|
21
21
|
var _getOperationRootType = require("../utilities/getOperationRootType");
|
|
22
22
|
|
|
23
|
+
var _mapAsyncIterator = _interopRequireDefault(require("./mapAsyncIterator"));
|
|
24
|
+
|
|
23
25
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
26
|
|
|
25
27
|
function subscribe(argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
|
|
@@ -79,17 +81,27 @@ function subscribeImpl(args) {
|
|
|
79
81
|
return (// Note: Flow can't refine isAsyncIterable, so explicit casts are used.
|
|
80
82
|
(0, _iterall.isAsyncIterable)(resultOrStream) ? (0, _mapAsyncIterator.default)(resultOrStream, mapSourceToResponse, reportGraphQLError) : resultOrStream
|
|
81
83
|
);
|
|
82
|
-
}
|
|
84
|
+
});
|
|
83
85
|
}
|
|
84
86
|
/**
|
|
85
87
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
86
88
|
* GraphQL specification, resolving the subscription source event stream.
|
|
87
89
|
*
|
|
88
|
-
* Returns a Promise
|
|
90
|
+
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
91
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
92
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
93
|
+
* is not an async iterable.
|
|
94
|
+
*
|
|
95
|
+
* If the client-provided arguments to this function do not result in a
|
|
96
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
97
|
+
* descriptive errors and no data will be returned.
|
|
89
98
|
*
|
|
90
|
-
* If the
|
|
91
|
-
*
|
|
92
|
-
*
|
|
99
|
+
* If the the source stream could not be created due to faulty subscription
|
|
100
|
+
* resolver logic or underlying systems, the promise will resolve to a single
|
|
101
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
102
|
+
*
|
|
103
|
+
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
104
|
+
* event stream returned by the resolver.
|
|
93
105
|
*
|
|
94
106
|
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
95
107
|
* a GraphQL execution for that event.
|
|
@@ -133,7 +145,7 @@ function createSourceEventStream(schema, document, rootValue, contextValue, vari
|
|
|
133
145
|
|
|
134
146
|
|
|
135
147
|
var resolveFn = fieldDef.subscribe || exeContext.fieldResolver;
|
|
136
|
-
var path = (0,
|
|
148
|
+
var path = (0, _Path.addPath)(undefined, responseName);
|
|
137
149
|
var info = (0, _execute.buildResolveInfo)(exeContext, fieldDef, fieldNodes, type, path); // resolveFieldValueOrError implements the "ResolveFieldEventStream"
|
|
138
150
|
// algorithm from GraphQL specification. It differs from
|
|
139
151
|
// "ResolveFieldValue" due to providing a different `resolveFn`.
|
|
@@ -143,7 +155,9 @@ function createSourceEventStream(schema, document, rootValue, contextValue, vari
|
|
|
143
155
|
return Promise.resolve(result).then(function (eventStream) {
|
|
144
156
|
// If eventStream is an Error, rethrow a located error.
|
|
145
157
|
if (eventStream instanceof Error) {
|
|
146
|
-
|
|
158
|
+
return {
|
|
159
|
+
errors: [(0, _locatedError.locatedError)(eventStream, fieldNodes, (0, _Path.pathToArray)(path))]
|
|
160
|
+
};
|
|
147
161
|
} // Assert field returned an event stream, otherwise yield an error.
|
|
148
162
|
|
|
149
163
|
|
|
@@ -155,6 +169,11 @@ function createSourceEventStream(schema, document, rootValue, contextValue, vari
|
|
|
155
169
|
throw new Error('Subscription field must return Async Iterable. Received: ' + (0, _inspect.default)(eventStream));
|
|
156
170
|
});
|
|
157
171
|
} catch (error) {
|
|
158
|
-
|
|
172
|
+
// As with reportGraphQLError above, if the error is a GraphQLError, report
|
|
173
|
+
// it as an ExecutionResult; otherwise treat it as a system-class error and
|
|
174
|
+
// re-throw it.
|
|
175
|
+
return error instanceof _GraphQLError.GraphQLError ? Promise.resolve({
|
|
176
|
+
errors: [error]
|
|
177
|
+
}) : Promise.reject(error);
|
|
159
178
|
}
|
|
160
179
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// @flow strict
|
|
2
2
|
|
|
3
3
|
import { isAsyncIterable } from 'iterall';
|
|
4
|
+
|
|
4
5
|
import inspect from '../jsutils/inspect';
|
|
6
|
+
import { addPath, pathToArray } from '../jsutils/Path';
|
|
7
|
+
|
|
5
8
|
import { GraphQLError } from '../error/GraphQLError';
|
|
6
9
|
import { locatedError } from '../error/locatedError';
|
|
10
|
+
|
|
11
|
+
import { type DocumentNode } from '../language/ast';
|
|
12
|
+
|
|
7
13
|
import {
|
|
8
14
|
type ExecutionResult,
|
|
9
|
-
addPath,
|
|
10
15
|
assertValidExecutionArguments,
|
|
11
16
|
buildExecutionContext,
|
|
12
17
|
buildResolveInfo,
|
|
@@ -14,15 +19,15 @@ import {
|
|
|
14
19
|
execute,
|
|
15
20
|
getFieldDef,
|
|
16
21
|
resolveFieldValueOrError,
|
|
17
|
-
responsePathAsArray,
|
|
18
22
|
} from '../execution/execute';
|
|
19
|
-
import { type GraphQLSchema } from '../type/schema';
|
|
20
|
-
import mapAsyncIterator from './mapAsyncIterator';
|
|
21
23
|
|
|
22
|
-
import { type
|
|
24
|
+
import { type GraphQLSchema } from '../type/schema';
|
|
23
25
|
import { type GraphQLFieldResolver } from '../type/definition';
|
|
26
|
+
|
|
24
27
|
import { getOperationRootType } from '../utilities/getOperationRootType';
|
|
25
28
|
|
|
29
|
+
import mapAsyncIterator from './mapAsyncIterator';
|
|
30
|
+
|
|
26
31
|
export type SubscriptionArgs = {|
|
|
27
32
|
schema: GraphQLSchema,
|
|
28
33
|
document: DocumentNode,
|
|
@@ -38,8 +43,9 @@ export type SubscriptionArgs = {|
|
|
|
38
43
|
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
39
44
|
*
|
|
40
45
|
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
41
|
-
* or an ExecutionResult (
|
|
42
|
-
*
|
|
46
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
47
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
48
|
+
* is not an async iterable.
|
|
43
49
|
*
|
|
44
50
|
* If the client-provided arguments to this function do not result in a
|
|
45
51
|
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
@@ -150,17 +156,15 @@ function subscribeImpl(
|
|
|
150
156
|
|
|
151
157
|
// Resolve the Source Stream, then map every source value to a
|
|
152
158
|
// ExecutionResult value as described above.
|
|
153
|
-
return sourcePromise.then(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
: ((resultOrStream: any): ExecutionResult),
|
|
163
|
-
reportGraphQLError,
|
|
159
|
+
return sourcePromise.then(resultOrStream =>
|
|
160
|
+
// Note: Flow can't refine isAsyncIterable, so explicit casts are used.
|
|
161
|
+
isAsyncIterable(resultOrStream)
|
|
162
|
+
? mapAsyncIterator(
|
|
163
|
+
((resultOrStream: any): AsyncIterable<mixed>),
|
|
164
|
+
mapSourceToResponse,
|
|
165
|
+
reportGraphQLError,
|
|
166
|
+
)
|
|
167
|
+
: ((resultOrStream: any): ExecutionResult),
|
|
164
168
|
);
|
|
165
169
|
}
|
|
166
170
|
|
|
@@ -168,11 +172,21 @@ function subscribeImpl(
|
|
|
168
172
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
169
173
|
* GraphQL specification, resolving the subscription source event stream.
|
|
170
174
|
*
|
|
171
|
-
* Returns a Promise
|
|
175
|
+
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
176
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
177
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
178
|
+
* is not an async iterable.
|
|
179
|
+
*
|
|
180
|
+
* If the client-provided arguments to this function do not result in a
|
|
181
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
182
|
+
* descriptive errors and no data will be returned.
|
|
183
|
+
*
|
|
184
|
+
* If the the source stream could not be created due to faulty subscription
|
|
185
|
+
* resolver logic or underlying systems, the promise will resolve to a single
|
|
186
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
172
187
|
*
|
|
173
|
-
* If the
|
|
174
|
-
*
|
|
175
|
-
* will throw an error, which should be caught and handled by the caller.
|
|
188
|
+
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
189
|
+
* event stream returned by the resolver.
|
|
176
190
|
*
|
|
177
191
|
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
178
192
|
* a GraphQL execution for that event.
|
|
@@ -259,7 +273,9 @@ export function createSourceEventStream(
|
|
|
259
273
|
return Promise.resolve(result).then(eventStream => {
|
|
260
274
|
// If eventStream is an Error, rethrow a located error.
|
|
261
275
|
if (eventStream instanceof Error) {
|
|
262
|
-
|
|
276
|
+
return {
|
|
277
|
+
errors: [locatedError(eventStream, fieldNodes, pathToArray(path))],
|
|
278
|
+
};
|
|
263
279
|
}
|
|
264
280
|
|
|
265
281
|
// Assert field returned an event stream, otherwise yield an error.
|
|
@@ -273,6 +289,11 @@ export function createSourceEventStream(
|
|
|
273
289
|
);
|
|
274
290
|
});
|
|
275
291
|
} catch (error) {
|
|
276
|
-
|
|
292
|
+
// As with reportGraphQLError above, if the error is a GraphQLError, report
|
|
293
|
+
// it as an ExecutionResult; otherwise treat it as a system-class error and
|
|
294
|
+
// re-throw it.
|
|
295
|
+
return error instanceof GraphQLError
|
|
296
|
+
? Promise.resolve({ errors: [error] })
|
|
297
|
+
: Promise.reject(error);
|
|
277
298
|
}
|
|
278
299
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isAsyncIterable } from 'iterall';
|
|
2
2
|
import inspect from '../jsutils/inspect';
|
|
3
|
+
import { addPath, pathToArray } from '../jsutils/Path';
|
|
3
4
|
import { GraphQLError } from '../error/GraphQLError';
|
|
4
5
|
import { locatedError } from '../error/locatedError';
|
|
5
|
-
import {
|
|
6
|
-
import mapAsyncIterator from './mapAsyncIterator';
|
|
6
|
+
import { assertValidExecutionArguments, buildExecutionContext, buildResolveInfo, collectFields, execute, getFieldDef, resolveFieldValueOrError } from '../execution/execute';
|
|
7
7
|
import { getOperationRootType } from '../utilities/getOperationRootType';
|
|
8
|
+
import mapAsyncIterator from './mapAsyncIterator';
|
|
8
9
|
export function subscribe(argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
|
|
9
10
|
/* eslint-enable no-redeclare */
|
|
10
11
|
// Extract arguments from object args if provided.
|
|
@@ -61,17 +62,27 @@ function subscribeImpl(args) {
|
|
|
61
62
|
return (// Note: Flow can't refine isAsyncIterable, so explicit casts are used.
|
|
62
63
|
isAsyncIterable(resultOrStream) ? mapAsyncIterator(resultOrStream, mapSourceToResponse, reportGraphQLError) : resultOrStream
|
|
63
64
|
);
|
|
64
|
-
}
|
|
65
|
+
});
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
68
69
|
* GraphQL specification, resolving the subscription source event stream.
|
|
69
70
|
*
|
|
70
|
-
* Returns a Promise
|
|
71
|
+
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
72
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
73
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
74
|
+
* is not an async iterable.
|
|
71
75
|
*
|
|
72
|
-
* If the client-provided
|
|
73
|
-
*
|
|
74
|
-
*
|
|
76
|
+
* If the client-provided arguments to this function do not result in a
|
|
77
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
78
|
+
* descriptive errors and no data will be returned.
|
|
79
|
+
*
|
|
80
|
+
* If the the source stream could not be created due to faulty subscription
|
|
81
|
+
* resolver logic or underlying systems, the promise will resolve to a single
|
|
82
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
83
|
+
*
|
|
84
|
+
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
85
|
+
* event stream returned by the resolver.
|
|
75
86
|
*
|
|
76
87
|
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
77
88
|
* a GraphQL execution for that event.
|
|
@@ -125,7 +136,9 @@ export function createSourceEventStream(schema, document, rootValue, contextValu
|
|
|
125
136
|
return Promise.resolve(result).then(function (eventStream) {
|
|
126
137
|
// If eventStream is an Error, rethrow a located error.
|
|
127
138
|
if (eventStream instanceof Error) {
|
|
128
|
-
|
|
139
|
+
return {
|
|
140
|
+
errors: [locatedError(eventStream, fieldNodes, pathToArray(path))]
|
|
141
|
+
};
|
|
129
142
|
} // Assert field returned an event stream, otherwise yield an error.
|
|
130
143
|
|
|
131
144
|
|
|
@@ -137,6 +150,11 @@ export function createSourceEventStream(schema, document, rootValue, contextValu
|
|
|
137
150
|
throw new Error('Subscription field must return Async Iterable. Received: ' + inspect(eventStream));
|
|
138
151
|
});
|
|
139
152
|
} catch (error) {
|
|
140
|
-
|
|
153
|
+
// As with reportGraphQLError above, if the error is a GraphQLError, report
|
|
154
|
+
// it as an ExecutionResult; otherwise treat it as a system-class error and
|
|
155
|
+
// re-throw it.
|
|
156
|
+
return error instanceof GraphQLError ? Promise.resolve({
|
|
157
|
+
errors: [error]
|
|
158
|
+
}) : Promise.reject(error);
|
|
141
159
|
}
|
|
142
160
|
}
|