@graphql-tools/executor 0.0.17 → 0.0.18-alpha-20230418100948-e2667413
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isIncrementalResult = exports.getFieldDef = exports.
|
|
3
|
+
exports.isIncrementalResult = exports.getFieldDef = exports.flattenIncrementalResults = exports.subscribe = exports.defaultFieldResolver = exports.defaultTypeResolver = exports.buildResolveInfo = exports.buildExecutionContext = exports.assertValidExecutionArguments = exports.executeSync = exports.execute = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const utils_1 = require("@graphql-tools/utils");
|
|
6
6
|
const values_js_1 = require("./values.js");
|
|
@@ -815,61 +815,16 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
815
815
|
// the GraphQL specification. The `execute` function provides the
|
|
816
816
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
817
817
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
818
|
-
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))))
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
826
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
827
|
-
* is not an async iterable.
|
|
828
|
-
*
|
|
829
|
-
* If the client-provided arguments to this function do not result in a
|
|
830
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
831
|
-
* descriptive errors and no data will be returned.
|
|
832
|
-
*
|
|
833
|
-
* If the the source stream could not be created due to faulty subscription
|
|
834
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
835
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
836
|
-
*
|
|
837
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
838
|
-
* event stream returned by the resolver.
|
|
839
|
-
*
|
|
840
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
841
|
-
* a GraphQL execution for that event.
|
|
842
|
-
*
|
|
843
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
844
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
845
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
846
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
847
|
-
*/
|
|
848
|
-
function createSourceEventStream(args) {
|
|
849
|
-
// If a valid execution context cannot be created due to incorrect arguments,
|
|
850
|
-
// a "Response" with only errors is returned.
|
|
851
|
-
const exeContext = buildExecutionContext(args);
|
|
852
|
-
// Return early errors if execution context failed.
|
|
853
|
-
if (!('schema' in exeContext)) {
|
|
854
|
-
return {
|
|
855
|
-
errors: exeContext.map(e => {
|
|
856
|
-
var _a;
|
|
857
|
-
Object.defineProperty(e, 'extensions', {
|
|
858
|
-
value: {
|
|
859
|
-
...e.extensions,
|
|
860
|
-
http: {
|
|
861
|
-
...(_a = e.extensions) === null || _a === void 0 ? void 0 : _a['http'],
|
|
862
|
-
status: 400,
|
|
863
|
-
},
|
|
864
|
-
},
|
|
865
|
-
});
|
|
866
|
-
return e;
|
|
867
|
-
}),
|
|
818
|
+
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), async function* (error) {
|
|
819
|
+
const wrappedError = (0, utils_1.createGraphQLError)(error.message, {
|
|
820
|
+
originalError: error,
|
|
821
|
+
nodes: [exeContext.operation],
|
|
822
|
+
});
|
|
823
|
+
yield {
|
|
824
|
+
errors: [wrappedError],
|
|
868
825
|
};
|
|
869
|
-
}
|
|
870
|
-
return createSourceEventStreamImpl(exeContext);
|
|
826
|
+
}));
|
|
871
827
|
}
|
|
872
|
-
exports.createSourceEventStream = createSourceEventStream;
|
|
873
828
|
function createSourceEventStreamImpl(exeContext) {
|
|
874
829
|
try {
|
|
875
830
|
const eventStream = executeSubscription(exeContext);
|
package/esm/execution/execute.js
CHANGED
|
@@ -803,59 +803,15 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
803
803
|
// the GraphQL specification. The `execute` function provides the
|
|
804
804
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
805
805
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
806
|
-
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))))
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
814
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
815
|
-
* is not an async iterable.
|
|
816
|
-
*
|
|
817
|
-
* If the client-provided arguments to this function do not result in a
|
|
818
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
819
|
-
* descriptive errors and no data will be returned.
|
|
820
|
-
*
|
|
821
|
-
* If the the source stream could not be created due to faulty subscription
|
|
822
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
823
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
824
|
-
*
|
|
825
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
826
|
-
* event stream returned by the resolver.
|
|
827
|
-
*
|
|
828
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
829
|
-
* a GraphQL execution for that event.
|
|
830
|
-
*
|
|
831
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
832
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
833
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
834
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
835
|
-
*/
|
|
836
|
-
export function createSourceEventStream(args) {
|
|
837
|
-
// If a valid execution context cannot be created due to incorrect arguments,
|
|
838
|
-
// a "Response" with only errors is returned.
|
|
839
|
-
const exeContext = buildExecutionContext(args);
|
|
840
|
-
// Return early errors if execution context failed.
|
|
841
|
-
if (!('schema' in exeContext)) {
|
|
842
|
-
return {
|
|
843
|
-
errors: exeContext.map(e => {
|
|
844
|
-
var _a;
|
|
845
|
-
Object.defineProperty(e, 'extensions', {
|
|
846
|
-
value: {
|
|
847
|
-
...e.extensions,
|
|
848
|
-
http: {
|
|
849
|
-
...(_a = e.extensions) === null || _a === void 0 ? void 0 : _a['http'],
|
|
850
|
-
status: 400,
|
|
851
|
-
},
|
|
852
|
-
},
|
|
853
|
-
});
|
|
854
|
-
return e;
|
|
855
|
-
}),
|
|
806
|
+
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), async function* (error) {
|
|
807
|
+
const wrappedError = createGraphQLError(error.message, {
|
|
808
|
+
originalError: error,
|
|
809
|
+
nodes: [exeContext.operation],
|
|
810
|
+
});
|
|
811
|
+
yield {
|
|
812
|
+
errors: [wrappedError],
|
|
856
813
|
};
|
|
857
|
-
}
|
|
858
|
-
return createSourceEventStreamImpl(exeContext);
|
|
814
|
+
}));
|
|
859
815
|
}
|
|
860
816
|
function createSourceEventStreamImpl(exeContext) {
|
|
861
817
|
try {
|
package/package.json
CHANGED
|
@@ -203,35 +203,6 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
203
203
|
*/
|
|
204
204
|
export declare function subscribe<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<AsyncGenerator<SingularExecutionResult<TData> | InitialIncrementalExecutionResult<TData> | SubsequentIncrementalExecutionResult<TData>, void, void> | SingularExecutionResult<TData>>;
|
|
205
205
|
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
206
|
-
/**
|
|
207
|
-
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
208
|
-
* GraphQL specification, resolving the subscription source event stream.
|
|
209
|
-
*
|
|
210
|
-
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
211
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
212
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
213
|
-
* is not an async iterable.
|
|
214
|
-
*
|
|
215
|
-
* If the client-provided arguments to this function do not result in a
|
|
216
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
217
|
-
* descriptive errors and no data will be returned.
|
|
218
|
-
*
|
|
219
|
-
* If the the source stream could not be created due to faulty subscription
|
|
220
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
221
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
222
|
-
*
|
|
223
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
224
|
-
* event stream returned by the resolver.
|
|
225
|
-
*
|
|
226
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
227
|
-
* a GraphQL execution for that event.
|
|
228
|
-
*
|
|
229
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
230
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
231
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
232
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
233
|
-
*/
|
|
234
|
-
export declare function createSourceEventStream(args: ExecutionArgs): MaybePromise<AsyncIterable<unknown> | SingularExecutionResult>;
|
|
235
206
|
declare class DeferredFragmentRecord {
|
|
236
207
|
type: 'defer';
|
|
237
208
|
errors: Array<GraphQLError>;
|
|
@@ -203,35 +203,6 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
203
203
|
*/
|
|
204
204
|
export declare function subscribe<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<AsyncGenerator<SingularExecutionResult<TData> | InitialIncrementalExecutionResult<TData> | SubsequentIncrementalExecutionResult<TData>, void, void> | SingularExecutionResult<TData>>;
|
|
205
205
|
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
206
|
-
/**
|
|
207
|
-
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
208
|
-
* GraphQL specification, resolving the subscription source event stream.
|
|
209
|
-
*
|
|
210
|
-
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
211
|
-
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
212
|
-
* other arguments to this function are invalid, or if the resolved event stream
|
|
213
|
-
* is not an async iterable.
|
|
214
|
-
*
|
|
215
|
-
* If the client-provided arguments to this function do not result in a
|
|
216
|
-
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
217
|
-
* descriptive errors and no data will be returned.
|
|
218
|
-
*
|
|
219
|
-
* If the the source stream could not be created due to faulty subscription
|
|
220
|
-
* resolver logic or underlying systems, the promise will resolve to a single
|
|
221
|
-
* ExecutionResult containing `errors` and no `data`.
|
|
222
|
-
*
|
|
223
|
-
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
224
|
-
* event stream returned by the resolver.
|
|
225
|
-
*
|
|
226
|
-
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
227
|
-
* a GraphQL execution for that event.
|
|
228
|
-
*
|
|
229
|
-
* This may be useful when hosting the stateful subscription service in a
|
|
230
|
-
* different process or machine than the stateless GraphQL execution engine,
|
|
231
|
-
* or otherwise separating these two steps. For more on this, see the
|
|
232
|
-
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
233
|
-
*/
|
|
234
|
-
export declare function createSourceEventStream(args: ExecutionArgs): MaybePromise<AsyncIterable<unknown> | SingularExecutionResult>;
|
|
235
206
|
declare class DeferredFragmentRecord {
|
|
236
207
|
type: 'defer';
|
|
237
208
|
errors: Array<GraphQLError>;
|