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 broken state with errors null #1208

Merged
merged 6 commits into from
Jan 22, 2017
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Expect active development and potentially significant breaking changes in the `0
- Fix bug where there could be store inconsistencies for two dependent optimistic updates [PR #1144](https://github.com/apollostack/apollo-client/pull/1144)
- Allow optional mutation arguments. [PR #1174](https://github.com/apollostack/apollo-client/pull/1174)
- Fix typings error with `strictNullChecks` [PR #1188](https://github.com/apollostack/apollo-client/pull/1188)
- Gracefully handle `null` GraphQL errors. [PR #1208](https://github.com/apollostack/apollo-client/pull/1208)
- Allow optional mutation arguments. [PR #1174](https://github.com/apollostack/apollo-client/pull/1174)

### 0.7.3
Expand Down
3 changes: 2 additions & 1 deletion src/errors/ApolloError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { GraphQLError } from 'graphql';
// If we have GraphQL errors present, add that to the error message.
if (Array.isArray(err.graphQLErrors) && err.graphQLErrors.length !== 0) {
err.graphQLErrors.forEach((graphQLError: GraphQLError) => {
message += 'GraphQL error: ' + graphQLError.message + '\n';
const errorMessage = graphQLError ? graphQLError.message : 'Error message not found.';
message += `GraphQL error: ${errorMessage}\n`;
});
}

Expand Down
30 changes: 30 additions & 0 deletions test/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,36 @@ describe('QueryManager', () => {
});
});

// Easy to get into this state if you write an incorrect `formatError`
// function with graphql-server or express-graphql
it('error array with nulls (handle non-spec-compliant server) #1185', (done) => {
assertWithObserver({
done,
query: gql`
query people {
allPeople(first: 1) {
people {
name
}
}
}`,
result: {
errors: [null],
},
observer: {
next() {
done(new Error('Should not fire next for an error'));
},
error(error) {
assert.deepEqual((error as any).graphQLErrors, [null]);
assert.equal(error.message, 'GraphQL error: Error message not found.');
done();
},
},
});
});


it('handles network errors', (done) => {
assertWithObserver({
done,
Expand Down