Skip to content

[client-preset] FragmentType returns type never using client-preset 4.0.0 #9493

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

Closed
DerTimonius opened this issue Jun 9, 2023 · 2 comments
Closed

Comments

@DerTimonius
Copy link

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

Hi everyone, thank you for this great package!
We have been using codegen for a while now and recently updated the client-preset from 2.0.0 to 4.0.0 - now a lot of TypeScript errors are popping up across our react/next.js application. The errors could be found in every component that used fragments or that passed the fragment information down to a different component. Upon further inspection I was able to figure out that FragmentType is now returning never like in the screenshot below

image

It's still possible to access the information inside the fragment with useFragment, but the type is now unknown
image

Your Example Website or App

private repo

Steps to Reproduce the Bug or Issue

  1. Follow the guide to create fragments
    My fragment is similar to this:
const UserInfoFragment = graphql(/* GraphQL */ `
  fragment UserInfoFragment on User {
    id
    profile {
      id
      firstName
      lastName
    }
  }
`);
  1. Type it using FragmentType<typeof UserInfoFragment>
  2. Hover over the type or use two-slash queries
  3. See type never

Expected behavior

Before we updated the client-preset, FragmentType did return the correct type information
image

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: v18.16.0
  • graphql version: 16.6.0
  • @graphql-codegen/* version(s):
    • cli: 4.0.1
    • client-preset: 4.0.0

While trying for a quick fix I also tried re-adding @graphql-codegen/typescript and @graphql-codegen/typescript-urql but this did not help.

Codegen Config File

schema: supergraph.graphql
documents: [utils/**/*.ts, pages/**/*.tsx, components/**/*.tsx, hooks/*.ts]
generates:
  gql/:
    preset: 'client'
    plugins: []
    config:
      dedupeFragments: true

Additional context

In the fragment-masking.ts file I found this error:
image

I'm pretty sure that no one in our team touched this file, so this might have happened on updating the client-preset version.

@tnyo43
Copy link
Contributor

tnyo43 commented Jun 10, 2023

Which version of @graphql-typed-document-node/core do you use?
You need to use the latest version (v3.2.0) to use DocumentTypeDecoration .

(check out the CHANGELOG)

@DerTimonius
Copy link
Author

@tnyo43 Thanks for the running, found two different versions in the lockfile (3.2.0 and 3.1.1). Apparently TS did not recognize v3.2.0.

Was able to resolve this by adding the correct version to the resolutions in the package.json file!

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