Skip to content
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

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

Open
xperiandri opened this issue Feb 15, 2024 · 3 comments

Comments

@xperiandri
Copy link

xperiandri commented Feb 15, 2024

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]
}
  1. Not tullable items
type Stall {
  availableProduce: [Produce!]
}

In context of fixing fsprojects/FSharp.Data.GraphQL#455 in fsprojects/FSharp.Data.GraphQL#458

@benjie
Copy link
Member

benjie commented Feb 15, 2024

Is it the correct behavior?

Yes. The relevant flow is:

@JoviDeCroock
Copy link
Member

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
Copy link
Member

benjie commented Feb 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants