-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 schema link to return errors for unknown queries #7094
Fix schema link to return errors for unknown queries #7094
Conversation
@@ -56,7 +54,9 @@ describe('SchemaLink', () => { | |||
}); | |||
observable.subscribe({ | |||
next, | |||
error: error => expect(false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(false)
doesn't fail the test. I've replaced this with throwing an error that would really fail the test now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing this and for going out of your way to improve it!
expect(false); | ||
done(); | ||
}, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this test didn't really assert for anything. The error handler was never called.
@@ -101,7 +104,9 @@ describe('SchemaLink', () => { | |||
}); | |||
observable.subscribe( | |||
next, | |||
error => expect(false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as mentioned above.
expect(result.errors![0].message).toMatch(/Cannot query field "unknown"/) | ||
done(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new test I've added that now passes.
Previously Apollo would return with an empty result object and loading status 7
– "ready". This can lead to unexpected states in apps that use the schema link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amannn Thanks for noticing this problem and fixing it, with tests!
@@ -56,7 +54,9 @@ describe('SchemaLink', () => { | |||
}); | |||
observable.subscribe({ | |||
next, | |||
error: error => expect(false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing this and for going out of your way to improve it!
Follow-up to #7094, to avoid enabling validation by default, since @apollo/[email protected] is not a major release.
@benjamn I understand, thanks for the hint! Do you have a use case in mind where this would be breaking? The previous behaviour was that an empty object was returned – regardless of what you query. In the apps where I noticed this behaviour, this broke the app, but in more subtle ways (runtime error in components) instead of warning that the query is invalid as soon as it is fired. |
Checklist:
If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changesPlease see the inline comments. I also fixed some tests that I think didn't quite do what they looked like.