eslint-plugin-graphql
eslint-plugin-graphql copied to clipboard
How to lint both template strings in JavaScript files and the content of gql files
trafficstars
With version 4.0.0 I try to lint deprecated field in a gql file and a template in a js file.
If I configure .eslintrc.js it with:
'graphql/template-strings': [
'error',
{
env: 'apollo',
// validators: 'all',
// eslint-disable-next-line global-require
schemaJson: require('./graphql.schema.json'),
tagName:'gql'
},
],
'graphql/no-deprecated-fields': [
'error',
{
env: 'literal',
// eslint-disable-next-line global-require
schemaJson: require('./graphql.schema.json'),
},
],
Then it will find a problem in gql files
me$ node ./node_modules/eslint/bin/eslint.js ./src/components/Cart.gql
/project/src/components/Cart.gql
48:7 error The field ShippingMethod.description is deprecated. Use localizedDescription graphql/no-deprecated-fields
✖ 1 problem (1 error, 0 warnings)
But it won't detect it in javaScript files
When I configure .eslintrc.js with:
'graphql/template-strings': [
'error',
{
env: 'apollo',
// validators: 'all',
// eslint-disable-next-line global-require
schemaJson: require('./graphql.schema.json'),
tagName:'gql'
},
],
'graphql/no-deprecated-fields': [
'error',
{
env: 'apollo',
// eslint-disable-next-line global-require
schemaJson: require('./graphql.schema.json'),
},
],
It will find the error in the javaScript file but not in the gql files.
There may be some sort of combination of settings that I haven't tried yet that will do both but I am unable to find it.
A work around could be to create multiple lint config files, one that is based on the .eslintrs.js but changes the env for the linter plugin and then run the linter twice