graphql / graphql-spec

GraphQL is a query language and execution engine tied to any backend service.
https://spec.graphql.org
14.29k stars 1.12k forks source link

What must be the result of executing only one fragment on a list of union or interface type? #1080

Open xperiandri opened 7 months ago

xperiandri commented 7 months ago

Having types Fruit and Vegetable implementing Produce as per https://graphql.com/learn/interfaces-and-unions/#fragments After I executed such query (use no shared fields, and only a sible type fragment while the collecton has multiple types)

query GetMostPopularStallProduce {
  mostPopularStall {
    availableProduce {
      ...  on Fruit {
        hasEdibleSeeds
      }
    }
  }
}

I've got

{
  "data": {
    "mostPopularStall": {
      "availableProduce": [
        {
          "hasEdibleSeeds": false
        },
        {
          "hasEdibleSeeds": true
        },
        {
          "hasEdibleSeeds": false
        },
        {},
        {}
      ]
    }
  }
}

Is it the correct behavior?

Specification does not mention such case at all.

I want to understand both cases like:

  1. Nullable items
    type Stall {
    availableProduce: [Produce]
    }
  2. Not tullable items
    type Stall {
    availableProduce: [Produce!]
    }

In context of fixing https://github.com/fsprojects/FSharp.Data.GraphQL/issues/455 in https://github.com/fsprojects/FSharp.Data.GraphQL/pull/458

benjie commented 7 months ago

Is it the correct behavior?

Yes. The relevant flow is:

JoviDeCroock commented 7 months ago

I guess currently it's a bit implicit in the sense that we say Initialize resultMap to an empty ordered map. and then we see that the fragment does not apply so it stays an empty ordered map. I think there might be an opportunity to clarify something along the lines of If a returned object has no matching fragments the result will be an empty ordered map..

benjie commented 7 months ago

I think adding an example that demonstrates this might be helpful; the algorithm itself seems unambiguous.