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
802 stars 105 forks source link

Unable to lint federation v2 schemas in v4 graphql-eslint #2812

Open InsidersByte opened 12 hours ago

InsidersByte commented 12 hours ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug

When attempting to lint a federation v2 schema with v4 of graphql-eslint that includes a federation directive e.g. @key. It fails with the error below.

Parsing error: Error while loading schema: Unknown directive "@key".

Unknown directive "@link".

It was possible to lint with v3 of graphql-eslint by setting parserOptions.schemaOptions.assumeValid to true, but it doesn't seem possible to do this in v4.

To Reproduce Steps to reproduce the behavior:

You can see an example failing schema here on the playground.

Expected behavior

To be able to lint federation v2 schemas.

Environment:

Additional context

I did see both of the following and while they are related it might not be the only way to resolve this issue hence I raised another one. Feel free to close if you think its appropriate:

dimaMachina commented 9 hours ago

try 4.3.0-alpha-20241204113935-074a093b359d2947f263679eac8596958876a3b6

graphql-eslint should parse federation subgraphs without parse errors and you could even use known-directives rule which previously reported errors about unknown @link directive.

But for linting federation subgraphs schemas optional peer dependency @apollo/subgraph should be installed (you'll get runtime error in case of missing it)

InsidersByte commented 8 hours ago

I just tried it and it worked great!

Thanks