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
789 stars 104 forks source link

Feedback for “no-unused-fields” #2138

Closed mashaLutskevich2002 closed 7 months ago

mashaLutskevich2002 commented 7 months ago

my eslint (in the overrides)

{
            "files": ["**/*.graphql"],
            "parser": "@graphql-eslint/eslint-plugin",
            "parserOptions": {
                "schema": "./schema.graphql",
                "operations": "./**/*.graphql"
            },
            "plugins": ["@graphql-eslint"],
            "rules": {
                "spaced-comment": "off",
                "@graphql-eslint/no-duplicate-fields": "error",
                "@graphql-eslint/no-unused-fields": "error",
                "prettier/prettier": "off"
            }
        }

I have a query

   #import 'corgi/components/AdvTracking/AdvTrackingAdvertFragment.gql'

query ViewedProductsQuery($perPage: Int, $scroll: Float, $currentRegionId: Int) {
    viewedProducts(perPage: $perPage, scroll: $scroll) {
        products {
            product{
                ...productItemFields
                advert {
                    ...advTrackingAdvertFields

                }
            }
            timestampViewed
            timestampViewed1
        }
        hasNextPage
    }
}
**`timestampViewed1` don`t use in the project, but I don`t have an error @graphql-eslint/no-unused-fields**

When i run `eslint --debug src/client/components/ViewedProductsBlock/ViewedProductsQuery.graphql`
 I return 
 **Error while loading rule '@graphql-eslint/no-unused-fields': Rule `no-unused-fields` requires `parserOptions.operations` to be set and loaded**
dimaMachina commented 7 months ago

timestampViewed1 Is used in your query

mashaLutskevich2002 commented 7 months ago

@dimaMachina in my query used, but I don`t use timestampViewed1 in my react project in the .tsx files. This field only in the query. Shouldn't I be getting an error because of this? Because the field is not used anywhere except for the query.

My task is "To get rid of fields that are not used in queries"

mashaLutskevich2002 commented 7 months ago

I requested the field timestampViewed1 in the query, but I don't use it anywhere. I should get an error because of this

dimaMachina commented 7 months ago

This rule warns unused fields in schema by graphql operations

mashaLutskevich2002 commented 7 months ago

Please, tell me, is there any rule for my task?

dimaMachina commented 7 months ago

In graphql-eslint not

mashaLutskevich2002 commented 7 months ago

“This rule warns unused fields in schema by graphql operations”

What does it mean? I don’t understand (( It means that in schema is field with type. And in query (in graphql file) this field don’t use?

нд, 21 січ. 2024 р. о 21:34 Dimitri POSTOLOV @.***> пише:

Closed #2138 https://github.com/dimaMachina/graphql-eslint/issues/2138 as not planned.

— Reply to this email directly, view it on GitHub https://github.com/dimaMachina/graphql-eslint/issues/2138#event-11549775135, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANWLF4UOFR5O5NWLPMOXX5LYPVUTVAVCNFSM6AAAAABCEFY246VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGU2DSNZXGUYTGNI . You are receiving this because you authored the thread.Message ID: @.***>

dimaMachina commented 7 months ago

Rule warns fields that are not selected in any graphql operations https://the-guild.dev/graphql/eslint/rules/no-unused-fields