Skip to content

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

Open

Description

@comatory

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

Activity

  1. comatory commented on Aug 21, 2023

    @comatory
    Author

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

  2. dimaMachina commented on Aug 21, 2023

    @dimaMachina
    Contributor

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址