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

require-selections does not report issues on FragmentSpreads within GraphQLUnionType #2318

Open
4 tasks done
maciesielka opened this issue May 15, 2024 · 0 comments · May be fixed by #2319
Open
4 tasks done

require-selections does not report issues on FragmentSpreads within GraphQLUnionType #2318

maciesielka opened this issue May 15, 2024 · 0 comments · May be fixed by #2319

Comments

@maciesielka
Copy link

maciesielka commented May 15, 2024

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox
  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

require-selections handles only InlineFragment spreads with GraphQLUnionTypes, despite named FragmentSpreads being valid GraphQL that should receive the same treatment.

} else if (rawType instanceof GraphQLUnionType) {
for (const selection of node.selections) {
if (selection.kind === Kind.INLINE_FRAGMENT) {
const types = rawType.getTypes();
const t = types.find(t => t.name === selection.typeCondition!.name.value);
if (t) {
checkFields(t);
}
}
}
}

To Reproduce

Steps to reproduce the behavior:

The failing test in the linked PR provides the best example for the bug (see commit that adds that test), but a simplified schema is reproduced below:

type User {
  id: ID
  name: String
  posts: [Post]
}

type Post {
  id: ID
  title: String
  author: [User!]!
}

type Query {
  user: User
  userOrPost: UserOrPost
}

union UserOrPost = User | Post

fragment UnionFragment on UserOrPost {
  ...UserFields
}

fragment UserFields on User {
  name
}

query {
  userOrPost {
    # no error is reported here, even though `...UnionFragment` does not select `id`
    ...UnionFragment
  }
}

Expected behavior

An error should be reported for FragmentSpread just like it is for InlineFragments within GraphQLUnionTypes.

Environment:

  • @graphql-eslint/eslint-plugin: 4.0.0
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

Successfully merging a pull request may close this issue.

1 participant