dimaMachina / graphql-eslint

ESLint parser, plugin, and rule set for GraphQL (for schema and operations). Easily customizable with custom rules. Integrates with IDEs and modern GraphQL tools.
https://the-guild.dev/graphql/eslint
MIT License
800 stars 104 forks source link

Cannot read properties of undefined (reading 'parserServices') #2569

Open waynezhang1995 opened 2 months ago

waynezhang1995 commented 2 months ago

Issue workflow progress

We are on @graphql-eslint/eslint-plugin@4.0.0-alpha.0.

This is our eslintrc

 files: ['*.graphql'],
 parser: '@graphql-eslint/eslint-plugin',
 plugins: ['@graphql-eslint'],
 rules: {
       ....

.graphqlrc.yml

schema:
    - internal/graph/schema/**/*.graphql
    - scripts/**/*.graphql

the above error is coming from

function requireGraphQLSchemaFromContext(ruleId, context) {
  const { schema } = context.sourceCode.parserServices;
  if (!schema)
    throw new Error(
      `Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/config/docs/user/schema for more info`
    );
  return schema;
}

and interestingly, if we change context.sourceCode to context.getSourceCode() everything starts working normally.

Appreciate any helps. Thanks

Progress of the issue based on the Contributor Workflow


Describe the bug

To Reproduce Steps to reproduce the behavior:

Expected behavior

Environment:

Additional context

alecmev commented 1 month ago

Similar issue for us, but with documents. getSourceCode() doesn't seem to help either. Sprinkled some console.logs, and looks like the wrong graphql.config.* is being loaded/used. It's a monorepo and we have more than one, and one of them doesn't have documents, because there aren't any in that particular package, only schemas.

Appears to happen only via LSP (in VSCode), not CLI.