eslint-plugin-graphql icon indicating copy to clipboard operation
eslint-plugin-graphql copied to clipboard

[FEAT] Enforce all conditional fragments of a Union type to be handled.

Open taylorgoolsby opened this issue 5 years ago • 0 comments
trafficstars

Consider this union type union SearchResult = Human | Droid | Starship.

And this query:

{
  search(text: "an") {
    __typename
    ... on Human {
      id
      name
      height
    }
    ... on Droid {
      id
      name
      primaryFunction
    }
    ... on Starship {
      id
      name
      length
    }
  }
}

This query handles all possible conditional fragments of a SearchResult.

Now, consider the following query:

{
  search(text: "an") {
    __typename
    ... on Human {
      id
      name
      height
    }
    ... on Droid {
      id
      name
      primaryFunction
    }
  }
}

This query is missing the conditional fragment for the Starship type.

If you try to run this query using Apollo, you can sometimes run into this error: Store error: the application attempted to write an object with no provided id but the store already contains an id of <Starship_id_here> for this object. The selectionSet that was trying to be written is:

This error is silent in Apollo, so it's hard to tell when it happens and some digging needs to happen.

Instead, it would be nice if eslint-plugin-graphql enforced all conditional fragments of a Union type to be handled.

taylorgoolsby avatar Aug 26 '20 20:08 taylorgoolsby