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

Inconsistent polymorphic results based on the input order #2307

Open
achintha-weerasinghe opened this issue Jan 9, 2025 · 1 comment
Open
Labels

Comments

@achintha-weerasinghe
Copy link

Summary

I have an union type union Animal = Cat | Dog and a root field called animals(input: [AnimalIdsAndTypesInput!]!): [Animal]!. AnimalIdsAndTypesInput contains two fields called id and type. type can be either CAT or DOG. This field should return the cats and dogs in the same order as the input ids and types. However, depending on the order of the input array, it produces nulls for some extended fields in Cat.

Steps to reproduce

  1. Use the reproduction branch: ouch-my-finger
  2. Run the schema.sql file against the database to create the cat and dog tables and insert some dummy data.
  3. Start postgraphile.
  4. Execute the following Query 1 and Query 2.

Query 1

query MyQuery {
  animals(input: [
    {id: "2", type: "CAT"},
    {id: "1", type: "DOG"}
  ]) {
    ... on Dog {
      id
      name
      ownerName
    }
    ... on Cat {
      id
      name
      enemies
    }
  }
}

Query 2

query MyQuery {
  animals(input: [
    {id: "1", type: "DOG"},
    {id: "2", type: "CAT"}
  ]) {
    ... on Dog {
      id
      name
      ownerName
    }
    ... on Cat {
      id
      name
      enemies
    }
  }
}
  1. In the above two queries, the only difference is the order of the two input objects.

Expected results

enemies of the Cat type should receive the expected JSON value.

Actual results

enemies of the Cat type receives null.

Additional context

I know the enemies field here can use a plan instead of custom sql execution. However, in my case it's more complex than this reproduction. Also, instead of loadMany I have tried withPgClient which returns no results, but an array of nulls.

When I said order of the fields, specifically this happens, when you put the extended type (in this case, it's the Cat type) later in the array of input objects.

@benjie
Copy link
Member

benjie commented Jan 9, 2025

I'm not going to investigate this because #2301 will involve rewriting a lot of how polymorphism works and this issue will likely no longer exist afterwards. If you would like it fixed in the mean time, you will need to investigate it and implement a fix yourself - sorry!

@benjie benjie moved this from 🌳 Triage to 🦔 Hedgehog in V5.0.0 Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🦔 Hedgehog
Development

No branches or pull requests

2 participants