graphql-eslint
graphql-eslint copied to clipboard
Problem with setting operations property on parserOptions when no operations in .graphql files
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox
Please make sure the graphql-eslint version under
package.json
matches yours.
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
We don't have operations defined inside of .graphql files. They are all defined in .ts and .tsx files. If I set my config as:
overrides: [
{
files: ['*.ts', '*.tsx'],
processor: '@graphql-eslint/graphql',
},
{
files: ['*.graphql'],
extends: ['plugin:@graphql-eslint/operations-recommended', 'plugin:@graphql-eslint/relay'],
parserOptions: {
operations: './src/**/*.{ts,tsx}',
schema: '../api-server/src/schema.graphql',
},
},
],
then I get the following errors in each of the .tsx files
If I remove the operations property from parserOptions, then I get the following error for a number of rules:
Error: Error while loading rule '@graphql-eslint/require-id-when-available': Rule `require-id-when-available` requires `parserOptions.operations` to be set and loaded. See https://bit.ly/graphql-eslint-operations for more info
I'm not sure how to proceed without running into errors or disabling a lot of rules.
Hey @BrianBusby I ran into a similar situation that led me to this issue.
I had some success with replacing the operations
field with documents
. The latter is a field supported via GraphQL config.
overrides: [
{
files: ['*.ts', '*.tsx'],
processor: '@graphql-eslint/graphql',
},
{
files: ['*.graphql'],
extends: ['plugin:@graphql-eslint/operations-recommended', 'plugin:@graphql-eslint/relay'],
parserOptions: {
- operations: './src/**/*.{ts,tsx}',
+ documents: './src/**/*.{tsx,ts}',
schema: '../api-server/src/schema.graphql',
},
},
],
I had a legacy .graphqlconfig
taking precedence over parserOptions that cased similar issues like described in the original post. After adding the following parserOptions all was well:
parserOptions: {
skipGraphQLConfig: true
}
I had the same issue and solved it by specifying documents
in the graphql config file. It appears to me that once you have a config file, schema and documents need to be specified there:
https://github.com/B2o5T/graphql-eslint/blob/8a3b5843f2aa2b1cbd9c1021ef24a3005c5b0508/packages/plugin/src/parser.ts#L20-L24
@BrianBusby please provide reproduction repo and I try to help you
I have same problem, then I create repo. https://github.com/takumiya081/eslint-graphql-not-work-sample https://github.com/takumiya081/eslint-graphql-not-work-sample/blob/main/packages/packageB/.eslintrc.js
yarn workspace package-b lint
yarn workspace v1.22.19
yarn run v1.22.19
warning package.json: No license field
$ eslint ./src --ext graphql
Oops! Something went wrong! :(
ESLint: 8.24.0
Error: Error while loading rule '@graphql-eslint/require-id-when-available': Rule `require-id-when-available` requires `parserOptions.operations` to be set and loaded. See https://bit.ly/graphql-eslint-operations for more info
@takumiya081 can confirm your issue, try 3.11.1-alpha-20220926102745-dd5901a
will release today
@B2o5T I try it and works fine 🎉 thank you ❤️
closed due silence