eslint-plugin-graphql icon indicating copy to clipboard operation
eslint-plugin-graphql copied to clipboard

Doesn't work with .gql files

Open lobosan opened this issue 7 years ago • 11 comments

Hi I'm trying to setup my project on vscode + eslint extension and this is what I did:

  1. Install npm install -g graphql-cli
  2. Run graphql init at the root level of my frontend project
  3. Run graphql get-schema and provide the graphql uri

My .graphqlconfig is as follows:

{
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "ruac_api": "http://172.17.6.74:3000/graphql"
    }
  }
}
  1. Installed eslint-plugin-graphql as a dev dependency through yarn add -D eslint-plugin-graphql
  2. Update my .eslintrc.js as follows:
module.exports = {
  root: true,
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'module'
  },
  env: {
    browser: true
  },
  // https://github.com/standard/standard/blob/master/docs/RULES-en.md
  extends: 'standard',
  // required to lint *.vue files
  plugins: [
    'html',
    'graphql'
  ],
  // add your custom rules here
  'rules': {
    // allow paren-less arrow functions
    'arrow-parens': 0,
    // allow async-await
    'generator-star-spacing': 0,
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
    // import default settings for the GraphQL client
    'graphql/template-strings': ['error', {
      env: 'literal'
    }]
  }
}
  1. I have my graphql queries and mutations in .gql files and when I add a property that doesn't exist in my schema, I'm not getting any error from eslint

Any ideas about how to make it work will be much appreciated

lobosan avatar Nov 28 '17 20:11 lobosan

On my phone so don't have the requisite information, but have you tried the ".graphql" extension instead of ".gql"? On Tue, Nov 28, 2017 at 12:40 PM Santiago Galindo [email protected] wrote:

Hi I'm trying to setup my project and this is what I did:

  1. Install npm install -g graphql-cli
  2. Run graphql init at the root level of my frontend project
  3. Run graphql get-schema and provide the graphql uri

My .graphqlconfig is as follows:

{ "schemaPath": "schema.graphql", "extensions": { "endpoints": { "ruac_api": "http://172.17.6.74:3000/graphql" } } }

  1. Installed eslint-plugin-graphql as a dev dependency through yarn add -D eslint-plugin-graphql
  2. Update my .eslintrc.js as follows:

module.exports = { root: true, parser: 'babel-eslint', parserOptions: { sourceType: 'module' }, env: { browser: true }, // https://github.com/standard/standard/blob/master/docs/RULES-en.md extends: 'standard', // required to lint *.vue files plugins: [ 'html', 'graphql' ], // add your custom rules here 'rules': { // allow paren-less arrow functions 'arrow-parens': 0, // allow async-await 'generator-star-spacing': 0, // allow debugger during development 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // import default settings for the GraphQL client 'graphql/template-strings': ['error', { env: 'literal' }] } }

  1. I have my graphql queries and mutations in .gql files and when I add a property that doesn't exist in my schema, I'm not getting any error from eslint

Any ideas about how to make it work will be much appreciated

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apollographql/eslint-plugin-graphql/issues/95, or mute the thread https://github.com/notifications/unsubscribe-auth/ABERRjCdmZftJ7iqlz2h1f8n3rUFNbujks5s7G-sgaJpZM4Qt4Pu .

jnwng avatar Nov 29 '17 01:11 jnwng

@jnwng yes I did but didn't work either

lobosan avatar Nov 29 '17 01:11 lobosan

@lobosan Did you get this to work? I'm setting up a project with Next.JS and Apollo 2.x. Hoping to have linting of queries in .gql files.

gihrig avatar Jan 25 '18 06:01 gihrig

@gihrig sorry I tried a few things but still not working :(

lobosan avatar Jan 25 '18 13:01 lobosan

@lobosan its a little hard to see what's going on here. do you mind setting up a small repo with this problem? is it a problem within your editor or does it give you an error on the CLI too? whats the error that comes up?

jnwng avatar Jan 29 '18 18:01 jnwng

I have the same issue. I get this error in my eslintrc.js from eslint with the exact same config:

Error while running ESLint: Error while loading rule 'graphql/template-strings': Syntax Error GraphQL request (9:1) Unexpected String.

moimael avatar Feb 02 '18 12:02 moimael

Could you provide more information about the GraphQL document too? Once I can get an example set of code and configuration that’s reproducible I’ll be able to help a lot more On Fri, Feb 2, 2018 at 4:59 AM Maël Lavault [email protected] wrote:

I have the same issue. I get this eeror in my eslintrc.js from eslint with the exact same config:

Error while running ESLint: Error while loading rule 'graphql/template-strings': Syntax Error GraphQL request (9:1) Unexpected String.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/apollographql/eslint-plugin-graphql/issues/95#issuecomment-362579663, or mute the thread https://github.com/notifications/unsubscribe-auth/ABERRjmc5yPTmsEKmQJB89zTjyBVODfGks5tQwahgaJpZM4Qt4Pu .

jnwng avatar Feb 02 '18 17:02 jnwng

From the eslint docs:

Currently the sole method for telling ESLint which file extensions to lint is by specifying a comma separated list of extensions using the --ext command line option. Note this flag only takes effect in conjunction with directories, and will be ignored if used with filenames or glob patterns.

Have you tried: eslint . --ext .gql?

peerhenry avatar Aug 04 '19 12:08 peerhenry

For me it does not warn about any problems in my .gql files (not existent types, undefined variables, ...). Help would be appreciated.

lassesteffen avatar Oct 21 '19 15:10 lassesteffen

This happened to me too and finally fixed it. In my case it was this issue, hope it helps https://github.com/apollographql/eslint-plugin-graphql/issues/256

garcianavalon avatar Jan 22 '20 13:01 garcianavalon

@garcianavalon Spent literally hours on this, thanks so much for working this out!

gaving avatar Oct 05 '20 11:10 gaving