@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 @@
|
|
|
1
|
+
export declare function invariant(condition: boolean, message?: string): asserts condition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function invariant(condition: boolean, message?: string): asserts condition;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare type ResolvedObject<TData> = {
|
|
2
|
+
[TKey in keyof TData]: TData[TKey] extends Promise<infer TValue> ? TValue : TData[TKey];
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function transforms a JS object `Record<string, Promise<T>>` into
|
|
6
|
+
* a `Promise<Record<string, T>>`
|
|
7
|
+
*
|
|
8
|
+
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
9
|
+
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
10
|
+
*/
|
|
11
|
+
export declare function promiseForObject<TData>(object: TData): Promise<ResolvedObject<TData>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare type ResolvedObject<TData> = {
|
|
2
|
+
[TKey in keyof TData]: TData[TKey] extends Promise<infer TValue> ? TValue : TData[TKey];
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function transforms a JS object `Record<string, Promise<T>>` into
|
|
6
|
+
* a `Promise<Record<string, T>>`
|
|
7
|
+
*
|
|
8
|
+
* This is akin to bluebird's `Promise.props`, but implemented only using
|
|
9
|
+
* `Promise.all` so it will work with any implementation of ES6 promises.
|
|
10
|
+
*/
|
|
11
|
+
export declare function promiseForObject<TData>(object: TData): Promise<ResolvedObject<TData>>;
|
|
12
|
+
export {};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSourceEventStream = exports.subscribe = void 0;
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
6
|
-
const execute_js_1 = require("./execute.js");
|
|
7
|
-
/**
|
|
8
|
-
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
9
|
-
*
|
|
10
|
-
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
11
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
12
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
13
|
-
* is not an async iterable.
|
|
14
|
-
*
|
|
15
|
-
* If the client-provided arguments to this function do not result in a
|
|
16
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
17
|
-
* descriptive errors and no data will be returned.
|
|
18
|
-
*
|
|
19
|
-
* If the source stream could not be created due to faulty subscription
|
|
20
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
21
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
22
|
-
*
|
|
23
|
-
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
24
|
-
* yields a stream of ExecutionResults representing the response stream.
|
|
25
|
-
*
|
|
26
|
-
* Accepts either an object with named arguments, or individual arguments.
|
|
27
|
-
*/
|
|
28
|
-
async function subscribe(args) {
|
|
29
|
-
// Temporary for v15 to v16 migration. Remove in v17
|
|
30
|
-
console.assert(arguments.length < 2, 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.');
|
|
31
|
-
const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver, } = args;
|
|
32
|
-
const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver);
|
|
33
|
-
if (!(0, utils_1.isAsyncIterable)(resultOrStream)) {
|
|
34
|
-
return resultOrStream;
|
|
35
|
-
}
|
|
36
|
-
// For each payload yielded from a subscription, map it over the normal
|
|
37
|
-
// GraphQL `execute` function, with `payload` as the rootValue.
|
|
38
|
-
// This implements the "MapSourceToResponseEvent" algorithm described in
|
|
39
|
-
// the GraphQL specification. The `execute` function provides the
|
|
40
|
-
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
41
|
-
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
42
|
-
const mapSourceToResponse = (payload) => (0, execute_js_1.execute)({
|
|
43
|
-
schema,
|
|
44
|
-
document,
|
|
45
|
-
rootValue: payload,
|
|
46
|
-
contextValue,
|
|
47
|
-
variableValues,
|
|
48
|
-
operationName,
|
|
49
|
-
fieldResolver,
|
|
50
|
-
});
|
|
51
|
-
// Map every source value to a ExecutionResult value as described above.
|
|
52
|
-
return (0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), mapSourceToResponse);
|
|
53
|
-
}
|
|
54
|
-
exports.subscribe = subscribe;
|
|
55
|
-
/**
|
|
56
|
-
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
57
|
-
* GraphQL specification, resolving the subscription source event stream.
|
|
58
|
-
*
|
|
59
|
-
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
60
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
61
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
62
|
-
* is not an async iterable.
|
|
63
|
-
*
|
|
64
|
-
* If the client-provided arguments to this function do not result in a
|
|
65
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
66
|
-
* descriptive errors and no data will be returned.
|
|
67
|
-
*
|
|
68
|
-
* If the the source stream could not be created due to faulty subscription
|
|
69
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
70
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
71
|
-
*
|
|
72
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
73
|
-
* event stream returned by the resolver.
|
|
74
|
-
*
|
|
75
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
76
|
-
* a GraphQL execution for that event.
|
|
77
|
-
*
|
|
78
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
79
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
80
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
81
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
82
|
-
*/
|
|
83
|
-
async function createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver) {
|
|
84
|
-
// If arguments are missing or incorrectly typed, this is an internal
|
|
85
|
-
// developer mistake which should throw an early error.
|
|
86
|
-
(0, execute_js_1.assertValidExecutionArguments)(schema, document, variableValues);
|
|
87
|
-
// If a valid execution context cannot be created due to incorrect arguments,
|
|
88
|
-
// a "Response" with only errors is returned.
|
|
89
|
-
const exeContext = (0, execute_js_1.buildExecutionContext)({
|
|
90
|
-
schema,
|
|
91
|
-
document,
|
|
92
|
-
rootValue,
|
|
93
|
-
contextValue,
|
|
94
|
-
variableValues,
|
|
95
|
-
operationName,
|
|
96
|
-
subscribeFieldResolver,
|
|
97
|
-
});
|
|
98
|
-
// Return early errors if execution context failed.
|
|
99
|
-
if (!('schema' in exeContext)) {
|
|
100
|
-
return { errors: exeContext };
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
const eventStream = await executeSubscription(exeContext);
|
|
104
|
-
// Assert field returned an event stream, otherwise yield an error.
|
|
105
|
-
if (!(0, utils_1.isAsyncIterable)(eventStream)) {
|
|
106
|
-
throw new Error('Subscription field must return Async Iterable. ' + `Received: ${(0, utils_1.inspect)(eventStream)}.`);
|
|
107
|
-
}
|
|
108
|
-
return eventStream;
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
// If it GraphQLError, report it as an ExecutionResult, containing only errors and no data.
|
|
112
|
-
// Otherwise treat the error as a system-class error and re-throw it.
|
|
113
|
-
if (error instanceof graphql_1.GraphQLError) {
|
|
114
|
-
return { errors: [error] };
|
|
115
|
-
}
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.createSourceEventStream = createSourceEventStream;
|
|
120
|
-
async function executeSubscription(exeContext) {
|
|
121
|
-
var _a;
|
|
122
|
-
const { schema, fragments, operation, variableValues, rootValue } = exeContext;
|
|
123
|
-
const rootType = schema.getSubscriptionType();
|
|
124
|
-
if (rootType == null) {
|
|
125
|
-
throw (0, utils_1.createGraphQLError)('Schema is not configured to execute subscription operation.', { nodes: operation });
|
|
126
|
-
}
|
|
127
|
-
const rootFields = (0, utils_1.collectFields)(schema, fragments, variableValues, rootType, operation.selectionSet);
|
|
128
|
-
const [responseName, fieldNodes] = [...rootFields.entries()][0];
|
|
129
|
-
const fieldDef = (0, execute_js_1.getFieldDef)(schema, rootType, fieldNodes[0]);
|
|
130
|
-
if (!fieldDef) {
|
|
131
|
-
const fieldName = fieldNodes[0].name.value;
|
|
132
|
-
throw (0, utils_1.createGraphQLError)(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes });
|
|
133
|
-
}
|
|
134
|
-
const path = (0, utils_1.addPath)(undefined, responseName, rootType.name);
|
|
135
|
-
const info = (0, execute_js_1.buildResolveInfo)(exeContext, fieldDef, fieldNodes, rootType, path);
|
|
136
|
-
try {
|
|
137
|
-
// Implements the "ResolveFieldEventStream" algorithm from GraphQL specification.
|
|
138
|
-
// It differs from "ResolveFieldValue" due to providing a different `resolveFn`.
|
|
139
|
-
// Build a JS object of arguments from the field.arguments AST, using the
|
|
140
|
-
// variables scope to fulfill any variable references.
|
|
141
|
-
const args = (0, utils_1.getArgumentValues)(fieldDef, fieldNodes[0], variableValues);
|
|
142
|
-
// The resolve function's optional third argument is a context value that
|
|
143
|
-
// is provided to every resolve function within an execution. It is commonly
|
|
144
|
-
// used to represent an authenticated user, or request-specific caches.
|
|
145
|
-
const contextValue = exeContext.contextValue;
|
|
146
|
-
// Call the `subscribe()` resolver or the default resolver to produce an
|
|
147
|
-
// AsyncIterable yielding raw payloads.
|
|
148
|
-
const resolveFn = (_a = fieldDef.subscribe) !== null && _a !== void 0 ? _a : exeContext.subscribeFieldResolver;
|
|
149
|
-
const eventStream = await resolveFn(rootValue, args, contextValue, info);
|
|
150
|
-
if (eventStream instanceof Error) {
|
|
151
|
-
throw eventStream;
|
|
152
|
-
}
|
|
153
|
-
return eventStream;
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
throw (0, graphql_1.locatedError)(error, fieldNodes, (0, utils_1.pathToArray)(path));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { GraphQLError, locatedError } from 'graphql';
|
|
2
|
-
import { collectFields, mapAsyncIterator, inspect, isAsyncIterable, createGraphQLError, addPath, pathToArray, getArgumentValues, } from '@graphql-tools/utils';
|
|
3
|
-
import { assertValidExecutionArguments, buildExecutionContext, buildResolveInfo, execute, getFieldDef, } from './execute.js';
|
|
4
|
-
/**
|
|
5
|
-
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
6
|
-
*
|
|
7
|
-
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
8
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
9
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
10
|
-
* is not an async iterable.
|
|
11
|
-
*
|
|
12
|
-
* If the client-provided arguments to this function do not result in a
|
|
13
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
14
|
-
* descriptive errors and no data will be returned.
|
|
15
|
-
*
|
|
16
|
-
* If the source stream could not be created due to faulty subscription
|
|
17
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
18
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
19
|
-
*
|
|
20
|
-
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
21
|
-
* yields a stream of ExecutionResults representing the response stream.
|
|
22
|
-
*
|
|
23
|
-
* Accepts either an object with named arguments, or individual arguments.
|
|
24
|
-
*/
|
|
25
|
-
export async function subscribe(args) {
|
|
26
|
-
// Temporary for v15 to v16 migration. Remove in v17
|
|
27
|
-
console.assert(arguments.length < 2, 'graphql@16 dropped long-deprecated support for positional arguments, please pass an object instead.');
|
|
28
|
-
const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver, } = args;
|
|
29
|
-
const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver);
|
|
30
|
-
if (!isAsyncIterable(resultOrStream)) {
|
|
31
|
-
return resultOrStream;
|
|
32
|
-
}
|
|
33
|
-
// For each payload yielded from a subscription, map it over the normal
|
|
34
|
-
// GraphQL `execute` function, with `payload` as the rootValue.
|
|
35
|
-
// This implements the "MapSourceToResponseEvent" algorithm described in
|
|
36
|
-
// the GraphQL specification. The `execute` function provides the
|
|
37
|
-
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
38
|
-
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
39
|
-
const mapSourceToResponse = (payload) => execute({
|
|
40
|
-
schema,
|
|
41
|
-
document,
|
|
42
|
-
rootValue: payload,
|
|
43
|
-
contextValue,
|
|
44
|
-
variableValues,
|
|
45
|
-
operationName,
|
|
46
|
-
fieldResolver,
|
|
47
|
-
});
|
|
48
|
-
// Map every source value to a ExecutionResult value as described above.
|
|
49
|
-
return mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), mapSourceToResponse);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
53
|
-
* GraphQL specification, resolving the subscription source event stream.
|
|
54
|
-
*
|
|
55
|
-
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
56
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
57
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
58
|
-
* is not an async iterable.
|
|
59
|
-
*
|
|
60
|
-
* If the client-provided arguments to this function do not result in a
|
|
61
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
62
|
-
* descriptive errors and no data will be returned.
|
|
63
|
-
*
|
|
64
|
-
* If the the source stream could not be created due to faulty subscription
|
|
65
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
66
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
67
|
-
*
|
|
68
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
69
|
-
* event stream returned by the resolver.
|
|
70
|
-
*
|
|
71
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
72
|
-
* a GraphQL execution for that event.
|
|
73
|
-
*
|
|
74
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
75
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
76
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
77
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
78
|
-
*/
|
|
79
|
-
export async function createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver) {
|
|
80
|
-
// If arguments are missing or incorrectly typed, this is an internal
|
|
81
|
-
// developer mistake which should throw an early error.
|
|
82
|
-
assertValidExecutionArguments(schema, document, variableValues);
|
|
83
|
-
// If a valid execution context cannot be created due to incorrect arguments,
|
|
84
|
-
// a "Response" with only errors is returned.
|
|
85
|
-
const exeContext = buildExecutionContext({
|
|
86
|
-
schema,
|
|
87
|
-
document,
|
|
88
|
-
rootValue,
|
|
89
|
-
contextValue,
|
|
90
|
-
variableValues,
|
|
91
|
-
operationName,
|
|
92
|
-
subscribeFieldResolver,
|
|
93
|
-
});
|
|
94
|
-
// Return early errors if execution context failed.
|
|
95
|
-
if (!('schema' in exeContext)) {
|
|
96
|
-
return { errors: exeContext };
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
const eventStream = await executeSubscription(exeContext);
|
|
100
|
-
// Assert field returned an event stream, otherwise yield an error.
|
|
101
|
-
if (!isAsyncIterable(eventStream)) {
|
|
102
|
-
throw new Error('Subscription field must return Async Iterable. ' + `Received: ${inspect(eventStream)}.`);
|
|
103
|
-
}
|
|
104
|
-
return eventStream;
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
// If it GraphQLError, report it as an ExecutionResult, containing only errors and no data.
|
|
108
|
-
// Otherwise treat the error as a system-class error and re-throw it.
|
|
109
|
-
if (error instanceof GraphQLError) {
|
|
110
|
-
return { errors: [error] };
|
|
111
|
-
}
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function executeSubscription(exeContext) {
|
|
116
|
-
var _a;
|
|
117
|
-
const { schema, fragments, operation, variableValues, rootValue } = exeContext;
|
|
118
|
-
const rootType = schema.getSubscriptionType();
|
|
119
|
-
if (rootType == null) {
|
|
120
|
-
throw createGraphQLError('Schema is not configured to execute subscription operation.', { nodes: operation });
|
|
121
|
-
}
|
|
122
|
-
const rootFields = collectFields(schema, fragments, variableValues, rootType, operation.selectionSet);
|
|
123
|
-
const [responseName, fieldNodes] = [...rootFields.entries()][0];
|
|
124
|
-
const fieldDef = getFieldDef(schema, rootType, fieldNodes[0]);
|
|
125
|
-
if (!fieldDef) {
|
|
126
|
-
const fieldName = fieldNodes[0].name.value;
|
|
127
|
-
throw createGraphQLError(`The subscription field "${fieldName}" is not defined.`, { nodes: fieldNodes });
|
|
128
|
-
}
|
|
129
|
-
const path = addPath(undefined, responseName, rootType.name);
|
|
130
|
-
const info = buildResolveInfo(exeContext, fieldDef, fieldNodes, rootType, path);
|
|
131
|
-
try {
|
|
132
|
-
// Implements the "ResolveFieldEventStream" algorithm from GraphQL specification.
|
|
133
|
-
// It differs from "ResolveFieldValue" due to providing a different `resolveFn`.
|
|
134
|
-
// Build a JS object of arguments from the field.arguments AST, using the
|
|
135
|
-
// variables scope to fulfill any variable references.
|
|
136
|
-
const args = getArgumentValues(fieldDef, fieldNodes[0], variableValues);
|
|
137
|
-
// The resolve function's optional third argument is a context value that
|
|
138
|
-
// is provided to every resolve function within an execution. It is commonly
|
|
139
|
-
// used to represent an authenticated user, or request-specific caches.
|
|
140
|
-
const contextValue = exeContext.contextValue;
|
|
141
|
-
// Call the `subscribe()` resolver or the default resolver to produce an
|
|
142
|
-
// AsyncIterable yielding raw payloads.
|
|
143
|
-
const resolveFn = (_a = fieldDef.subscribe) !== null && _a !== void 0 ? _a : exeContext.subscribeFieldResolver;
|
|
144
|
-
const eventStream = await resolveFn(rootValue, args, contextValue, info);
|
|
145
|
-
if (eventStream instanceof Error) {
|
|
146
|
-
throw eventStream;
|
|
147
|
-
}
|
|
148
|
-
return eventStream;
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
throw locatedError(error, fieldNodes, pathToArray(path));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { GraphQLFieldResolver, GraphQLSchema } from 'graphql';
|
|
2
|
-
import { Maybe, ExecutionResult } from '@graphql-tools/utils';
|
|
3
|
-
import type { ExecutionArgs } from './execute.cjs';
|
|
4
|
-
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
|
-
/**
|
|
6
|
-
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
7
|
-
*
|
|
8
|
-
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
9
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
10
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
11
|
-
* is not an async iterable.
|
|
12
|
-
*
|
|
13
|
-
* If the client-provided arguments to this function do not result in a
|
|
14
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
15
|
-
* descriptive errors and no data will be returned.
|
|
16
|
-
*
|
|
17
|
-
* If the source stream could not be created due to faulty subscription
|
|
18
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
19
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
20
|
-
*
|
|
21
|
-
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
22
|
-
* yields a stream of ExecutionResults representing the response stream.
|
|
23
|
-
*
|
|
24
|
-
* Accepts either an object with named arguments, or individual arguments.
|
|
25
|
-
*/
|
|
26
|
-
export declare function subscribe(args: ExecutionArgs): Promise<AsyncIterable<ExecutionResult> | ExecutionResult>;
|
|
27
|
-
/**
|
|
28
|
-
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
29
|
-
* GraphQL specification, resolving the subscription source event stream.
|
|
30
|
-
*
|
|
31
|
-
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
32
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
33
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
34
|
-
* is not an async iterable.
|
|
35
|
-
*
|
|
36
|
-
* If the client-provided arguments to this function do not result in a
|
|
37
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
38
|
-
* descriptive errors and no data will be returned.
|
|
39
|
-
*
|
|
40
|
-
* If the the source stream could not be created due to faulty subscription
|
|
41
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
42
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
43
|
-
*
|
|
44
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
45
|
-
* event stream returned by the resolver.
|
|
46
|
-
*
|
|
47
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
48
|
-
* a GraphQL execution for that event.
|
|
49
|
-
*
|
|
50
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
51
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
52
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
53
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
54
|
-
*/
|
|
55
|
-
export declare function createSourceEventStream<TData = {
|
|
56
|
-
[key: string]: any;
|
|
57
|
-
}, TVariables = {
|
|
58
|
-
[key: string]: any;
|
|
59
|
-
}, TContext = any>(schema: GraphQLSchema, document: TypedDocumentNode<TData, TVariables>, rootValue?: unknown, contextValue?: TContext, variableValues?: TVariables, operationName?: Maybe<string>, subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, TContext>>): Promise<AsyncIterable<unknown> | ExecutionResult>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { GraphQLFieldResolver, GraphQLSchema } from 'graphql';
|
|
2
|
-
import { Maybe, ExecutionResult } from '@graphql-tools/utils';
|
|
3
|
-
import type { ExecutionArgs } from './execute.js';
|
|
4
|
-
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
|
-
/**
|
|
6
|
-
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
7
|
-
*
|
|
8
|
-
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
9
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
10
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
11
|
-
* is not an async iterable.
|
|
12
|
-
*
|
|
13
|
-
* If the client-provided arguments to this function do not result in a
|
|
14
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
15
|
-
* descriptive errors and no data will be returned.
|
|
16
|
-
*
|
|
17
|
-
* If the source stream could not be created due to faulty subscription
|
|
18
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
19
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
20
|
-
*
|
|
21
|
-
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
22
|
-
* yields a stream of ExecutionResults representing the response stream.
|
|
23
|
-
*
|
|
24
|
-
* Accepts either an object with named arguments, or individual arguments.
|
|
25
|
-
*/
|
|
26
|
-
export declare function subscribe(args: ExecutionArgs): Promise<AsyncIterable<ExecutionResult> | ExecutionResult>;
|
|
27
|
-
/**
|
|
28
|
-
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
29
|
-
* GraphQL specification, resolving the subscription source event stream.
|
|
30
|
-
*
|
|
31
|
-
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
32
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
33
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
34
|
-
* is not an async iterable.
|
|
35
|
-
*
|
|
36
|
-
* If the client-provided arguments to this function do not result in a
|
|
37
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
38
|
-
* descriptive errors and no data will be returned.
|
|
39
|
-
*
|
|
40
|
-
* If the the source stream could not be created due to faulty subscription
|
|
41
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
42
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
43
|
-
*
|
|
44
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
45
|
-
* event stream returned by the resolver.
|
|
46
|
-
*
|
|
47
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
48
|
-
* a GraphQL execution for that event.
|
|
49
|
-
*
|
|
50
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
51
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
52
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
53
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
54
|
-
*/
|
|
55
|
-
export declare function createSourceEventStream<TData = {
|
|
56
|
-
[key: string]: any;
|
|
57
|
-
}, TVariables = {
|
|
58
|
-
[key: string]: any;
|
|
59
|
-
}, TContext = any>(schema: GraphQLSchema, document: TypedDocumentNode<TData, TVariables>, rootValue?: unknown, contextValue?: TContext, variableValues?: TVariables, operationName?: Maybe<string>, subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, TContext>>): Promise<AsyncIterable<unknown> | ExecutionResult>;
|