dotansimha / dotansimha/graphql-code-generator
Allow Relay's internal __id in queries
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Is your feature request related to a problem? Please describe.**
We are using [Relay](https://relay.dev/) as our FE GQL library. Relay offers a [client-only `__id` to query the internal record id](https://relay.dev/docs/guided-tour/list-data/updating-connections/#accessing-connections-using-__id). The Relay compiler understands this `__id` in queries but GraphQL Code Generator does not.
Example schema:
```
type Query {
me: User!
}
type User implements Node {
id: ID!
username: String!
email: String!
}
```
Example query:
```
query FooQuery {
me {
__id
id
name
}
}
```
If I set `skipDocumentsValidation: true` the code will later fail (in our case when executing the `typescript` plugin) when it expects a `__id` field to be defined as part of the schema.
**Describe the solution you'd like**
The Apollo `@client` directive could work if GraphQL codegen special cased that directive. It could skip over this field during validation and not include it in the generated types.
**Describe alternatives you've considered**
It is possible right now to set `skipDocumentsValidation: true` and to define the `__id` field in a client schema extension for each type that queries for it.
However this solution isn't great as using `__id` in a query will work (as in Relay will compile w/o error and the GQL fetch works) but will produce an unhelpful error (`name` property doesn't exist on `undefined`). This won't help developers understand how to fix this error by defining a client schema extension for a `__id` field for that type.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.