Skip to content

Commit

Permalink
fix: support errors with extensions set undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jan 3, 2024
1 parent d94dd1a commit 3ef877a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/metal-days-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-yoga': patch
---

Support errors with extensions set undefined
37 changes: 37 additions & 0 deletions packages/graphql-yoga/__tests__/error-masking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,41 @@ describe('error masking', () => {
],
});
});

it('support errors with undefined extensions', async () => {
const yoga = createYoga({
logging: false,
context: () => {
const error = createGraphQLError('I like turtles');
Object.defineProperty(error, 'extensions', {
get() {
return undefined;
},
});
throw error;
},
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
a: String!
}
`,
}),
});

const response = await yoga.fetch('http://yoga/graphql', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({ query: '{ __typename }' }),
});
expect(await response.json()).toMatchObject({
errors: [
{
message: 'I like turtles',
},
],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function processRegularResult(
!Array.isArray(executionResult) &&
areGraphQLErrors(executionResult.errors) &&
executionResult.errors.some(
err => !err.extensions.originalError || isGraphQLError(err.extensions.originalError),
err => !err.extensions?.originalError || isGraphQLError(err.extensions.originalError),
),
);

Expand Down

0 comments on commit 3ef877a

Please sign in to comment.