Skip to content

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

@DerTimonius

Description

@DerTimonius

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions