Skip to content

Commit 6fcd4c6

Browse files
committed
never serialize coordinate
1 parent 2b67fa6 commit 6fcd4c6

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

packages/utils/src/errors.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ declare module 'graphql' {
2222
*/
2323
readonly coordinate?: string;
2424
}
25-
26-
interface GraphQLFormattedError {
27-
/**
28-
* An optional schema coordinate (e.g. "MyType.myField") associated with this error.
29-
*/
30-
readonly coordinate?: string;
31-
}
3225
}
3326

3427
const possibleGraphQLErrorProperties = [
@@ -53,13 +46,6 @@ export function isGraphQLErrorLike(error: any) {
5346
);
5447
}
5548

56-
export const toJSON: GraphQLError['toJSON'] = function toJSON(this: GraphQLError) {
57-
const formattedError = GraphQLError.prototype.toJSON.apply(this);
58-
// @ts-expect-error coordinate is readonly
59-
formattedError.coordinate = this.coordinate;
60-
return formattedError;
61-
};
62-
6349
export function createGraphQLError(message: string, options?: GraphQLErrorOptions): GraphQLError {
6450
if (
6551
options?.originalError &&
@@ -90,7 +76,6 @@ export function createGraphQLError(message: string, options?: GraphQLErrorOption
9076
if (options?.coordinate && error.coordinate == null) {
9177
Object.defineProperties(error, {
9278
coordinate: { value: options.coordinate, enumerable: true, configurable: true },
93-
toJSON: { value: toJSON },
9479
});
9580
}
9681

@@ -116,7 +101,6 @@ export function locatedError(
116101
const coordinate = `${info.parentType.name}.${info.fieldName}`;
117102
Object.defineProperties(error, {
118103
coordinate: { value: coordinate, enumerable: true, configurable: true },
119-
toJSON: { value: toJSON },
120104
});
121105
}
122106

packages/utils/tests/errors.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ describe('Errors', () => {
8383
});
8484
});
8585

86-
testIf(versionInfo.major >= 16)('should have coordinate in JSON representation', () => {
86+
it('should not have coordinate in JSON representation', () => {
87+
// Since this an experiment, we don't want coordinate to leak to the client
8788
const error = createGraphQLError('message', {
8889
coordinate: 'Query.test',
8990
});
90-
expect(JSON.stringify(error)).toBe('{"message":"message","coordinate":"Query.test"}');
91+
expect(JSON.stringify(error)).toBe('{"message":"message"}');
9192
});
9293
});
9394
});

0 commit comments

Comments
 (0)