kamilkisiela / graphql-config

One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
https://the-guild.dev/graphql/config
MIT License
1.16k stars 93 forks source link

Support Relay `__id` data ID field on non-scalar types #1374

Open comatory opened 1 year ago

comatory commented 1 year ago

Is your feature request related to a problem? Please describe.

We're using graphql-eslint with graphql-config to enable linting GraphQL string in our frontend codebase which uses Relay.

Field __id is available in Relay on all non-scalar fields: https://relay.dev/docs/next/glossary/#dataid. The meaning behind this id (also called data ID) is to expose the value of the key in Relay's cache. Most of the times __id equals to id if type extends Node interface.

But our use-case is with connections. Relay mutations can receive "connection ID" so you can update lists, it's idiomatic to pass this id dynamically by querying __id on connection fragment (supplied to usePaginationFragment hook).

The problem is that at the moment we must disable @graphql-eslint/fields-on-correct-type rule because field __id is not recognized, e.g.:

error  Cannot query field "__id" on type "ItemsConnection"  @graphql-eslint/fields-on-correct-type

Describe the solution you'd like

Provide boolean option in configuration file that would specify that schema is used in Relay context. It could be as simple as relay: true or to future-proof it for other clients:

client: 'relay'

It's not really important I think.

Describe alternatives you've considered

I've tried to create my own extension in graphql-config so I could try extending every non-scalar type with __id but I did not manage to load the extension. It's not entirely clear to me from documentation how can I create and load my own extension if I'm using graphql-eslint because my goal is to not create 3rd party tool (I noticed tools like graphql-codegen load the configuration and extension in one specific place via CLI).

Additional context

comatory commented 10 months ago

👋 Hey, what do you think about my proposal? Does it make sense?

dimaMachina commented 10 months ago

Yes, it totally makes sense and will be fixed!