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 schema link to return errors for unknown queries #7094

Merged
merged 1 commit into from
Oct 1, 2020
Merged

Fix schema link to return errors for unknown queries #7094

merged 1 commit into from
Oct 1, 2020

Conversation

amannn
Copy link
Contributor

@amannn amannn commented Sep 29, 2020

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes
  • Make sure all of the significant new logic is covered by tests

Please see the inline comments. I also fixed some tests that I think didn't quite do what they looked like.

@@ -56,7 +54,9 @@ describe('SchemaLink', () => {
});
observable.subscribe({
next,
error: error => expect(false),
Copy link
Contributor Author

@amannn amannn Sep 29, 2020

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.

Copy link
Member

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();
},
);
Copy link
Contributor Author

@amannn amannn Sep 29, 2020

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),
Copy link
Contributor Author

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();
});
});
Copy link
Contributor Author

@amannn amannn Sep 29, 2020

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.

Copy link
Member

@benjamn benjamn left a 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),
Copy link
Member

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!

src/link/schema/index.ts Show resolved Hide resolved
@benjamn benjamn changed the base branch from main to release-3.3 October 1, 2020 18:32
@benjamn benjamn merged commit 78198f8 into apollographql:release-3.3 Oct 1, 2020
benjamn added a commit that referenced this pull request Oct 1, 2020
benjamn added a commit that referenced this pull request Nov 24, 2020
Follow-up to #7094, to avoid enabling validation by default, since
@apollo/[email protected] is not a major release.
@benjamn
Copy link
Member

benjamn commented Nov 24, 2020

@amannn (+ anyone else who comes across this PR) I got a bit nervous about this being a breaking change for a minor release (AC3.3), so I made the validation opt-in in e27be1e.

@amannn
Copy link
Contributor Author

amannn commented Nov 24, 2020

@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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants