Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: graphQLErrors in Error Link if networkError.result is an empty string #11329

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-hounds-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix graphQLErrors in Error Link if networkError.result is an empty string
34 changes: 34 additions & 0 deletions src/link/error/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,40 @@ describe("error handling", () => {
});
}
);
itAsync(
"sets graphQLErrors to undefined if networkError.result is an empty string",
(resolve, reject) => {
const query = gql`
query Foo {
foo {
bar
}
}
`;

let called: boolean;
const errorLink = onError(({ graphQLErrors }) => {
expect(graphQLErrors).toBeUndefined();
called = true;
});

const mockLink = new ApolloLink((operation) => {
return new Observable((obs) => {
const response = { status: 500, ok: false } as Response;
throwServerError(response, "", "app is crashing");
});
});

const link = errorLink.concat(mockLink);

execute(link, { query }).subscribe({
error: (e) => {
expect(called).toBe(true);
resolve();
},
});
}
);
itAsync("completes if no errors", (resolve, reject) => {
const query = gql`
{
Expand Down
7 changes: 4 additions & 3 deletions src/link/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ export function onError(errorHandler: ErrorHandler): ApolloLink {
networkError,
//Network errors can return GraphQL errors on for example a 403
graphQLErrors:
networkError &&
networkError.result &&
networkError.result.errors,
(networkError &&
networkError.result &&
networkError.result.errors) ||
void 0,
forward,
});
if (retriedResult) {
Expand Down
Loading