Skip to content

Commit d68d506

Browse files
committed
zap mergeErrors
1 parent 023e9d8 commit d68d506

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
@@ -239,20 +239,6 @@ function executeImpl(
239239
return buildResponse(context, result);
240240
}
241241

242-
/**
243-
* Utility function to merge context's errors so far the errors in an
244-
* ExecutionPartialResult, zero the context's errors, and return the new
245-
* ExecutionPartialResult.
246-
*/
247-
function mergeErrors(
248-
context: ExecutionContext,
249-
result: ExecutionPartialResultNP<mixed>,
250-
): ExecutionPartialResultNP<mixed> {
251-
const errors = context.errors;
252-
context.errors = [];
253-
return { data: result.data, errors: [...errors, ...(result.errors || [])] };
254-
}
255-
256242
/**
257243
* Given a completed execution context and data, build the { errors, data }
258244
* response defined by the "Response" section of the GraphQL specification.
@@ -263,9 +249,7 @@ function buildResponse(
263249
) {
264250
const promise = getPromise(result);
265251
if (promise) {
266-
return promise.then(resolved =>
267-
buildResponse(context, mergeErrors(context, resolved)),
268-
);
252+
return promise.then(resolved => buildResponse(context, resolved));
269253
}
270254
if (result.data && (!result.errors || !result.errors.length)) {
271255
return { data: result.data };
@@ -440,13 +424,14 @@ function executeOperation(
440424
: executeFields(exeContext, type, rootValue, path, fields);
441425
const promise = getPromise(result);
442426
if (promise) {
443-
return promise.then(undefined, error =>
444-
mergeErrors(exeContext, { data: null, errors: [error] }),
445-
);
427+
return promise.then(undefined, error => ({
428+
data: null,
429+
errors: [error],
430+
}));
446431
}
447-
return mergeErrors(exeContext, result);
432+
return result;
448433
} catch (error) {
449-
return mergeErrors(exeContext, { data: null, errors: [error] });
434+
return { data: null, errors: [error] };
450435
}
451436
}
452437

@@ -587,7 +572,7 @@ function mergeEPRs(
587572
(merged, value, i) => {
588573
merged.data[keys[i]] = value.data;
589574
if (value.errors && value.errors.length) {
590-
merged.errors.push.apply(merged.errors, value.errors);
575+
merged.errors.push(...value.errors);
591576
}
592577
return merged;
593578
},
@@ -1130,7 +1115,7 @@ function flattenEPRs(
11301115
forEach((eprs: any), item => {
11311116
data.push(item.data);
11321117
if (item.errors && item.errors.length) {
1133-
errors.push.apply(errors, item.errors);
1118+
errors.push(...item.errors);
11341119
}
11351120
});
11361121
return { data, errors };

0 commit comments

Comments
 (0)