eslint-plugin-graphql
eslint-plugin-graphql copied to clipboard
Doesn't work with .gql files
Hi I'm trying to setup my project on vscode + eslint extension and this is what I did:
- Install
npm install -g graphql-cli - Run
graphql initat the root level of my frontend project - Run
graphql get-schemaand provide the graphql uri
My .graphqlconfig is as follows:
{
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"ruac_api": "http://172.17.6.74:3000/graphql"
}
}
}
- Installed eslint-plugin-graphql as a dev dependency through
yarn add -D eslint-plugin-graphql - Update my
.eslintrc.jsas 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'
}]
}
}
- I have my graphql queries and mutations in
.gql filesand 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
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:
- Install npm install -g graphql-cli
- Run graphql init at the root level of my frontend project
- 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" } } }
- Installed eslint-plugin-graphql as a dev dependency through yarn add -D eslint-plugin-graphql
- 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' }] } }
- 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 yes I did but didn't work either
@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 sorry I tried a few things but still not working :(
@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?
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.
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 .
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?
For me it does not warn about any problems in my .gql files (not existent types, undefined variables, ...). Help would be appreciated.
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 Spent literally hours on this, thanks so much for working this out!