Skip to content

Commit c3d938a

Browse files
committed
Make serialized error spec compliant
Summary: An update recently in `facebook/graphql/spec/Section 7 -- Response.md` specify that GraphQL services may provide an additional entry to errors with key `extensions`. Although non-specified entries are not violations, they are still discouraged. This update try to follow through with the spec recommendation.
1 parent b7e8814 commit c3d938a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export interface ErrorConfig {
1616

1717
export interface ErrorInfo {
1818
message: string;
19-
name: string;
20-
time_thrown: string;
21-
data?: object;
2219
path?: string;
2320
locations?: any;
21+
extensions?: {
22+
name: string;
23+
time_thrown: string;
24+
data?: object;
25+
};
2426
}
2527

2628
export class ApolloError extends ExtendableError {
@@ -56,11 +58,13 @@ export class ApolloError extends ExtendableError {
5658

5759
let error: ErrorInfo = {
5860
message,
59-
name,
60-
time_thrown,
61-
data,
6261
path,
63-
locations
62+
locations,
63+
extensions: {
64+
name,
65+
time_thrown,
66+
data
67+
}
6468
};
6569

6670
if (_showLocations) {

test/spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('createError', () => {
3131
},
3232
});
3333

34-
const { message, name, time_thrown, data } = e.serialize();
34+
const { message, extensions: { name, time_thrown, data } } = e.serialize();
3535
expect(message).to.equal('A foo 2.0 error has occurred');
3636
expect(name).to.equal('FooError');
3737
expect(time_thrown).to.equal(e.time_thrown);

0 commit comments

Comments
 (0)