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: error when server throws and we are also querying for a local field #10362

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/small-lemons-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix error when server returns an error and we are also querying for a local field
41 changes: 41 additions & 0 deletions src/__tests__/local-state/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1196,4 +1196,45 @@ describe('Combining client and server state/operations', () => {
},
});
});

itAsync('should handle server errors when field is required', (resolve, reject) => {
alessbell marked this conversation as resolved.
Show resolved Hide resolved
const query = gql`
query GetUser {
user {
firstName @client
lastName
}
}
`;

const cache = new InMemoryCache();
const link = new ApolloLink(operation => {
expect(operation.operationName).toBe('GetUser');
alessbell marked this conversation as resolved.
Show resolved Hide resolved
return Observable.of({
data: null,
errors: [new GraphQLError("something went wrong", {
extensions: {
code: "INTERNAL_SERVER_ERROR"
},
path: ["user"]
})]
});
});

const client = new ApolloClient({
cache,
link,
resolvers: {},
});

client.watchQuery({ query }).subscribe({
error(error) {
expect(error.message).toEqual("something went wrong");
resolve();
},
next() {
reject();
},
});
});
});
4 changes: 4 additions & 0 deletions src/core/LocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ export class LocalState<TCacheShape> {
rootValue: any,
execContext: ExecContext,
): Promise<any> {
if (!rootValue) {
return null;
}

const { variables } = execContext;
const fieldName = field.name.value;
const aliasedFieldName = resultKeyNameFromField(field);
Expand Down