graphql-go-tools
graphql-go-tools copied to clipboard
Required field skipped in output when using inline fragments
Consider a query like the following:
{
user {
id
... on RegisteredUser {
name
}
}
If "id" is required when "name" is selected (due to federation or other reasons), the requiredFieldsVisitor will add "id" to the ... on RegisteredUser
selection set and then mark the field to be skipped in the output. The problem is "id" was actually selected outside the fragment and shouldn't be skipped!
The problematic logic is here: https://github.com/jensneuse/graphql-go-tools/blob/master/pkg/engine/plan/plan.go#L1599-L1626.
Currently, the output for this query looks like:
{
"user": {
"name": "some name"
}
}
Can you create one ore more failing tests to cover the "right" behaviour? (or even provide a solution)
Can you create one ore more failing tests to cover the "right" behaviour? (or even provide a solution)
Yes, I can put together a some tests. I can also work on a solution.
The fix would currently be very complicated, I think. The operation normalization proposed in https://github.com/jensneuse/graphql-go-tools/issues/328#issuecomment-1030296919 would make the fix much simpler. Could you let me know if the normalization approach discussed in that comment sounds reasonable to you?