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

Support Deno-compatible TypeScript outputs

Open XiNiHa opened this issue 6 months ago • 1 comments

Is your feature request related to a problem? Please describe.

Currently, it's not possible to consume TypeScript outputs from graphql-codegen in Deno, as the imports are either extensionless or use .js extensions(with emitLegacyCommonJSImports: false), whereas it must be .ts in Deno.

Describe the solution you'd like

Not sure, especially since we already have emitLegacyCommonJSImports config, which affects the import extensions. Maybe we should deprecate the existing config and then replace it with something more configurable.

Describe alternatives you've considered

No response

Any additional important details?

Here's the relevant codegen config (and a hacky workaround)

XiNiHa avatar Jun 17 '25 14:06 XiNiHa

Thank you for the example hook. I've implemented the following into my config so that my generated gql.ts file imports from .ts rather than .js:

const config: CodegenConfig = {
    // ...
    hooks: {
        beforeOneFileWrite: (_, content: string) => content.replace(/\.js/g, '.ts')
    },
}

kaboofdotdev avatar Jun 18 '25 23:06 kaboofdotdev

There is a disgusting hack that works:

"baseTypesPath": "types/schema.mts.mts"

Use .mts.mts and the last .mts will be automatically stripped, leaving behind the second one for a correct fully specified import path including the file extension.

jaydenseric avatar Jul 30 '25 23:07 jaydenseric