@graphql-tools/executor 1.2.3 → 1.2.4-rc-20240322082015-3ea3fdfe4b4811657bcf474a0bf7b1187f3c4c09
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 +22 -1
- package/esm/execution/execute.js +22 -1
- package/package.json +1 -1
package/cjs/execution/execute.js
CHANGED
|
@@ -51,6 +51,9 @@ function execute(args) {
|
|
|
51
51
|
}
|
|
52
52
|
exports.execute = execute;
|
|
53
53
|
function executeImpl(exeContext) {
|
|
54
|
+
if (exeContext.signal?.aborted) {
|
|
55
|
+
throw exeContext.signal.reason;
|
|
56
|
+
}
|
|
54
57
|
// Return a Promise that will eventually resolve to the data described by
|
|
55
58
|
// The "Response" section of the GraphQL specification.
|
|
56
59
|
//
|
|
@@ -62,7 +65,7 @@ function executeImpl(exeContext) {
|
|
|
62
65
|
// Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
63
66
|
// at which point we still log the error and null the parent field, which
|
|
64
67
|
// in this case is the entire response.
|
|
65
|
-
|
|
68
|
+
const result = new value_or_promise_1.ValueOrPromise(() => executeOperation(exeContext))
|
|
66
69
|
.then(data => {
|
|
67
70
|
const initialResult = buildResponse(data, exeContext.errors);
|
|
68
71
|
if (exeContext.subsequentPayloads.size > 0) {
|
|
@@ -80,6 +83,24 @@ function executeImpl(exeContext) {
|
|
|
80
83
|
return buildResponse(null, exeContext.errors);
|
|
81
84
|
})
|
|
82
85
|
.resolve();
|
|
86
|
+
if (!exeContext.signal || 'initialResult' in result || 'then' in result === false) {
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
let resolve;
|
|
90
|
+
let reject;
|
|
91
|
+
const abortP = new Promise((_resolve, _reject) => {
|
|
92
|
+
resolve = _resolve;
|
|
93
|
+
reject = _reject;
|
|
94
|
+
});
|
|
95
|
+
function abortListener() {
|
|
96
|
+
reject(exeContext.signal?.reason);
|
|
97
|
+
}
|
|
98
|
+
exeContext.signal.addEventListener('abort', abortListener);
|
|
99
|
+
result.then(() => {
|
|
100
|
+
exeContext.signal?.removeEventListener('abort', abortListener);
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
return Promise.race([abortP, result]);
|
|
83
104
|
}
|
|
84
105
|
/**
|
|
85
106
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
package/esm/execution/execute.js
CHANGED
|
@@ -47,6 +47,9 @@ export function execute(args) {
|
|
|
47
47
|
return executeImpl(exeContext);
|
|
48
48
|
}
|
|
49
49
|
function executeImpl(exeContext) {
|
|
50
|
+
if (exeContext.signal?.aborted) {
|
|
51
|
+
throw exeContext.signal.reason;
|
|
52
|
+
}
|
|
50
53
|
// Return a Promise that will eventually resolve to the data described by
|
|
51
54
|
// The "Response" section of the GraphQL specification.
|
|
52
55
|
//
|
|
@@ -58,7 +61,7 @@ function executeImpl(exeContext) {
|
|
|
58
61
|
// Errors from sub-fields of a NonNull type may propagate to the top level,
|
|
59
62
|
// at which point we still log the error and null the parent field, which
|
|
60
63
|
// in this case is the entire response.
|
|
61
|
-
|
|
64
|
+
const result = new ValueOrPromise(() => executeOperation(exeContext))
|
|
62
65
|
.then(data => {
|
|
63
66
|
const initialResult = buildResponse(data, exeContext.errors);
|
|
64
67
|
if (exeContext.subsequentPayloads.size > 0) {
|
|
@@ -76,6 +79,24 @@ function executeImpl(exeContext) {
|
|
|
76
79
|
return buildResponse(null, exeContext.errors);
|
|
77
80
|
})
|
|
78
81
|
.resolve();
|
|
82
|
+
if (!exeContext.signal || 'initialResult' in result || 'then' in result === false) {
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
let resolve;
|
|
86
|
+
let reject;
|
|
87
|
+
const abortP = new Promise((_resolve, _reject) => {
|
|
88
|
+
resolve = _resolve;
|
|
89
|
+
reject = _reject;
|
|
90
|
+
});
|
|
91
|
+
function abortListener() {
|
|
92
|
+
reject(exeContext.signal?.reason);
|
|
93
|
+
}
|
|
94
|
+
exeContext.signal.addEventListener('abort', abortListener);
|
|
95
|
+
result.then(() => {
|
|
96
|
+
exeContext.signal?.removeEventListener('abort', abortListener);
|
|
97
|
+
resolve();
|
|
98
|
+
});
|
|
99
|
+
return Promise.race([abortP, result]);
|
|
79
100
|
}
|
|
80
101
|
/**
|
|
81
102
|
* Also implements the "Executing requests" section of the GraphQL specification.
|
package/package.json
CHANGED