@graphql-tools/executor 1.2.4 → 1.2.5-alpha-20240328134228-8452ac4e9c9e6970bfeb2ff7ab914352a0d7a646
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
|
@@ -830,15 +830,10 @@ function subscribe(args) {
|
|
|
830
830
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
831
831
|
}
|
|
832
832
|
exports.subscribe = subscribe;
|
|
833
|
-
function flattenIncrementalResults(incrementalResults
|
|
833
|
+
function flattenIncrementalResults(incrementalResults) {
|
|
834
834
|
const subsequentIterator = incrementalResults.subsequentResults;
|
|
835
835
|
let initialResultSent = false;
|
|
836
836
|
let done = false;
|
|
837
|
-
signal?.addEventListener('abort', () => {
|
|
838
|
-
done = true;
|
|
839
|
-
// we catch here to avoid unhandled promise rejection
|
|
840
|
-
subsequentIterator.throw?.(signal?.reason).catch(() => undefined);
|
|
841
|
-
});
|
|
842
837
|
return {
|
|
843
838
|
[Symbol.asyncIterator]() {
|
|
844
839
|
return this;
|
|
@@ -870,9 +865,9 @@ function flattenIncrementalResults(incrementalResults, signal) {
|
|
|
870
865
|
};
|
|
871
866
|
}
|
|
872
867
|
exports.flattenIncrementalResults = flattenIncrementalResults;
|
|
873
|
-
async function* ensureAsyncIterable(someExecutionResult
|
|
868
|
+
async function* ensureAsyncIterable(someExecutionResult) {
|
|
874
869
|
if ('initialResult' in someExecutionResult) {
|
|
875
|
-
yield* flattenIncrementalResults(someExecutionResult
|
|
870
|
+
yield* flattenIncrementalResults(someExecutionResult);
|
|
876
871
|
}
|
|
877
872
|
else {
|
|
878
873
|
yield someExecutionResult;
|
|
@@ -888,7 +883,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
888
883
|
// the GraphQL specification. The `execute` function provides the
|
|
889
884
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
890
885
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
891
|
-
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))
|
|
886
|
+
return (0, flattenAsyncIterable_js_1.flattenAsyncIterable)((0, utils_1.mapAsyncIterator)(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), (error) => {
|
|
892
887
|
const wrappedError = (0, utils_1.createGraphQLError)(error.message, {
|
|
893
888
|
originalError: error,
|
|
894
889
|
nodes: [exeContext.operation],
|
|
@@ -1185,16 +1180,20 @@ function getCompletedIncrementalResults(exeContext) {
|
|
|
1185
1180
|
}
|
|
1186
1181
|
function yieldSubsequentPayloads(exeContext) {
|
|
1187
1182
|
let isDone = false;
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1183
|
+
const abortPromise = new Promise((_, reject) => {
|
|
1184
|
+
exeContext.signal?.addEventListener('abort', () => {
|
|
1185
|
+
isDone = true;
|
|
1186
|
+
reject(exeContext.signal?.reason);
|
|
1187
|
+
});
|
|
1192
1188
|
});
|
|
1193
1189
|
async function next() {
|
|
1194
1190
|
if (isDone) {
|
|
1195
1191
|
return { value: undefined, done: true };
|
|
1196
1192
|
}
|
|
1197
|
-
await Promise.race(
|
|
1193
|
+
await Promise.race([
|
|
1194
|
+
abortPromise,
|
|
1195
|
+
...Array.from(exeContext.subsequentPayloads).map(p => p.promise),
|
|
1196
|
+
]);
|
|
1198
1197
|
if (isDone) {
|
|
1199
1198
|
// a different call to next has exhausted all payloads
|
|
1200
1199
|
return { value: undefined, done: true };
|
|
@@ -1249,11 +1248,10 @@ class DeferredFragmentRecord {
|
|
|
1249
1248
|
this._exeContext.subsequentPayloads.add(this);
|
|
1250
1249
|
this.isCompleted = false;
|
|
1251
1250
|
this.data = null;
|
|
1252
|
-
this.promise = new Promise(
|
|
1251
|
+
this.promise = new Promise(resolve => {
|
|
1253
1252
|
this._resolve = MaybePromise => {
|
|
1254
1253
|
resolve(MaybePromise);
|
|
1255
1254
|
};
|
|
1256
|
-
this._reject = reject;
|
|
1257
1255
|
}).then(data => {
|
|
1258
1256
|
this.data = data;
|
|
1259
1257
|
this.isCompleted = true;
|
|
@@ -1267,9 +1265,6 @@ class DeferredFragmentRecord {
|
|
|
1267
1265
|
}
|
|
1268
1266
|
this._resolve?.(data);
|
|
1269
1267
|
}
|
|
1270
|
-
cancel(reason) {
|
|
1271
|
-
this._reject?.(reason);
|
|
1272
|
-
}
|
|
1273
1268
|
}
|
|
1274
1269
|
class StreamRecord {
|
|
1275
1270
|
constructor(opts) {
|
|
@@ -1284,11 +1279,10 @@ class StreamRecord {
|
|
|
1284
1279
|
this._exeContext.subsequentPayloads.add(this);
|
|
1285
1280
|
this.isCompleted = false;
|
|
1286
1281
|
this.items = null;
|
|
1287
|
-
this.promise = new Promise(
|
|
1282
|
+
this.promise = new Promise(resolve => {
|
|
1288
1283
|
this._resolve = MaybePromise => {
|
|
1289
1284
|
resolve(MaybePromise);
|
|
1290
1285
|
};
|
|
1291
|
-
this._reject = reject;
|
|
1292
1286
|
}).then(items => {
|
|
1293
1287
|
this.items = items;
|
|
1294
1288
|
this.isCompleted = true;
|
|
@@ -1305,9 +1299,6 @@ class StreamRecord {
|
|
|
1305
1299
|
setIsCompletedIterator() {
|
|
1306
1300
|
this.isCompletedIterator = true;
|
|
1307
1301
|
}
|
|
1308
|
-
cancel(reason) {
|
|
1309
|
-
this._reject?.(reason);
|
|
1310
|
-
}
|
|
1311
1302
|
}
|
|
1312
1303
|
function isStreamPayload(asyncPayload) {
|
|
1313
1304
|
return asyncPayload.type === 'stream';
|
|
@@ -15,7 +15,7 @@ function normalizedExecutor(args) {
|
|
|
15
15
|
return new value_or_promise_1.ValueOrPromise(() => (0, execute_js_1.execute)(args))
|
|
16
16
|
.then((result) => {
|
|
17
17
|
if ('initialResult' in result) {
|
|
18
|
-
return (0, execute_js_1.flattenIncrementalResults)(result
|
|
18
|
+
return (0, execute_js_1.flattenIncrementalResults)(result);
|
|
19
19
|
}
|
|
20
20
|
return result;
|
|
21
21
|
})
|
package/esm/execution/execute.js
CHANGED
|
@@ -819,15 +819,10 @@ export function subscribe(args) {
|
|
|
819
819
|
}
|
|
820
820
|
return mapSourceToResponse(exeContext, resultOrStream);
|
|
821
821
|
}
|
|
822
|
-
export function flattenIncrementalResults(incrementalResults
|
|
822
|
+
export function flattenIncrementalResults(incrementalResults) {
|
|
823
823
|
const subsequentIterator = incrementalResults.subsequentResults;
|
|
824
824
|
let initialResultSent = false;
|
|
825
825
|
let done = false;
|
|
826
|
-
signal?.addEventListener('abort', () => {
|
|
827
|
-
done = true;
|
|
828
|
-
// we catch here to avoid unhandled promise rejection
|
|
829
|
-
subsequentIterator.throw?.(signal?.reason).catch(() => undefined);
|
|
830
|
-
});
|
|
831
826
|
return {
|
|
832
827
|
[Symbol.asyncIterator]() {
|
|
833
828
|
return this;
|
|
@@ -858,9 +853,9 @@ export function flattenIncrementalResults(incrementalResults, signal) {
|
|
|
858
853
|
},
|
|
859
854
|
};
|
|
860
855
|
}
|
|
861
|
-
async function* ensureAsyncIterable(someExecutionResult
|
|
856
|
+
async function* ensureAsyncIterable(someExecutionResult) {
|
|
862
857
|
if ('initialResult' in someExecutionResult) {
|
|
863
|
-
yield* flattenIncrementalResults(someExecutionResult
|
|
858
|
+
yield* flattenIncrementalResults(someExecutionResult);
|
|
864
859
|
}
|
|
865
860
|
else {
|
|
866
861
|
yield someExecutionResult;
|
|
@@ -876,7 +871,7 @@ function mapSourceToResponse(exeContext, resultOrStream) {
|
|
|
876
871
|
// the GraphQL specification. The `execute` function provides the
|
|
877
872
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
878
873
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
879
|
-
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))
|
|
874
|
+
return flattenAsyncIterable(mapAsyncIterator(resultOrStream[Symbol.asyncIterator](), async (payload) => ensureAsyncIterable(await executeImpl(buildPerEventExecutionContext(exeContext, payload))), (error) => {
|
|
880
875
|
const wrappedError = createGraphQLError(error.message, {
|
|
881
876
|
originalError: error,
|
|
882
877
|
nodes: [exeContext.operation],
|
|
@@ -1173,16 +1168,20 @@ function getCompletedIncrementalResults(exeContext) {
|
|
|
1173
1168
|
}
|
|
1174
1169
|
function yieldSubsequentPayloads(exeContext) {
|
|
1175
1170
|
let isDone = false;
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1171
|
+
const abortPromise = new Promise((_, reject) => {
|
|
1172
|
+
exeContext.signal?.addEventListener('abort', () => {
|
|
1173
|
+
isDone = true;
|
|
1174
|
+
reject(exeContext.signal?.reason);
|
|
1175
|
+
});
|
|
1180
1176
|
});
|
|
1181
1177
|
async function next() {
|
|
1182
1178
|
if (isDone) {
|
|
1183
1179
|
return { value: undefined, done: true };
|
|
1184
1180
|
}
|
|
1185
|
-
await Promise.race(
|
|
1181
|
+
await Promise.race([
|
|
1182
|
+
abortPromise,
|
|
1183
|
+
...Array.from(exeContext.subsequentPayloads).map(p => p.promise),
|
|
1184
|
+
]);
|
|
1186
1185
|
if (isDone) {
|
|
1187
1186
|
// a different call to next has exhausted all payloads
|
|
1188
1187
|
return { value: undefined, done: true };
|
|
@@ -1237,11 +1236,10 @@ class DeferredFragmentRecord {
|
|
|
1237
1236
|
this._exeContext.subsequentPayloads.add(this);
|
|
1238
1237
|
this.isCompleted = false;
|
|
1239
1238
|
this.data = null;
|
|
1240
|
-
this.promise = new Promise(
|
|
1239
|
+
this.promise = new Promise(resolve => {
|
|
1241
1240
|
this._resolve = MaybePromise => {
|
|
1242
1241
|
resolve(MaybePromise);
|
|
1243
1242
|
};
|
|
1244
|
-
this._reject = reject;
|
|
1245
1243
|
}).then(data => {
|
|
1246
1244
|
this.data = data;
|
|
1247
1245
|
this.isCompleted = true;
|
|
@@ -1255,9 +1253,6 @@ class DeferredFragmentRecord {
|
|
|
1255
1253
|
}
|
|
1256
1254
|
this._resolve?.(data);
|
|
1257
1255
|
}
|
|
1258
|
-
cancel(reason) {
|
|
1259
|
-
this._reject?.(reason);
|
|
1260
|
-
}
|
|
1261
1256
|
}
|
|
1262
1257
|
class StreamRecord {
|
|
1263
1258
|
constructor(opts) {
|
|
@@ -1272,11 +1267,10 @@ class StreamRecord {
|
|
|
1272
1267
|
this._exeContext.subsequentPayloads.add(this);
|
|
1273
1268
|
this.isCompleted = false;
|
|
1274
1269
|
this.items = null;
|
|
1275
|
-
this.promise = new Promise(
|
|
1270
|
+
this.promise = new Promise(resolve => {
|
|
1276
1271
|
this._resolve = MaybePromise => {
|
|
1277
1272
|
resolve(MaybePromise);
|
|
1278
1273
|
};
|
|
1279
|
-
this._reject = reject;
|
|
1280
1274
|
}).then(items => {
|
|
1281
1275
|
this.items = items;
|
|
1282
1276
|
this.isCompleted = true;
|
|
@@ -1293,9 +1287,6 @@ class StreamRecord {
|
|
|
1293
1287
|
setIsCompletedIterator() {
|
|
1294
1288
|
this.isCompletedIterator = true;
|
|
1295
1289
|
}
|
|
1296
|
-
cancel(reason) {
|
|
1297
|
-
this._reject?.(reason);
|
|
1298
|
-
}
|
|
1299
1290
|
}
|
|
1300
1291
|
function isStreamPayload(asyncPayload) {
|
|
1301
1292
|
return asyncPayload.type === 'stream';
|
|
@@ -12,7 +12,7 @@ export function normalizedExecutor(args) {
|
|
|
12
12
|
return new ValueOrPromise(() => execute(args))
|
|
13
13
|
.then((result) => {
|
|
14
14
|
if ('initialResult' in result) {
|
|
15
|
-
return flattenIncrementalResults(result
|
|
15
|
+
return flattenIncrementalResults(result);
|
|
16
16
|
}
|
|
17
17
|
return result;
|
|
18
18
|
})
|
package/package.json
CHANGED
|
@@ -204,7 +204,7 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
204
204
|
* Accepts an object with named arguments.
|
|
205
205
|
*/
|
|
206
206
|
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>>;
|
|
207
|
-
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData
|
|
207
|
+
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
208
208
|
declare class DeferredFragmentRecord {
|
|
209
209
|
type: 'defer';
|
|
210
210
|
errors: Array<GraphQLError>;
|
|
@@ -216,7 +216,6 @@ declare class DeferredFragmentRecord {
|
|
|
216
216
|
isCompleted: boolean;
|
|
217
217
|
_exeContext: ExecutionContext;
|
|
218
218
|
_resolve?: (arg: MaybePromise<Record<string, unknown> | null>) => void;
|
|
219
|
-
_reject?: (reason: unknown) => void;
|
|
220
219
|
constructor(opts: {
|
|
221
220
|
label: string | undefined;
|
|
222
221
|
path: Path | undefined;
|
|
@@ -224,7 +223,6 @@ declare class DeferredFragmentRecord {
|
|
|
224
223
|
exeContext: ExecutionContext;
|
|
225
224
|
});
|
|
226
225
|
addData(data: MaybePromise<Record<string, unknown> | null>): void;
|
|
227
|
-
cancel(reason: unknown): void;
|
|
228
226
|
}
|
|
229
227
|
declare class StreamRecord {
|
|
230
228
|
type: 'stream';
|
|
@@ -239,7 +237,6 @@ declare class StreamRecord {
|
|
|
239
237
|
isCompleted: boolean;
|
|
240
238
|
_exeContext: ExecutionContext;
|
|
241
239
|
_resolve?: (arg: MaybePromise<Array<unknown> | null>) => void;
|
|
242
|
-
_reject?: (reason: unknown) => void;
|
|
243
240
|
constructor(opts: {
|
|
244
241
|
label: string | undefined;
|
|
245
242
|
path: Path | undefined;
|
|
@@ -249,7 +246,6 @@ declare class StreamRecord {
|
|
|
249
246
|
});
|
|
250
247
|
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
251
248
|
setIsCompletedIterator(): void;
|
|
252
|
-
cancel(reason: unknown): void;
|
|
253
249
|
}
|
|
254
250
|
type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
255
251
|
/**
|
|
@@ -204,7 +204,7 @@ export declare const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown
|
|
|
204
204
|
* Accepts an object with named arguments.
|
|
205
205
|
*/
|
|
206
206
|
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>>;
|
|
207
|
-
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData
|
|
207
|
+
export declare function flattenIncrementalResults<TData>(incrementalResults: IncrementalExecutionResults<TData>): AsyncGenerator<SubsequentIncrementalExecutionResult<TData, Record<string, unknown>>, void, void>;
|
|
208
208
|
declare class DeferredFragmentRecord {
|
|
209
209
|
type: 'defer';
|
|
210
210
|
errors: Array<GraphQLError>;
|
|
@@ -216,7 +216,6 @@ declare class DeferredFragmentRecord {
|
|
|
216
216
|
isCompleted: boolean;
|
|
217
217
|
_exeContext: ExecutionContext;
|
|
218
218
|
_resolve?: (arg: MaybePromise<Record<string, unknown> | null>) => void;
|
|
219
|
-
_reject?: (reason: unknown) => void;
|
|
220
219
|
constructor(opts: {
|
|
221
220
|
label: string | undefined;
|
|
222
221
|
path: Path | undefined;
|
|
@@ -224,7 +223,6 @@ declare class DeferredFragmentRecord {
|
|
|
224
223
|
exeContext: ExecutionContext;
|
|
225
224
|
});
|
|
226
225
|
addData(data: MaybePromise<Record<string, unknown> | null>): void;
|
|
227
|
-
cancel(reason: unknown): void;
|
|
228
226
|
}
|
|
229
227
|
declare class StreamRecord {
|
|
230
228
|
type: 'stream';
|
|
@@ -239,7 +237,6 @@ declare class StreamRecord {
|
|
|
239
237
|
isCompleted: boolean;
|
|
240
238
|
_exeContext: ExecutionContext;
|
|
241
239
|
_resolve?: (arg: MaybePromise<Array<unknown> | null>) => void;
|
|
242
|
-
_reject?: (reason: unknown) => void;
|
|
243
240
|
constructor(opts: {
|
|
244
241
|
label: string | undefined;
|
|
245
242
|
path: Path | undefined;
|
|
@@ -249,7 +246,6 @@ declare class StreamRecord {
|
|
|
249
246
|
});
|
|
250
247
|
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
251
248
|
setIsCompletedIterator(): void;
|
|
252
|
-
cancel(reason: unknown): void;
|
|
253
249
|
}
|
|
254
250
|
type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
255
251
|
/**
|