-
Notifications
You must be signed in to change notification settings - Fork 54
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: expand all possible abstract ids #81
Conversation
@gmac This is excellent. Thanks a lot for this. I'm happy to write unit tests for this if you'd prefer. Should be a simple case of adding the Apple/Banana example to |
08f0daf
to
32af2d2
Compare
Thanks @nmaquet & @lucianjon, tests have been added. Bramble is teaching me Go, and I'm really enjoying it! This PR is good to go on my end! |
31f2da4
to
f0483da
Compare
Codecov Report
@@ Coverage Diff @@
## main #81 +/- ##
==========================================
+ Coverage 66.78% 67.05% +0.26%
==========================================
Files 24 24
Lines 2728 2747 +19
==========================================
+ Hits 1822 1842 +20
+ Misses 750 749 -1
Partials 156 156
Continue to review full report at Codecov.
|
Fix: spurious test failures caused by #81
This fixes a bug with the notoriously tricky hint selections of abstract types.
The problem
Here's a schema...
Then here's a query:
This query works fine if the endpoint returns an
Apple
, but it fails if aBanana
is returned:Why does a
Banana
fail? It's because ID hint selections are only being added to user-defined boundary fragments, i.e:Apple
. In the above selection, the user hasn't explicitly made aBanana
selection, so there's no ID hint added for a banana. That means that when aBanana
gets is returned, the executor comes up with a boundary type that returned no ID.The fix
This updates the query planner to expand abstract types with ID selection hints for all possible boundary types. The above request now comes out looking like this:
Now, regardless of what the user has selected, we know that all possible boundary results will come back with the expected ID. GraphQL Tools stitching does something very similar. It's generally better to normalize the request than to make complicated assumptions about the result.
Gross, there's now two
...on Apple
fragments, can we consolidate those? Sure, we could using something like selectionSetHasFieldNamed for fragments. However, I'm generally against adding loops for the sake of human cosmetics when GraphQL servers don't care if fragments or fields get duplicated in the selection. But if there's strong resistance to this, I'm happy to prettify it.Tests
Opening this now for initial review on the implementation... I'm still learning Go, so I'm a bit slow to write code and still have to figure out how to write/run tests.