Skip to content

requireAllFields option of require-selections demands nonexistent fields #2911

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

Open
3 of 4 tasks
tpict opened this issue May 8, 2025 · 0 comments · May be fixed by #2912
Open
3 of 4 tasks

requireAllFields option of require-selections demands nonexistent fields #2911

tpict opened this issue May 8, 2025 · 0 comments · May be fixed by #2912

Comments

@tpict
Copy link

tpict commented May 8, 2025

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox

    For example, you can start off by editing the
    'basic' example on Stackblitz.

    Please make sure the graphql-eslint version under package.json matches yours.

  • 2. A failing test has been provided

  • 3. A local solution has been provided

  • 4. A pull request is pending review


Describe the bug

When using the require-selections rule with the requireAllFields option, a selection on a type that has any of the fieldNames is demanded to include all of the fieldNames, whether or not they exist on that type.

To Reproduce Steps to reproduce the behavior:

I've included a unit test in my PR #2912 that reproduces the error: dfdda86

The issue occurs when requireAllFields is set true and a given type implements only some of the specified fieldNames. e.g. given a schema

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

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

a rule config

{ requireAllFields: true, fieldName: ['id', 'title', 'content'] }

and a document

        {
          user {
            id
            posts {
              id
              title
              content
            }
          }
        }

the rule will report that you must select the user.title and user.content fields, even though they don't exist.

Expected behavior

The lint rule should not fail selection sets based on the absence of fields that cannot be selected in that context.

Environment:

  • OS: macOS
  • @graphql-eslint/eslint-plugin: 4.4.0
  • Node.js: 22.7.0
@tpict tpict linked a pull request May 8, 2025 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant