graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Auto select ids for relay

Open tbezman opened this issue 2 years ago • 7 comments

Description

Relay automatically selects the id field on a type if one is available, event when the engineer did not explicitly select it in their query / fragment / whatever. At Gallery, we use graphql-codegen to generate type safe mocks for our tests. This leads to a divergence between the two technologies. The types generated by graphql-codegen do not have the id field in the types. This leads to Relay freaking out when the id field is not present.

This PR simply automatically selects the field if one is present.

Type of change

Please delete options that are not relevant.

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

How Has This Been Tested?

I added a new test block to ts-document-spec with some good coverage related to this code.

Test Environment:

  • OS: MacOS
  • @graphql-codegen/...: ?
  • NodeJS: 16.12.0

Checklist:

  • [ ] I have followed the CONTRIBUTING doc and the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules

tbezman avatar May 25 '22 06:05 tbezman

⚠️ No Changeset found

Latest commit: dd4599c55bb8bb90fbfffd4461bce32786f54977

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar May 25 '22 06:05 changeset-bot[bot]

Someone is attempting to deploy a commit to the The Guild Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 25 '22 06:05 vercel[bot]

@charlypoly I'm a bit confused on how I can help move this PR forward. Should we be discussing in the other thread? https://github.com/dotansimha/graphql-code-generator/issues/7888

tbezman avatar Aug 01 '22 13:08 tbezman

@charlypoly can we get this merged?

Robinnnnn avatar Aug 19 '22 04:08 Robinnnnn

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
graphql-code-generator ✅ Ready (Inspect) Visit Preview Aug 19, 2022 at 10:16AM (UTC)

vercel[bot] avatar Aug 19 '22 10:08 vercel[bot]

@n1ru4l definitely. i've since fixed a few small bugs. will get this PR updated asap.

tbezman avatar Sep 01 '22 07:09 tbezman

@n1ru4l Alright, we should be good for a review

tbezman avatar Sep 04 '22 19:09 tbezman

Hey @tbezman, starting with https://github.com/dotansimha/graphql-code-generator/releases/tag/release-1676995873 it is now possible to provide custom document transforms.

This allows implementing this in user-land, therefore this PR might no longer be needed.

What do you think?

n1ru4l avatar Feb 24 '23 10:02 n1ru4l

Hey @tbezman any update regarding https://github.com/dotansimha/graphql-code-generator/pull/7881#issuecomment-1443393864?

n1ru4l avatar Mar 08 '23 15:03 n1ru4l

Closing this. Please use document transforms for implementing this. https://github.com/dotansimha/graphql-code-generator/releases/tag/release-1676995873

n1ru4l avatar Mar 16 '23 11:03 n1ru4l