dimaMachina / graphql-eslint

ESLint parser, plugin and set rules for GraphQL (for schema and operations). Easily customizable with custom rules. Integrates with IDEs and modern GraphQL tools.
https://the-guild.dev/graphql/eslint
MIT License
779 stars 102 forks source link

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

Open M1CK431 opened 1 year ago

M1CK431 commented 1 year ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


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:

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 commented 1 year ago

:up:

M1CK431 commented 1 year ago

🆙 (bis)

FloEdelmann commented 1 year ago

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

M1CK431 commented 1 year ago

Hi @FloEdelmann and thanks for your reply.

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

dimaMachina commented 1 year ago

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 commented 1 year ago

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

dimaMachina commented 1 year ago

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 commented 1 year ago

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.

M1CK431 commented 11 months ago

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

benquarmby commented 1 week ago

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.