Skip to content

Inconsistent polymorphic results based on the input order #2307

Open
@achintha-weerasinghe

Description

@achintha-weerasinghe

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      🦔 Hedgehog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions