Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
comatory opened this issue Jun 21, 2023 · 2 comments
Open

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

comatory opened this issue Jun 21, 2023 · 2 comments
Assignees

Comments

@comatory
Copy link

comatory commented Jun 21, 2023

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
Copy link
Author

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

@dimaMachina
Copy link
Collaborator

Yes, it totally makes sense and will be fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants