Skip to content

Failure on TypeScript files that contain satisfies keyword #10395

@awx-doma-lei

Description

@awx-doma-lei

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

Hey team, I just encountered this problem that graphql-codegen fails when an operation is located in a TypeScript file that contains the satisfies keyword. Upgrading all @graphql-codegen/* dependencies didn't help. Strangely enough, when I tried to reproduce with a fresh project, putting in the same plugins, configuration and the same TypeScript source code, it worked just fine.

Your Example Website or App

https://github.com/awx-doma-lei/graphql-codegen-cli-issue-repro

Steps to Reproduce the Bug or Issue

Run yarn codegen to see the error

Image

Expected behavior

As a user, I expect graphql-codegen to work with my TypeScript files that uses the satisfies keyword.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 20.18.1
  • graphql version: 16.9.0
  • @graphql-codegen/cli version(s): 5.0.2, 5.0.7

Codegen Config File

No response

Additional context

Looking into the error stack, I noticed there's a Missing semicolon error from @babel/parser, and found that it's an earlier version of Babel (7.18.11 in my case) that doesn't support TypeScript 4.9 syntax (it's supported since Babel 7.20.0). But in the fresh project, the installed Babel was the latest, and that explained the issue.

Babel was depended on by @graphql-codegen/cli through the following chain:

@graphql-codegen/cli
-> @graphql-tools/{code-file-loader,git-loader,github-loader}
   -> @graphql-tools/graphql-tag-pluck
      -> @babel/parser

The reason that upgrading didn't work despite the latest @graphql-tools/graphql-tag-pluck already requires a higher version of Babel (7.26.0) since 8.3.18 was that the latest @graphql-codegen/cli's dependencies is still as tolerant as ^8.0.0, so @babel/parser didn't get updated when I upgraded @graphql-codegen/cli.

I think we should update @graphql-codegen/cli's package.json to require the newer versions of @graphql-tools/* dependencies to ensure a higher version of Babel and hence to ensure the support of TypeScript 4.9.

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