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

Why "no-unused-variables" and "no-unused-fragments" rules requires GraphQL Schema and Operations? #1172

Open
4 tasks
M1CK431 opened this issue Sep 26, 2022 · 10 comments

Comments

@M1CK431
Copy link

M1CK431 commented Sep 26, 2022

Issue workflow progress

Progress of the issue based on the Contributor Workflow

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

    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

I don't understand why no-unused-variables and no-unused-fragments rules requires GraphQL Schema and Operations?

To Reproduce
Steps to reproduce the behavior:

Simpy use that rules without providing GraphQL Schema or Operations.

Expected behavior

Abilty to use no-unused-variables and no-unused-fragments rules without defined GraphQL Schema and Operations.

Environment:

  • OS: N/A
  • @graphql-eslint/eslint-plugin: N/A
  • Node.js: N/A

Additional context

I'm working on a frontend webapp where the API schema is not easily reachable because of complexe authentication process. In addition, the API is under active development and the schema is often updated so I can't just download the schema one time and forget.

Still, I would like to ensure that no one left unused variables and/or fragments in .gql files. I don't understand why this plugin need to know the GraphQL Schema and Operations to check for unused variables and/or fragments in a single .gql file. Could you please explain?

@M1CK431
Copy link
Author

M1CK431 commented Oct 6, 2022

🆙

@M1CK431
Copy link
Author

M1CK431 commented Dec 14, 2022

🆙 (bis)

@FloEdelmann
Copy link
Contributor

A fragment could be used in another .graphql file, so at least for that rule, operations need to be provided.

@M1CK431
Copy link
Author

M1CK431 commented Dec 19, 2022

Hi @FloEdelmann and thanks for your reply.

Ok I understand for no-unused-fragments but what about no-unused-variables?

@dimaMachina
Copy link
Owner

no-unused-fragments

we need to see overall siblings whether it's used or not somewhere

no-unused-variables

same as above because fragments can contain variables

@M1CK431
Copy link
Author

M1CK431 commented Dec 19, 2022

Ok, so what about a rule dedicated to check unused variables/fragment in a single .gql file?

@dimaMachina
Copy link
Owner

what do you want to omit schema or siblings?

also, I guess requires schema for no-unused-fragments can be removed, but not for no-unused-variables, the test failed with context.getRecursiveVariableUsages is not a function error

@M1CK431
Copy link
Author

M1CK431 commented Dec 20, 2022

I'm in a use case where the schema is very difficult to fetch from the editor while working on the webapp because of complexe authentication process. In addition the schema is updated relatively often so downloading it as a file is not really an option. So my goal is to enforce the maximum number of rules without the schema.

We don't use fragment so often (despite we should probably), however we already discover unused variables in some of our .gql files that's why I'm interested to enforce that rule.

@dimaMachina dimaMachina reopened this Dec 20, 2022
@M1CK431
Copy link
Author

M1CK431 commented Jul 17, 2023

Hi @B2o5T , hope you are well :)
Any news regarding this issue?

@benquarmby
Copy link

benquarmby commented Jun 27, 2024

For additional context, my use case does have access to the operations (via parserOptions.operations) but not the schema, similar to the above. The schema is a moving target, and not deterministic enough for use at build-time. We are catching these issues right now at deploy-time (when the schema is known), but the ability to run static checks like no-unused-fragments without schema would allow us to catch them much earlier, right in the editor.

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

4 participants