Skip to content

Fix type errors in generated types when queries use enums or input objects - #139

Open
saga-dasgupta wants to merge 2 commits into
mainfrom
saga/fix-codegen-duplicate-types
Open

saga-dasgupta wants to merge 2 commits into
mainfrom
saga/fix-codegen-duplicate-types

Conversation

@saga-dasgupta

@saga-dasgupta saga-dasgupta commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

main updates GraphQL Codegen to v6 (#99), and the pending release (#137) would ship it. In v6, typescript-operations re-declares the enums and input objects that the typescript plugin already writes to the same file. Function templates use both plugins, so generated/api.ts has type errors as soon as a query uses an enum or an input object:

generated/api.ts: error TS2300: Duplicate identifier 'LineFilter'.

Functions still build, because esbuild doesn't type-check. But editors show the errors and tsc fails, so the generated types can't be type-checked, including when typing a prepare target's result with the run query's variables type. 3 of the 14 JavaScript function templates already hit this. Upstream won't change it (dotansimha/graphql-code-generator#10782).

What

Use the last codegen releases before that change: CLI 6.3.1, typescript 5.0.10 and typescript-operations 5.1.0.

Adds a test, run in a new CI workflow, that generates types the way Shopify CLI does and type-checks them. It fails on main.

Merge this before #137. Dependabot PRs that move codegen to v6 or v7 (#118, #120, #131, #133) bring this bug back, and the new test now fails on them.

Differences from 2.0.1

  • Union types in generated/api.ts are split across lines.
  • With skipTypename: true (not used by templates), an unselected union member is typed Record<PropertyKey, never> instead of {}, which is slightly looser.
  • Codegen dropped Node 18. Shopify CLI already requires Node 22.12.

Not changed here: the high-severity @graphql-tools/utils advisories that come through the @graphql-tools/url-loader and graphql-config pins. 2.0.1 and main have them too.

typescript-operations 6 re-declares the enums and input objects that the
typescript plugin already emits into the same file, so generated/api.ts fails
to compile when an input query selects an enum field or uses enum or input
object variables.

Use GraphQL Codegen CLI 6.3.1, typescript 5.0.10 and typescript-operations
5.1.0. They don't depend on lodash, and generate the same output as 2.0.1.
The duplicate declarations are type errors: esbuild doesn't type-check, so
functions still build. Inline the schema and query in the test, and drop the
prepare variables test, which also passes on main.
@saga-dasgupta saga-dasgupta changed the title Keep generated types compiling with enums and input objects Fix type errors in generated types when queries use enums or input objects Nov 9, 2026
@saga-dasgupta
saga-dasgupta marked this pull request as ready for review November 9, 2026 18:55

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant