graphql-go-tools icon indicating copy to clipboard operation
graphql-go-tools copied to clipboard

Required field skipped in output when using inline fragments

Open dnerdy opened this issue 3 years ago • 2 comments

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"
  }
}

dnerdy avatar Feb 04 '22 01:02 dnerdy

Can you create one ore more failing tests to cover the "right" behaviour? (or even provide a solution)

jensneuse avatar Feb 04 '22 08:02 jensneuse

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?

dnerdy avatar Feb 04 '22 19:02 dnerdy