Skip to content

require-selections does not check all possible types of union types #2963

Open

Description

@noahm

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

This feels related to #2318, only with inline fragments. On a union type where at least one selected type selects an available id, all other selected types are not all checked.

To Reproduce Steps to reproduce the behavior:
npm run lint in this stackblitz summarized below:

type User {
  id: ID
  name: String
}

type Post {
  id: ID
  title: String
}

union UserOrPost = User | Post

type Query {
  user: User
  userOrPost: UserOrPost
}

query {
  userOrPost {
    ... on User { id }
    # no error reported, though inline fragment does not select `id` from Post
    ... on Post { title }
  }
}

Expected behavior

All available id fields are required to be selected from all types of a union that make one available

Environment:

  • OS: Linux
  • @graphql-eslint/eslint-plugin: 4.4.0
  • Node.js: 22.22.3

Additional context

This is an edge case that we found at Twitch some years back and I added support for it to our custom gql validation tooling. I'd like to migrate off that custom stack to this eslint plugin, but this is a gap in coverage that we need to fix first. I'll be following this up with a PR shortly.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址