graphql / graphql-spec

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

Unclear spec for array with fragments #1079

Closed njlr closed 9 months ago

njlr commented 9 months ago

In this page, there is an interactive example for playing with fragments.

availableProduce returns an array of Produce, which is an interface. Using fragments, we can match on only Fruit items.

Here is the query:

{
  mostPopularStall {
    availableProduce {
      ... on Fruit {
        name
        hasEdibleSeeds
      }
    }
  }
}

Then the response is:

{
  "data": {
    "mostPopularStall": {
      "availableProduce": [
        {
          "name": "pear",
          "hasEdibleSeeds": false
        },
        {
          "name": "blueberry",
          "hasEdibleSeeds": true
        },
        {
          "name": "banana",
          "hasEdibleSeeds": false
        },
        {},
        {}
      ]
    }
  }
}

Notice how the non-matching items (type Vegetable) have been returned as empty objects {}.

This behavior makes sense, however I was unable to find this documented in the spec.

What is the correct behavior here?

Sorry in advance if I have simply missed the relevant section!

Related PR: https://github.com/fsprojects/FSharp.Data.GraphQL/pull/458

njlr commented 9 months ago

Dupe of https://github.com/graphql/graphql-spec/issues/1080