-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
handleNull.ts
29 lines (23 loc) · 857 Bytes
/
handleNull.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { GraphQLError } from 'graphql';
import AggregateError from '@ardatan/aggregate-error';
import { relocatedError, unextendedError } from '@graphql-tools/utils';
export function handleNull(errors: ReadonlyArray<GraphQLError>) {
if (errors.length) {
const graphQLToolsMergedPath = errors[0].extensions.graphQLToolsMergedPath;
const unannotatedErrors = errors.map(error => unextendedError(error, 'graphQLToolsMergedPath'));
if (unannotatedErrors.length > 1) {
const combinedError = new AggregateError(unannotatedErrors);
return new GraphQLError(
combinedError.message,
undefined,
undefined,
undefined,
graphQLToolsMergedPath,
combinedError
);
}
const error = unannotatedErrors[0];
return relocatedError(error, graphQLToolsMergedPath);
}
return null;
}