@graphql-tools/executor 0.0.2 → 0.0.3-alpha-20221031181646-cd48ed2f
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/cjs/execution/execute.js +654 -109
- package/cjs/execution/flattenAsyncIterable.js +91 -0
- package/cjs/execution/invariant.js +9 -0
- package/cjs/execution/promiseForObject.js +21 -0
- package/esm/execution/execute.js +651 -108
- package/esm/execution/flattenAsyncIterable.js +87 -0
- package/esm/execution/invariant.js +5 -0
- package/esm/execution/promiseForObject.js +17 -0
- package/package.json +2 -2
- package/typings/execution/execute.d.cts +168 -23
- package/typings/execution/execute.d.ts +168 -23
- package/typings/execution/flattenAsyncIterable.d.cts +7 -0
- package/typings/execution/flattenAsyncIterable.d.ts +7 -0
- package/typings/execution/invariant.d.cts +1 -0
- package/typings/execution/invariant.d.ts +1 -0
- package/typings/execution/promiseForObject.d.cts +12 -0
- package/typings/execution/promiseForObject.d.ts +12 -0
- package/cjs/execution/subscribe.js +0 -158
- package/esm/execution/subscribe.js +0 -153
- package/typings/execution/subscribe.d.cts +0 -59
- package/typings/execution/subscribe.d.ts +0 -59
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an AsyncIterable of AsyncIterables, flatten all yielded results into a
|
|
3
|
+
* single AsyncIterable.
|
|
4
|
+
*/
|
|
5
|
+
export function flattenAsyncIterable(iterable) {
|
|
6
|
+
// You might think this whole function could be replaced with
|
|
7
|
+
//
|
|
8
|
+
// async function* flattenAsyncIterable(iterable) {
|
|
9
|
+
// for await (const subIterator of iterable) {
|
|
10
|
+
// yield* subIterator;
|
|
11
|
+
// }
|
|
12
|
+
// }
|
|
13
|
+
//
|
|
14
|
+
// but calling `.return()` on the iterator it returns won't interrupt the `for await`.
|
|
15
|
+
const topIterator = iterable[Symbol.asyncIterator]();
|
|
16
|
+
let currentNestedIterator;
|
|
17
|
+
let waitForCurrentNestedIterator;
|
|
18
|
+
let done = false;
|
|
19
|
+
async function next() {
|
|
20
|
+
if (done) {
|
|
21
|
+
return { value: undefined, done: true };
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
if (!currentNestedIterator) {
|
|
25
|
+
// Somebody else is getting it already.
|
|
26
|
+
if (waitForCurrentNestedIterator) {
|
|
27
|
+
await waitForCurrentNestedIterator;
|
|
28
|
+
return await next();
|
|
29
|
+
}
|
|
30
|
+
// Nobody else is getting it. We should!
|
|
31
|
+
let resolve;
|
|
32
|
+
waitForCurrentNestedIterator = new Promise(r => {
|
|
33
|
+
resolve = r;
|
|
34
|
+
});
|
|
35
|
+
const topIteratorResult = await topIterator.next();
|
|
36
|
+
if (topIteratorResult.done) {
|
|
37
|
+
// Given that done only ever transitions from false to true,
|
|
38
|
+
// require-atomic-updates is being unnecessarily cautious.
|
|
39
|
+
done = true;
|
|
40
|
+
return await next();
|
|
41
|
+
}
|
|
42
|
+
// eslint is making a reasonable point here, but we've explicitly protected
|
|
43
|
+
// ourself from the race condition by ensuring that only the single call
|
|
44
|
+
// that assigns to waitForCurrentNestedIterator is allowed to assign to
|
|
45
|
+
// currentNestedIterator or waitForCurrentNestedIterator.
|
|
46
|
+
currentNestedIterator = topIteratorResult.value[Symbol.asyncIterator]();
|
|
47
|
+
waitForCurrentNestedIterator = undefined;
|
|
48
|
+
resolve();
|
|
49
|
+
return await next();
|
|
50
|
+
}
|
|
51
|
+
const rememberCurrentNestedIterator = currentNestedIterator;
|
|
52
|
+
const nestedIteratorResult = await currentNestedIterator.next();
|
|
53
|
+
if (!nestedIteratorResult.done) {
|
|
54
|
+
return nestedIteratorResult;
|
|
55
|
+
}
|
|
56
|
+
// The nested iterator is done. If it's still the current one, make it not
|
|
57
|
+
// current. (If it's not the current one, somebody else has made us move on.)
|
|
58
|
+
if (currentNestedIterator === rememberCurrentNestedIterator) {
|
|
59
|
+
currentNestedIterator = undefined;
|
|
60
|
+
}
|
|
61
|
+
return await next();
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
done = true;
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
next,
|
|
70
|
+
async return() {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
done = true;
|
|
73
|
+
await Promise.all([(_a = currentNestedIterator === null || currentNestedIterator === void 0 ? void 0 : currentNestedIterator.return) === null || _a === void 0 ? void 0 : _a.call(currentNestedIterator), (_b = topIterator.return) === null || _b === void 0 ? void 0 : _b.call(topIterator)]);
|
|
74
|
+
return { value: undefined, done: true };
|
|
75
|
+
},
|
|
76
|
+
async throw(error) {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
done = true;
|
|
79
|
+
await Promise.all([(_a = currentNestedIterator === null || currentNestedIterator === void 0 ? void 0 : currentNestedIterator.throw) === null || _a === void 0 ? void 0 : _a.call(currentNestedIterator, error), (_b = topIterator.throw) === null || _b === void 0 ? void 0 : _b.call(topIterator, error)]);
|
|
80
|
+
/* c8 ignore next */
|
|
81
|
+
throw error;
|
|
82
|
+
},
|
|
83
|
+
[Symbol.asyncIterator]() {
|
|
84
|
+
return this;
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function transforms a JS object `Record<string, Promise<T>>` into
|
|
3
|
+
* a `Promise<Record<string, T>>`
|
|
4
|
+
*
|
|
5
|
+
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
6
|
+
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
7
|
+
*/
|
|
8
|
+
export async function promiseForObject(object) {
|
|
9
|
+
const keys = Object.keys(object);
|
|
10
|
+
const values = Object.values(object);
|
|
11
|
+
const resolvedValues = await Promise.all(values);
|
|
12
|
+
const resolvedObject = Object.create(null);
|
|
13
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
14
|
+
resolvedObject[keys[i]] = resolvedValues[i];
|
|
15
|
+
}
|
|
16
|
+
return resolvedObject;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/executor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-alpha-20221031181646-cd48ed2f",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-tools/utils": "
|
|
9
|
+
"@graphql-tools/utils": "9.0.0-alpha-20221031181646-cd48ed2f",
|
|
10
10
|
"@graphql-typed-document-node/core": "3.1.1"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GraphQLFormattedError,
|
|
2
|
-
import {
|
|
1
|
+
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema } from 'graphql';
|
|
2
|
+
import type { GraphQLError } from 'graphql';
|
|
3
|
+
import { Path, Maybe, MaybePromise, ExecutionResult } from '@graphql-tools/utils';
|
|
3
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
5
|
/**
|
|
5
6
|
* Terminology
|
|
@@ -26,25 +27,72 @@ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
|
26
27
|
* Namely, schema of the type system that is currently executing,
|
|
27
28
|
* and the fragments defined in the query document
|
|
28
29
|
*/
|
|
29
|
-
export interface ExecutionContext<TContext = any> {
|
|
30
|
+
export interface ExecutionContext<TVariables = any, TContext = any> {
|
|
30
31
|
schema: GraphQLSchema;
|
|
31
32
|
fragments: Record<string, FragmentDefinitionNode>;
|
|
32
33
|
rootValue: unknown;
|
|
33
34
|
contextValue: TContext;
|
|
34
35
|
operation: OperationDefinitionNode;
|
|
35
|
-
variableValues:
|
|
36
|
-
[variable: string]: unknown;
|
|
37
|
-
};
|
|
36
|
+
variableValues: TVariables;
|
|
38
37
|
fieldResolver: GraphQLFieldResolver<any, TContext>;
|
|
39
38
|
typeResolver: GraphQLTypeResolver<any, TContext>;
|
|
40
39
|
subscribeFieldResolver: GraphQLFieldResolver<any, TContext>;
|
|
41
40
|
errors: Array<GraphQLError>;
|
|
41
|
+
subsequentPayloads: Set<AsyncPayloadRecord>;
|
|
42
42
|
}
|
|
43
|
-
export interface FormattedExecutionResult<TData =
|
|
43
|
+
export interface FormattedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
44
44
|
errors?: ReadonlyArray<GraphQLFormattedError>;
|
|
45
45
|
data?: TData | null;
|
|
46
46
|
extensions?: TExtensions;
|
|
47
47
|
}
|
|
48
|
+
export interface ExperimentalIncrementalExecutionResults<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
49
|
+
initialResult: InitialIncrementalExecutionResult<TData, TExtensions>;
|
|
50
|
+
subsequentResults: AsyncGenerator<SubsequentIncrementalExecutionResult<TData, TExtensions>, void, void>;
|
|
51
|
+
}
|
|
52
|
+
export interface InitialIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends ExecutionResult<TData, TExtensions> {
|
|
53
|
+
hasNext: boolean;
|
|
54
|
+
incremental?: ReadonlyArray<IncrementalResult<TData, TExtensions>>;
|
|
55
|
+
extensions?: TExtensions;
|
|
56
|
+
}
|
|
57
|
+
export interface FormattedInitialIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends FormattedExecutionResult<TData, TExtensions> {
|
|
58
|
+
hasNext: boolean;
|
|
59
|
+
incremental?: ReadonlyArray<FormattedIncrementalResult<TData, TExtensions>>;
|
|
60
|
+
extensions?: TExtensions;
|
|
61
|
+
}
|
|
62
|
+
export interface SubsequentIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
63
|
+
hasNext: boolean;
|
|
64
|
+
incremental?: ReadonlyArray<IncrementalResult<TData, TExtensions>>;
|
|
65
|
+
extensions?: TExtensions;
|
|
66
|
+
}
|
|
67
|
+
export interface FormattedSubsequentIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
68
|
+
hasNext: boolean;
|
|
69
|
+
incremental?: ReadonlyArray<FormattedIncrementalResult<TData, TExtensions>>;
|
|
70
|
+
extensions?: TExtensions;
|
|
71
|
+
}
|
|
72
|
+
export interface IncrementalDeferResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends ExecutionResult<TData, TExtensions> {
|
|
73
|
+
path?: ReadonlyArray<string | number>;
|
|
74
|
+
label?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface FormattedIncrementalDeferResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends FormattedExecutionResult<TData, TExtensions> {
|
|
77
|
+
path?: ReadonlyArray<string | number>;
|
|
78
|
+
label?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface IncrementalStreamResult<TData = Array<unknown>, TExtensions = Record<string, unknown>> {
|
|
81
|
+
errors?: ReadonlyArray<GraphQLError>;
|
|
82
|
+
items?: TData | null;
|
|
83
|
+
path?: ReadonlyArray<string | number>;
|
|
84
|
+
label?: string;
|
|
85
|
+
extensions?: TExtensions;
|
|
86
|
+
}
|
|
87
|
+
export interface FormattedIncrementalStreamResult<TData = Array<unknown>, TExtensions = Record<string, unknown>> {
|
|
88
|
+
errors?: ReadonlyArray<GraphQLFormattedError>;
|
|
89
|
+
items?: TData | null;
|
|
90
|
+
path?: ReadonlyArray<string | number>;
|
|
91
|
+
label?: string;
|
|
92
|
+
extensions?: TExtensions;
|
|
93
|
+
}
|
|
94
|
+
export declare type IncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = IncrementalDeferResult<TData, TExtensions> | IncrementalStreamResult<TData, TExtensions>;
|
|
95
|
+
export declare type FormattedIncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = FormattedIncrementalDeferResult<TData, TExtensions> | FormattedIncrementalStreamResult<TData, TExtensions>;
|
|
48
96
|
export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
49
97
|
schema: GraphQLSchema;
|
|
50
98
|
document: TypedDocumentNode<TData, TVariables>;
|
|
@@ -65,12 +113,27 @@ export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
|
65
113
|
*
|
|
66
114
|
* If the arguments to this function do not result in a legal execution context,
|
|
67
115
|
* a GraphQLError will be thrown immediately explaining the invalid input.
|
|
116
|
+
*
|
|
117
|
+
* This function does not support incremental delivery (`@defer` and `@stream`).
|
|
118
|
+
* If an operation which would defer or stream data is executed with this
|
|
119
|
+
* function, it will throw or resolve to an object containing an error instead.
|
|
120
|
+
* Use `experimentalExecuteIncrementally` if you want to support incremental
|
|
121
|
+
* delivery.
|
|
122
|
+
*/
|
|
123
|
+
export declare function execute<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<ExecutionResult<TData>>;
|
|
124
|
+
/**
|
|
125
|
+
* Implements the "Executing requests" section of the GraphQL specification,
|
|
126
|
+
* including `@defer` and `@stream` as proposed in
|
|
127
|
+
* https://github.com/graphql/graphql-spec/pull/742
|
|
128
|
+
*
|
|
129
|
+
* This function returns a Promise of an ExperimentalIncrementalExecutionResults
|
|
130
|
+
* object. This object either consists of a single ExecutionResult, or an
|
|
131
|
+
* object containing an `initialResult` and a stream of `subsequentResults`.
|
|
132
|
+
*
|
|
133
|
+
* If the arguments to this function do not result in a legal execution context,
|
|
134
|
+
* a GraphQLError will be thrown immediately explaining the invalid input.
|
|
68
135
|
*/
|
|
69
|
-
export declare function
|
|
70
|
-
[key: string]: any;
|
|
71
|
-
}, TVariables = {
|
|
72
|
-
[key: string]: any;
|
|
73
|
-
}, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<ExecutionResult<TData>>;
|
|
136
|
+
export declare function experimentalExecuteIncrementally<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<ExecutionResult<TData> | ExperimentalIncrementalExecutionResults<TData>>;
|
|
74
137
|
/**
|
|
75
138
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
|
76
139
|
* However, it guarantees to complete synchronously (or throw an error) assuming
|
|
@@ -93,16 +156,12 @@ export declare function assertValidExecutionArguments<TVariables>(schema: GraphQ
|
|
|
93
156
|
* TODO: consider no longer exporting this function
|
|
94
157
|
* @internal
|
|
95
158
|
*/
|
|
96
|
-
export declare function buildExecutionContext<TData =
|
|
97
|
-
[key: string]: any;
|
|
98
|
-
}, TVariables = {
|
|
99
|
-
[key: string]: any;
|
|
100
|
-
}, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): ReadonlyArray<GraphQLError> | ExecutionContext;
|
|
159
|
+
export declare function buildExecutionContext<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): ReadonlyArray<GraphQLError> | ExecutionContext;
|
|
101
160
|
/**
|
|
102
161
|
* TODO: consider no longer exporting this function
|
|
103
162
|
* @internal
|
|
104
163
|
*/
|
|
105
|
-
export declare function buildResolveInfo(exeContext: ExecutionContext, fieldDef: GraphQLField<unknown, unknown>, fieldNodes:
|
|
164
|
+
export declare function buildResolveInfo(exeContext: ExecutionContext, fieldDef: GraphQLField<unknown, unknown>, fieldNodes: Array<FieldNode>, parentType: GraphQLObjectType, path: Path): GraphQLResolveInfo;
|
|
106
165
|
/**
|
|
107
166
|
* If a resolveType function is not given, then a default resolve behavior is
|
|
108
167
|
* used which attempts two strategies:
|
|
@@ -130,19 +189,61 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
130
189
|
* is not an async iterable.
|
|
131
190
|
*
|
|
132
191
|
* If the client-provided arguments to this function do not result in a
|
|
133
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
134
|
-
*
|
|
192
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with descriptive
|
|
193
|
+
* errors and no data will be returned.
|
|
135
194
|
*
|
|
136
|
-
* If the source stream could not be created due to faulty subscription
|
|
137
|
-
*
|
|
195
|
+
* If the source stream could not be created due to faulty subscription resolver
|
|
196
|
+
* logic or underlying systems, the promise will resolve to a single
|
|
138
197
|
* ExecutionResult containing `errors` and no `data`.
|
|
139
198
|
*
|
|
140
199
|
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
141
200
|
* yields a stream of ExecutionResults representing the response stream.
|
|
142
201
|
*
|
|
143
|
-
*
|
|
202
|
+
* This function does not support incremental delivery (`@defer` and `@stream`).
|
|
203
|
+
* If an operation which would defer or stream data is executed with this
|
|
204
|
+
* function, each `InitialIncrementalExecutionResult` and
|
|
205
|
+
* `SubsequentIncrementalExecutionResult` in the result stream will be replaced
|
|
206
|
+
* with an `ExecutionResult` with a single error stating that defer/stream is
|
|
207
|
+
* not supported. Use `experimentalSubscribeIncrementally` if you want to
|
|
208
|
+
* support incremental delivery.
|
|
209
|
+
*
|
|
210
|
+
* Accepts an object with named arguments.
|
|
144
211
|
*/
|
|
145
212
|
export declare function subscribe(args: ExecutionArgs): MaybePromise<AsyncIterable<ExecutionResult> | ExecutionResult>;
|
|
213
|
+
/**
|
|
214
|
+
* Implements the "Subscribe" algorithm described in the GraphQL specification,
|
|
215
|
+
* including `@defer` and `@stream` as proposed in
|
|
216
|
+
* https://github.com/graphql/graphql-spec/pull/742
|
|
217
|
+
*
|
|
218
|
+
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
219
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
220
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
221
|
+
* is not an async iterable.
|
|
222
|
+
*
|
|
223
|
+
* If the client-provided arguments to this function do not result in a
|
|
224
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with descriptive
|
|
225
|
+
* errors and no data will be returned.
|
|
226
|
+
*
|
|
227
|
+
* If the source stream could not be created due to faulty subscription resolver
|
|
228
|
+
* logic or underlying systems, the promise will resolve to a single
|
|
229
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
230
|
+
*
|
|
231
|
+
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
232
|
+
* yields a stream of result representing the response stream.
|
|
233
|
+
*
|
|
234
|
+
* Each result may be an ExecutionResult with no `hasNext` (if executing the
|
|
235
|
+
* event did not use `@defer` or `@stream`), or an
|
|
236
|
+
* `InitialIncrementalExecutionResult` or `SubsequentIncrementalExecutionResult`
|
|
237
|
+
* (if executing the event used `@defer` or `@stream`). In the case of
|
|
238
|
+
* incremental execution results, each event produces a single
|
|
239
|
+
* `InitialIncrementalExecutionResult` followed by one or more
|
|
240
|
+
* `SubsequentIncrementalExecutionResult`s; all but the last have `hasNext: true`,
|
|
241
|
+
* and the last has `hasNext: false`. There is no interleaving between results
|
|
242
|
+
* generated from the same original event.
|
|
243
|
+
*
|
|
244
|
+
* Accepts an object with named arguments.
|
|
245
|
+
*/
|
|
246
|
+
export declare function experimentalSubscribeIncrementally(args: ExecutionArgs): MaybePromise<AsyncGenerator<ExecutionResult | InitialIncrementalExecutionResult | SubsequentIncrementalExecutionResult, void, void> | ExecutionResult>;
|
|
146
247
|
/**
|
|
147
248
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
148
249
|
* GraphQL specification, resolving the subscription source event stream.
|
|
@@ -172,6 +273,49 @@ export declare function subscribe(args: ExecutionArgs): MaybePromise<AsyncIterab
|
|
|
172
273
|
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
173
274
|
*/
|
|
174
275
|
export declare function createSourceEventStream(args: ExecutionArgs): MaybePromise<AsyncIterable<unknown> | ExecutionResult>;
|
|
276
|
+
declare class DeferredFragmentRecord {
|
|
277
|
+
type: 'defer';
|
|
278
|
+
errors: Array<GraphQLError>;
|
|
279
|
+
label: string | undefined;
|
|
280
|
+
path: Array<string | number>;
|
|
281
|
+
promise: Promise<void>;
|
|
282
|
+
data: Record<string, unknown> | null;
|
|
283
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
284
|
+
isCompleted: boolean;
|
|
285
|
+
_exeContext: ExecutionContext;
|
|
286
|
+
_resolve?: (arg: MaybePromise<Record<string, unknown> | null>) => void;
|
|
287
|
+
constructor(opts: {
|
|
288
|
+
label: string | undefined;
|
|
289
|
+
path: Path | undefined;
|
|
290
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
291
|
+
exeContext: ExecutionContext;
|
|
292
|
+
});
|
|
293
|
+
addData(data: MaybePromise<Record<string, unknown> | null>): void;
|
|
294
|
+
}
|
|
295
|
+
declare class StreamRecord {
|
|
296
|
+
type: 'stream';
|
|
297
|
+
errors: Array<GraphQLError>;
|
|
298
|
+
label: string | undefined;
|
|
299
|
+
path: Array<string | number>;
|
|
300
|
+
items: Array<unknown> | null;
|
|
301
|
+
promise: Promise<void>;
|
|
302
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
303
|
+
iterator: AsyncIterator<unknown> | undefined;
|
|
304
|
+
isCompletedIterator?: boolean;
|
|
305
|
+
isCompleted: boolean;
|
|
306
|
+
_exeContext: ExecutionContext;
|
|
307
|
+
_resolve?: (arg: MaybePromise<Array<unknown> | null>) => void;
|
|
308
|
+
constructor(opts: {
|
|
309
|
+
label: string | undefined;
|
|
310
|
+
path: Path | undefined;
|
|
311
|
+
iterator?: AsyncIterator<unknown>;
|
|
312
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
313
|
+
exeContext: ExecutionContext;
|
|
314
|
+
});
|
|
315
|
+
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
316
|
+
setIsCompletedIterator(): void;
|
|
317
|
+
}
|
|
318
|
+
declare type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
175
319
|
/**
|
|
176
320
|
* This method looks up the field on the given type definition.
|
|
177
321
|
* It has special casing for the three introspection fields,
|
|
@@ -184,3 +328,4 @@ export declare function createSourceEventStream(args: ExecutionArgs): MaybePromi
|
|
|
184
328
|
* @internal
|
|
185
329
|
*/
|
|
186
330
|
export declare function getFieldDef(schema: GraphQLSchema, parentType: GraphQLObjectType, fieldNode: FieldNode): Maybe<GraphQLField<unknown, unknown>>;
|
|
331
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GraphQLFormattedError,
|
|
2
|
-
import {
|
|
1
|
+
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema } from 'graphql';
|
|
2
|
+
import type { GraphQLError } from 'graphql';
|
|
3
|
+
import { Path, Maybe, MaybePromise, ExecutionResult } from '@graphql-tools/utils';
|
|
3
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
5
|
/**
|
|
5
6
|
* Terminology
|
|
@@ -26,25 +27,72 @@ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
|
26
27
|
* Namely, schema of the type system that is currently executing,
|
|
27
28
|
* and the fragments defined in the query document
|
|
28
29
|
*/
|
|
29
|
-
export interface ExecutionContext<TContext = any> {
|
|
30
|
+
export interface ExecutionContext<TVariables = any, TContext = any> {
|
|
30
31
|
schema: GraphQLSchema;
|
|
31
32
|
fragments: Record<string, FragmentDefinitionNode>;
|
|
32
33
|
rootValue: unknown;
|
|
33
34
|
contextValue: TContext;
|
|
34
35
|
operation: OperationDefinitionNode;
|
|
35
|
-
variableValues:
|
|
36
|
-
[variable: string]: unknown;
|
|
37
|
-
};
|
|
36
|
+
variableValues: TVariables;
|
|
38
37
|
fieldResolver: GraphQLFieldResolver<any, TContext>;
|
|
39
38
|
typeResolver: GraphQLTypeResolver<any, TContext>;
|
|
40
39
|
subscribeFieldResolver: GraphQLFieldResolver<any, TContext>;
|
|
41
40
|
errors: Array<GraphQLError>;
|
|
41
|
+
subsequentPayloads: Set<AsyncPayloadRecord>;
|
|
42
42
|
}
|
|
43
|
-
export interface FormattedExecutionResult<TData =
|
|
43
|
+
export interface FormattedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
44
44
|
errors?: ReadonlyArray<GraphQLFormattedError>;
|
|
45
45
|
data?: TData | null;
|
|
46
46
|
extensions?: TExtensions;
|
|
47
47
|
}
|
|
48
|
+
export interface ExperimentalIncrementalExecutionResults<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
49
|
+
initialResult: InitialIncrementalExecutionResult<TData, TExtensions>;
|
|
50
|
+
subsequentResults: AsyncGenerator<SubsequentIncrementalExecutionResult<TData, TExtensions>, void, void>;
|
|
51
|
+
}
|
|
52
|
+
export interface InitialIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends ExecutionResult<TData, TExtensions> {
|
|
53
|
+
hasNext: boolean;
|
|
54
|
+
incremental?: ReadonlyArray<IncrementalResult<TData, TExtensions>>;
|
|
55
|
+
extensions?: TExtensions;
|
|
56
|
+
}
|
|
57
|
+
export interface FormattedInitialIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends FormattedExecutionResult<TData, TExtensions> {
|
|
58
|
+
hasNext: boolean;
|
|
59
|
+
incremental?: ReadonlyArray<FormattedIncrementalResult<TData, TExtensions>>;
|
|
60
|
+
extensions?: TExtensions;
|
|
61
|
+
}
|
|
62
|
+
export interface SubsequentIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
63
|
+
hasNext: boolean;
|
|
64
|
+
incremental?: ReadonlyArray<IncrementalResult<TData, TExtensions>>;
|
|
65
|
+
extensions?: TExtensions;
|
|
66
|
+
}
|
|
67
|
+
export interface FormattedSubsequentIncrementalExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> {
|
|
68
|
+
hasNext: boolean;
|
|
69
|
+
incremental?: ReadonlyArray<FormattedIncrementalResult<TData, TExtensions>>;
|
|
70
|
+
extensions?: TExtensions;
|
|
71
|
+
}
|
|
72
|
+
export interface IncrementalDeferResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends ExecutionResult<TData, TExtensions> {
|
|
73
|
+
path?: ReadonlyArray<string | number>;
|
|
74
|
+
label?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface FormattedIncrementalDeferResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> extends FormattedExecutionResult<TData, TExtensions> {
|
|
77
|
+
path?: ReadonlyArray<string | number>;
|
|
78
|
+
label?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface IncrementalStreamResult<TData = Array<unknown>, TExtensions = Record<string, unknown>> {
|
|
81
|
+
errors?: ReadonlyArray<GraphQLError>;
|
|
82
|
+
items?: TData | null;
|
|
83
|
+
path?: ReadonlyArray<string | number>;
|
|
84
|
+
label?: string;
|
|
85
|
+
extensions?: TExtensions;
|
|
86
|
+
}
|
|
87
|
+
export interface FormattedIncrementalStreamResult<TData = Array<unknown>, TExtensions = Record<string, unknown>> {
|
|
88
|
+
errors?: ReadonlyArray<GraphQLFormattedError>;
|
|
89
|
+
items?: TData | null;
|
|
90
|
+
path?: ReadonlyArray<string | number>;
|
|
91
|
+
label?: string;
|
|
92
|
+
extensions?: TExtensions;
|
|
93
|
+
}
|
|
94
|
+
export declare type IncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = IncrementalDeferResult<TData, TExtensions> | IncrementalStreamResult<TData, TExtensions>;
|
|
95
|
+
export declare type FormattedIncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = FormattedIncrementalDeferResult<TData, TExtensions> | FormattedIncrementalStreamResult<TData, TExtensions>;
|
|
48
96
|
export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
49
97
|
schema: GraphQLSchema;
|
|
50
98
|
document: TypedDocumentNode<TData, TVariables>;
|
|
@@ -65,12 +113,27 @@ export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
|
65
113
|
*
|
|
66
114
|
* If the arguments to this function do not result in a legal execution context,
|
|
67
115
|
* a GraphQLError will be thrown immediately explaining the invalid input.
|
|
116
|
+
*
|
|
117
|
+
* This function does not support incremental delivery (`@defer` and `@stream`).
|
|
118
|
+
* If an operation which would defer or stream data is executed with this
|
|
119
|
+
* function, it will throw or resolve to an object containing an error instead.
|
|
120
|
+
* Use `experimentalExecuteIncrementally` if you want to support incremental
|
|
121
|
+
* delivery.
|
|
122
|
+
*/
|
|
123
|
+
export declare function execute<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<ExecutionResult<TData>>;
|
|
124
|
+
/**
|
|
125
|
+
* Implements the "Executing requests" section of the GraphQL specification,
|
|
126
|
+
* including `@defer` and `@stream` as proposed in
|
|
127
|
+
* https://github.com/graphql/graphql-spec/pull/742
|
|
128
|
+
*
|
|
129
|
+
* This function returns a Promise of an ExperimentalIncrementalExecutionResults
|
|
130
|
+
* object. This object either consists of a single ExecutionResult, or an
|
|
131
|
+
* object containing an `initialResult` and a stream of `subsequentResults`.
|
|
132
|
+
*
|
|
133
|
+
* If the arguments to this function do not result in a legal execution context,
|
|
134
|
+
* a GraphQLError will be thrown immediately explaining the invalid input.
|
|
68
135
|
*/
|
|
69
|
-
export declare function
|
|
70
|
-
[key: string]: any;
|
|
71
|
-
}, TVariables = {
|
|
72
|
-
[key: string]: any;
|
|
73
|
-
}, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<ExecutionResult<TData>>;
|
|
136
|
+
export declare function experimentalExecuteIncrementally<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<ExecutionResult<TData> | ExperimentalIncrementalExecutionResults<TData>>;
|
|
74
137
|
/**
|
|
75
138
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
|
76
139
|
* However, it guarantees to complete synchronously (or throw an error) assuming
|
|
@@ -93,16 +156,12 @@ export declare function assertValidExecutionArguments<TVariables>(schema: GraphQ
|
|
|
93
156
|
* TODO: consider no longer exporting this function
|
|
94
157
|
* @internal
|
|
95
158
|
*/
|
|
96
|
-
export declare function buildExecutionContext<TData =
|
|
97
|
-
[key: string]: any;
|
|
98
|
-
}, TVariables = {
|
|
99
|
-
[key: string]: any;
|
|
100
|
-
}, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): ReadonlyArray<GraphQLError> | ExecutionContext;
|
|
159
|
+
export declare function buildExecutionContext<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): ReadonlyArray<GraphQLError> | ExecutionContext;
|
|
101
160
|
/**
|
|
102
161
|
* TODO: consider no longer exporting this function
|
|
103
162
|
* @internal
|
|
104
163
|
*/
|
|
105
|
-
export declare function buildResolveInfo(exeContext: ExecutionContext, fieldDef: GraphQLField<unknown, unknown>, fieldNodes:
|
|
164
|
+
export declare function buildResolveInfo(exeContext: ExecutionContext, fieldDef: GraphQLField<unknown, unknown>, fieldNodes: Array<FieldNode>, parentType: GraphQLObjectType, path: Path): GraphQLResolveInfo;
|
|
106
165
|
/**
|
|
107
166
|
* If a resolveType function is not given, then a default resolve behavior is
|
|
108
167
|
* used which attempts two strategies:
|
|
@@ -130,19 +189,61 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
130
189
|
* is not an async iterable.
|
|
131
190
|
*
|
|
132
191
|
* If the client-provided arguments to this function do not result in a
|
|
133
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
134
|
-
*
|
|
192
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with descriptive
|
|
193
|
+
* errors and no data will be returned.
|
|
135
194
|
*
|
|
136
|
-
* If the source stream could not be created due to faulty subscription
|
|
137
|
-
*
|
|
195
|
+
* If the source stream could not be created due to faulty subscription resolver
|
|
196
|
+
* logic or underlying systems, the promise will resolve to a single
|
|
138
197
|
* ExecutionResult containing `errors` and no `data`.
|
|
139
198
|
*
|
|
140
199
|
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
141
200
|
* yields a stream of ExecutionResults representing the response stream.
|
|
142
201
|
*
|
|
143
|
-
*
|
|
202
|
+
* This function does not support incremental delivery (`@defer` and `@stream`).
|
|
203
|
+
* If an operation which would defer or stream data is executed with this
|
|
204
|
+
* function, each `InitialIncrementalExecutionResult` and
|
|
205
|
+
* `SubsequentIncrementalExecutionResult` in the result stream will be replaced
|
|
206
|
+
* with an `ExecutionResult` with a single error stating that defer/stream is
|
|
207
|
+
* not supported. Use `experimentalSubscribeIncrementally` if you want to
|
|
208
|
+
* support incremental delivery.
|
|
209
|
+
*
|
|
210
|
+
* Accepts an object with named arguments.
|
|
144
211
|
*/
|
|
145
212
|
export declare function subscribe(args: ExecutionArgs): MaybePromise<AsyncIterable<ExecutionResult> | ExecutionResult>;
|
|
213
|
+
/**
|
|
214
|
+
* Implements the "Subscribe" algorithm described in the GraphQL specification,
|
|
215
|
+
* including `@defer` and `@stream` as proposed in
|
|
216
|
+
* https://github.com/graphql/graphql-spec/pull/742
|
|
217
|
+
*
|
|
218
|
+
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
219
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
220
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
221
|
+
* is not an async iterable.
|
|
222
|
+
*
|
|
223
|
+
* If the client-provided arguments to this function do not result in a
|
|
224
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with descriptive
|
|
225
|
+
* errors and no data will be returned.
|
|
226
|
+
*
|
|
227
|
+
* If the source stream could not be created due to faulty subscription resolver
|
|
228
|
+
* logic or underlying systems, the promise will resolve to a single
|
|
229
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
230
|
+
*
|
|
231
|
+
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
232
|
+
* yields a stream of result representing the response stream.
|
|
233
|
+
*
|
|
234
|
+
* Each result may be an ExecutionResult with no `hasNext` (if executing the
|
|
235
|
+
* event did not use `@defer` or `@stream`), or an
|
|
236
|
+
* `InitialIncrementalExecutionResult` or `SubsequentIncrementalExecutionResult`
|
|
237
|
+
* (if executing the event used `@defer` or `@stream`). In the case of
|
|
238
|
+
* incremental execution results, each event produces a single
|
|
239
|
+
* `InitialIncrementalExecutionResult` followed by one or more
|
|
240
|
+
* `SubsequentIncrementalExecutionResult`s; all but the last have `hasNext: true`,
|
|
241
|
+
* and the last has `hasNext: false`. There is no interleaving between results
|
|
242
|
+
* generated from the same original event.
|
|
243
|
+
*
|
|
244
|
+
* Accepts an object with named arguments.
|
|
245
|
+
*/
|
|
246
|
+
export declare function experimentalSubscribeIncrementally(args: ExecutionArgs): MaybePromise<AsyncGenerator<ExecutionResult | InitialIncrementalExecutionResult | SubsequentIncrementalExecutionResult, void, void> | ExecutionResult>;
|
|
146
247
|
/**
|
|
147
248
|
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
148
249
|
* GraphQL specification, resolving the subscription source event stream.
|
|
@@ -172,6 +273,49 @@ export declare function subscribe(args: ExecutionArgs): MaybePromise<AsyncIterab
|
|
|
172
273
|
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
173
274
|
*/
|
|
174
275
|
export declare function createSourceEventStream(args: ExecutionArgs): MaybePromise<AsyncIterable<unknown> | ExecutionResult>;
|
|
276
|
+
declare class DeferredFragmentRecord {
|
|
277
|
+
type: 'defer';
|
|
278
|
+
errors: Array<GraphQLError>;
|
|
279
|
+
label: string | undefined;
|
|
280
|
+
path: Array<string | number>;
|
|
281
|
+
promise: Promise<void>;
|
|
282
|
+
data: Record<string, unknown> | null;
|
|
283
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
284
|
+
isCompleted: boolean;
|
|
285
|
+
_exeContext: ExecutionContext;
|
|
286
|
+
_resolve?: (arg: MaybePromise<Record<string, unknown> | null>) => void;
|
|
287
|
+
constructor(opts: {
|
|
288
|
+
label: string | undefined;
|
|
289
|
+
path: Path | undefined;
|
|
290
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
291
|
+
exeContext: ExecutionContext;
|
|
292
|
+
});
|
|
293
|
+
addData(data: MaybePromise<Record<string, unknown> | null>): void;
|
|
294
|
+
}
|
|
295
|
+
declare class StreamRecord {
|
|
296
|
+
type: 'stream';
|
|
297
|
+
errors: Array<GraphQLError>;
|
|
298
|
+
label: string | undefined;
|
|
299
|
+
path: Array<string | number>;
|
|
300
|
+
items: Array<unknown> | null;
|
|
301
|
+
promise: Promise<void>;
|
|
302
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
303
|
+
iterator: AsyncIterator<unknown> | undefined;
|
|
304
|
+
isCompletedIterator?: boolean;
|
|
305
|
+
isCompleted: boolean;
|
|
306
|
+
_exeContext: ExecutionContext;
|
|
307
|
+
_resolve?: (arg: MaybePromise<Array<unknown> | null>) => void;
|
|
308
|
+
constructor(opts: {
|
|
309
|
+
label: string | undefined;
|
|
310
|
+
path: Path | undefined;
|
|
311
|
+
iterator?: AsyncIterator<unknown>;
|
|
312
|
+
parentContext: AsyncPayloadRecord | undefined;
|
|
313
|
+
exeContext: ExecutionContext;
|
|
314
|
+
});
|
|
315
|
+
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
316
|
+
setIsCompletedIterator(): void;
|
|
317
|
+
}
|
|
318
|
+
declare type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
175
319
|
/**
|
|
176
320
|
* This method looks up the field on the given type definition.
|
|
177
321
|
* It has special casing for the three introspection fields,
|
|
@@ -184,3 +328,4 @@ export declare function createSourceEventStream(args: ExecutionArgs): MaybePromi
|
|
|
184
328
|
* @internal
|
|
185
329
|
*/
|
|
186
330
|
export declare function getFieldDef(schema: GraphQLSchema, parentType: GraphQLObjectType, fieldNode: FieldNode): Maybe<GraphQLField<unknown, unknown>>;
|
|
331
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare type AsyncIterableOrGenerator<T> = AsyncGenerator<T, void, void> | AsyncIterable<T>;
|
|
2
|
+
/**
|
|
3
|
+
* Given an AsyncIterable of AsyncIterables, flatten all yielded results into a
|
|
4
|
+
* single AsyncIterable.
|
|
5
|
+
*/
|
|
6
|
+
export declare function flattenAsyncIterable<T>(iterable: AsyncIterableOrGenerator<AsyncIterableOrGenerator<T>>): AsyncGenerator<T, void, void>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare type AsyncIterableOrGenerator<T> = AsyncGenerator<T, void, void> | AsyncIterable<T>;
|
|
2
|
+
/**
|
|
3
|
+
* Given an AsyncIterable of AsyncIterables, flatten all yielded results into a
|
|
4
|
+
* single AsyncIterable.
|
|
5
|
+
*/
|
|
6
|
+
export declare function flattenAsyncIterable<T>(iterable: AsyncIterableOrGenerator<AsyncIterableOrGenerator<T>>): AsyncGenerator<T, void, void>;
|
|
7
|
+
export {};
|