-
Notifications
You must be signed in to change notification settings - Fork 2
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
Field Selection Merging demonstration of problem #19
base: main
Are you sure you want to change the base?
Field Selection Merging demonstration of problem #19
Conversation
It turns out this is a bit tricky. In the test case, I think the type we want is:
I put together a branch to take a stab at achieving this, but it has some issues--it serializes a few things differently, but also worse. In particular, I think a query like this: query {
hero {
... on Droid {
id
properties {
x
y
}
}
}
} should result in
but it doesn't. I think this all stems from one issue: the rules of omittability are implicit for JSON (and therefore not carefully specified), but not so for Argo. The algorithms in the GraphQL spec also aren't easy to alter to collect this information. Tight rules around omittability are helpful for the client experience, so probably some client code generators have run into this issue. I'll think more about it, but I'm also open to any ideas you might have! |
The logic I followed in the Erlang implementation was to add two new functions used by
When creating the (1)
|
One additional thing to consider is this point from section 2.b.ii. part of
The current Argo Typer doesn't account for arguments at all, but perhaps the "canonical name" should be kept as part of the Wire Type information in order to account for this as described in this PR. The "canonical name" here would collapse selected fields like Perhaps something like this? type Field = {
name: string
of: Wire.Type
omittable: boolean
source: string?
} |
I think the missing piece is to check for an "exact" selection--anywhere a fragment's type condition exactly matches the field's type. When it's exact, don't mark it omittable (unless a directive demands it).
Yes, I think you're right.
Thank you, all of this was very helpful! I updated this branch, and it behaves as expected: https://github.com/msolomon/argo/blob/overlapping-fields
Fortunately, I think here (similar to elsewhere, including the reference implementation of lots of the field merging logic) we can rely on GraphQL validating this for us before we ever get to Argo. The query will fail validation if these will later not be mergable. |
This was my first thought, too. I tried this with the query in this PR by adding a new value for However, I was running into the problem where fields underneath Does your branch handle this correctly? If so, I'll revisit what I did to see if I can find where my mistake is. |
I think it works correctly, at least, this test passes: https://github.com/msolomon/argo/blob/overlapping-fields/argo-js/test/wire.test.ts#L190-L191 It's possible further nesting would be a problem, I didn't write a test for it. |
See GraphQL Spec: 5.3.2 Field Selection Merging.
The attached test case currently fails:
Here is the JSON dump of the wire type:
I think the expected wire type should look like this: