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

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

Open
taylorgoolsby opened this issue Aug 26, 2020 · 0 comments

Comments

@taylorgoolsby
Copy link

taylorgoolsby commented Aug 26, 2020

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.

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

1 participant