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

Problem with setting operations property on parserOptions when no operations in .graphql files

Open BrianBusby opened this issue 2 years ago • 3 comments

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

Screen Shot 2022-08-18 at 1 30 36 PM

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.

BrianBusby avatar Aug 18 '22 17:08 BrianBusby

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',
      },
    },
  ],

jocmp avatar Aug 18 '22 20:08 jocmp

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
}

nikolaik avatar Aug 31 '22 19:08 nikolaik

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

tobiasdiez avatar Sep 18 '22 15:09 tobiasdiez

@BrianBusby please provide reproduction repo and I try to help you

dimaMachina avatar Sep 23 '22 23:09 dimaMachina

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 avatar Sep 26 '22 07:09 takumiya081

@takumiya081 can confirm your issue, try 3.11.1-alpha-20220926102745-dd5901a will release today

dimaMachina avatar Sep 26 '22 10:09 dimaMachina

@B2o5T I try it and works fine 🎉 thank you ❤️

takumiya081 avatar Sep 26 '22 10:09 takumiya081

closed due silence

dimaMachina avatar Mar 05 '23 12:03 dimaMachina