dotansimha / dotansimha/graphql-code-generator

Support auto selecting ids in typescript-operations

Open
#7,888 1 comment 4 reactions 0 assignees View on GitHub
core
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.**

I'm always frustrated when I use `@graphql-codegen/typescript-operations` to generate mock types for my Relay queries. It's frustrating because Relay will automatically select the `id` field behind the scenes if your type has one, but the generated types from `typescript-operations` do not include the `id` field.

This leads to me drop a bunch of `@ts-expect-error`s in my test files which actually make the entire object not type safe.

**Describe the solution you'd like**

I'd like `typescript-operations` to automatically include the `id` in the selection set if the type allows for it.k

**Describe alternatives you've considered**

I haven't thought of any.

**Additional context**

I've taken a stab at an implementation in [this PR](https://github.com/dotansimha/graphql-code-generator/pull/7881)

I created a repro of this problem in this [repo](https://github.com/tbezman/graphql-codegen-repro/blob/main/components/SomeComponent.test.tsx).

### Steps to repro
1. Clone that repo
2. yarn install
3. yarn jest
4. See the following error image

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.