apollographql / eslint-plugin-graphql

:vertical_traffic_light: Check your GraphQL query strings against a schema.
https://www.npmjs.com/package/eslint-plugin-graphql
1.21k stars 103 forks source link

Ignoring a literal file with eslint-disable #102

Open pleunv opened 6 years ago

pleunv commented 6 years ago

Hey guys, thanks for this plugin! Probably going to make our life a lot easier :)

I'm having a couple problematic queries that I cannot immediately change in order to be validated (mostly unions with field type conflicts behind the same alias - query executes, but the validator is not a big fan), and I noticed that # eslint-disable does not seem to have any effect right now. Would it be feasible to add support for this, or is there currently a workaround?

bdrobinson commented 5 years ago

It would also be useful to do this on a per-line basis. Would this be difficult?

const query = gql`
  {
    whatever {
       field # eslint-disable-line
    }
  }
`
arkwright commented 5 years ago

In case it helps to unblock anyone, I just tested the following locally on eslint-plugin-graphql@3.0.3.

This does not work:

// eslint-disable-next-line graphql/no-deprecated-fields
const query = gql`
  {
    whatever {
       deprecatedField
    }
  }
`;

This works:

/* eslint-disable graphql/no-deprecated-fields */
const query = gql`
  {
    whatever {
       deprecatedField
    }
  }
`;
/* eslint-enable graphql/no-deprecated-fields */

Unfortunately this means that until one can migrate away from the deprecated field, any other fields within this query which are subsequently deprecated will not be caught by the linter.

cosmonot1 commented 4 years ago

Running into the same issue with # import and fragments. Specifically, the graphql/template-strings rule is complaining about unused variables. The variables are used in the fragments.

#import "./serverOnlyFragment.graphql"
#import "./sharedFragment.graphql"

# eslint-disable graphql/template-strings
# eslint-disable-next-line graphql/template-strings
query HomePageServer(    # eslint-disable-line graphql/template-strings
    # eslint-disable-next-line graphql/template-strings
    $isAuthenticated: Boolean!     # eslint-disable-line graphql/template-strings
    $gpid: Long!    # eslint-disable-line graphql/template-strings
    $latitude: Float!    # eslint-disable-line graphql/template-strings
    $longitude: Float!    # eslint-disable-line graphql/template-strings
    $tld: String!    # eslint-disable-line graphql/template-strings
) {
    ...ServerOnlyFragment
    ...SharedFragment
}

Expected # eslint-disable graphql/template-strings, # eslint-disable-line graphql/template-strings, or # eslint-disable-next-line graphql/template-strings to disable the rule, but it doesn't.

Would be stoked to get support for eslint-disable functionality, or of exhaustive checking of imports for rules

paul-vd commented 2 years ago

Also having the same is as @cosmonot1

margintop5px commented 4 months ago

+1 for per-line disabling