Skip to content

Commit 6cec35f

Browse files
committed
also override toJSON in locatedError
1 parent c5bd447 commit 6cec35f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

packages/utils/src/errors.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,10 @@ export function createGraphQLError(message: string, options?: GraphQLErrorOption
8888
);
8989

9090
if (options?.coordinate && error.coordinate == null) {
91-
Object.defineProperty(error, 'coordinate', {
92-
value: options.coordinate,
93-
enumerable: true,
94-
configurable: true,
91+
Object.defineProperties(error, {
92+
coordinate: { value: options.coordinate, enumerable: true, configurable: true },
93+
toJSON: { value: toJSON },
9594
});
96-
error.toJSON = toJSON;
9795
}
9896

9997
return error;
@@ -115,10 +113,10 @@ export function locatedError(
115113

116114
// `graphql` locatedError is only changing path and nodes if it is not already defined
117115
if (!error.coordinate && info && error.coordinate == null) {
118-
Object.defineProperty(error, 'coordinate', {
119-
value: `${info.parentType.name}.${info.fieldName}`,
120-
enumerable: true,
121-
configurable: true,
116+
const coordinate = `${info.parentType.name}.${info.fieldName}`;
117+
Object.defineProperties(error, {
118+
coordinate: { value: coordinate, enumerable: true, configurable: true },
119+
toJSON: { value: toJSON },
122120
});
123121
}
124122

0 commit comments

Comments
 (0)