Skip to content

Commit 573620b

Browse files
committed
zap mergeErrors
1 parent ed16b51 commit 573620b

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/execution/execute.js

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,6 @@ function executeImpl(
234234
return buildResponse(context, result);
235235
}
236236

237-
/**
238-
* Utility function to merge context's errors so far the errors in an
239-
* ExecutionPartialResult, zero the context's errors, and return the new
240-
* ExecutionPartialResult.
241-
*/
242-
function mergeErrors(
243-
context: ExecutionContext,
244-
result: ExecutionPartialResultNP<mixed>,
245-
): ExecutionPartialResultNP<mixed> {
246-
const errors = context.errors;
247-
context.errors = [];
248-
return { data: result.data, errors: [...errors, ...(result.errors || [])] };
249-
}
250-
251237
/**
252238
* Given a completed execution context and data, build the { errors, data }
253239
* response defined by the "Response" section of the GraphQL specification.
@@ -258,9 +244,7 @@ function buildResponse(
258244
) {
259245
const promise = getPromise(result);
260246
if (promise) {
261-
return promise.then(resolved =>
262-
buildResponse(context, mergeErrors(context, resolved)),
263-
);
247+
return promise.then(resolved => buildResponse(context, resolved));
264248
}
265249
if (result.data && (!result.errors || !result.errors.length)) {
266250
return { data: result.data };
@@ -435,13 +419,14 @@ function executeOperation(
435419
: executeFields(exeContext, type, rootValue, path, fields);
436420
const promise = getPromise(result);
437421
if (promise) {
438-
return promise.then(undefined, error =>
439-
mergeErrors(exeContext, { data: null, errors: [error] }),
440-
);
422+
return promise.then(undefined, error => ({
423+
data: null,
424+
errors: [error],
425+
}));
441426
}
442-
return mergeErrors(exeContext, result);
427+
return result;
443428
} catch (error) {
444-
return mergeErrors(exeContext, { data: null, errors: [error] });
429+
return { data: null, errors: [error] };
445430
}
446431
}
447432

@@ -582,7 +567,7 @@ function mergeEPRs(
582567
(merged, value, i) => {
583568
merged.data[keys[i]] = value.data;
584569
if (value.errors && value.errors.length) {
585-
merged.errors.push.apply(merged.errors, value.errors);
570+
merged.errors.push(...value.errors);
586571
}
587572
return merged;
588573
},
@@ -1125,7 +1110,7 @@ function flattenEPRs(
11251110
forEach((eprs: any), item => {
11261111
data.push(item.data);
11271112
if (item.errors && item.errors.length) {
1128-
errors.push.apply(errors, item.errors);
1113+
errors.push(...item.errors);
11291114
}
11301115
});
11311116
return { data, errors };

0 commit comments

Comments
 (0)