@graphql-tools/executor 1.3.14 → 1.4.0
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 +27 -15
- package/esm/execution/execute.js +27 -15
- package/package.json +1 -1
package/cjs/execution/execute.js
CHANGED
|
@@ -162,7 +162,11 @@ function buildExecutionContext(args) {
|
|
|
162
162
|
if (operationName == null) {
|
|
163
163
|
if (operation !== undefined) {
|
|
164
164
|
return [
|
|
165
|
-
(0, utils_1.createGraphQLError)('Must provide operation name if query contains multiple operations.'
|
|
165
|
+
(0, utils_1.createGraphQLError)('Must provide operation name if query contains multiple operations.', {
|
|
166
|
+
extensions: {
|
|
167
|
+
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
166
170
|
];
|
|
167
171
|
}
|
|
168
172
|
operation = definition;
|
|
@@ -177,9 +181,21 @@ function buildExecutionContext(args) {
|
|
|
177
181
|
}
|
|
178
182
|
if (operation == null) {
|
|
179
183
|
if (operationName != null) {
|
|
180
|
-
return [
|
|
184
|
+
return [
|
|
185
|
+
(0, utils_1.createGraphQLError)(`Unknown operation named "${operationName}".`, {
|
|
186
|
+
extensions: {
|
|
187
|
+
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
];
|
|
181
191
|
}
|
|
182
|
-
return [
|
|
192
|
+
return [
|
|
193
|
+
(0, utils_1.createGraphQLError)('Must provide an operation.', {
|
|
194
|
+
extensions: {
|
|
195
|
+
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
198
|
+
];
|
|
183
199
|
}
|
|
184
200
|
// FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
185
201
|
/* c8 ignore next */
|
|
@@ -803,19 +819,15 @@ function subscribe(args) {
|
|
|
803
819
|
const exeContext = buildExecutionContext(args);
|
|
804
820
|
// Return early errors if execution context failed.
|
|
805
821
|
if (!('schema' in exeContext)) {
|
|
822
|
+
for (const error of exeContext) {
|
|
823
|
+
// @ts-expect-error - We are intentionally modifying the errors
|
|
824
|
+
const extensions = (error.extensions ||= {});
|
|
825
|
+
const httpExtensions = (extensions['http'] ||= {});
|
|
826
|
+
httpExtensions.status = 400;
|
|
827
|
+
error.extensions['code'] = 'BAD_USER_INPUT';
|
|
828
|
+
}
|
|
806
829
|
return {
|
|
807
|
-
errors: exeContext
|
|
808
|
-
Object.defineProperty(e, 'extensions', {
|
|
809
|
-
value: {
|
|
810
|
-
...e.extensions,
|
|
811
|
-
http: {
|
|
812
|
-
...(e.extensions?.['http'] || {}),
|
|
813
|
-
status: 400,
|
|
814
|
-
},
|
|
815
|
-
},
|
|
816
|
-
});
|
|
817
|
-
return e;
|
|
818
|
-
}),
|
|
830
|
+
errors: exeContext,
|
|
819
831
|
};
|
|
820
832
|
}
|
|
821
833
|
const resultOrStream = createSourceEventStreamImpl(exeContext);
|
package/esm/execution/execute.js
CHANGED
|
@@ -150,7 +150,11 @@ export function buildExecutionContext(args) {
|
|
|
150
150
|
if (operationName == null) {
|
|
151
151
|
if (operation !== undefined) {
|
|
152
152
|
return [
|
|
153
|
-
createGraphQLError('Must provide operation name if query contains multiple operations.'
|
|
153
|
+
createGraphQLError('Must provide operation name if query contains multiple operations.', {
|
|
154
|
+
extensions: {
|
|
155
|
+
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
156
|
+
},
|
|
157
|
+
}),
|
|
154
158
|
];
|
|
155
159
|
}
|
|
156
160
|
operation = definition;
|
|
@@ -165,9 +169,21 @@ export function buildExecutionContext(args) {
|
|
|
165
169
|
}
|
|
166
170
|
if (operation == null) {
|
|
167
171
|
if (operationName != null) {
|
|
168
|
-
return [
|
|
172
|
+
return [
|
|
173
|
+
createGraphQLError(`Unknown operation named "${operationName}".`, {
|
|
174
|
+
extensions: {
|
|
175
|
+
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
178
|
+
];
|
|
169
179
|
}
|
|
170
|
-
return [
|
|
180
|
+
return [
|
|
181
|
+
createGraphQLError('Must provide an operation.', {
|
|
182
|
+
extensions: {
|
|
183
|
+
code: 'OPERATION_RESOLUTION_FAILURE',
|
|
184
|
+
},
|
|
185
|
+
}),
|
|
186
|
+
];
|
|
171
187
|
}
|
|
172
188
|
// FIXME: https://github.com/graphql/graphql-js/issues/2203
|
|
173
189
|
/* c8 ignore next */
|
|
@@ -789,19 +805,15 @@ export function subscribe(args) {
|
|
|
789
805
|
const exeContext = buildExecutionContext(args);
|
|
790
806
|
// Return early errors if execution context failed.
|
|
791
807
|
if (!('schema' in exeContext)) {
|
|
808
|
+
for (const error of exeContext) {
|
|
809
|
+
// @ts-expect-error - We are intentionally modifying the errors
|
|
810
|
+
const extensions = (error.extensions ||= {});
|
|
811
|
+
const httpExtensions = (extensions['http'] ||= {});
|
|
812
|
+
httpExtensions.status = 400;
|
|
813
|
+
error.extensions['code'] = 'BAD_USER_INPUT';
|
|
814
|
+
}
|
|
792
815
|
return {
|
|
793
|
-
errors: exeContext
|
|
794
|
-
Object.defineProperty(e, 'extensions', {
|
|
795
|
-
value: {
|
|
796
|
-
...e.extensions,
|
|
797
|
-
http: {
|
|
798
|
-
...(e.extensions?.['http'] || {}),
|
|
799
|
-
status: 400,
|
|
800
|
-
},
|
|
801
|
-
},
|
|
802
|
-
});
|
|
803
|
-
return e;
|
|
804
|
-
}),
|
|
816
|
+
errors: exeContext,
|
|
805
817
|
};
|
|
806
818
|
}
|
|
807
819
|
const resultOrStream = createSourceEventStreamImpl(exeContext);
|