-
Notifications
You must be signed in to change notification settings - Fork 1
Allow generating .ts files with enums #9
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
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied the changes to an existing app, and was able to use .ts
as expected!
Hello, I am experiencing this issue as enum can't be imported for d.ts files. Is there a way to force this tool to generate a .ts file directly, instead of d.ts ? Renaming is an option but you have to do it all the time the file is re-generated. |
When you configure this plugin, you can specify a name for the generated file. You just need to do it once and it should be always generated with that name: export default {
overwrite: true,
pluckConfig,
generates: {
'my-api.generated.ts': {
preset, schema, documents: [...]
}
}
} |
Hello @frandiox , Sorry to be a mess here, but for the hell of me I can't figure out how to configure that with Shopify recommendation here: https://shopify.dev/docs/api/shopify-app-remix/v2/guide-graphql-types My
It should definitely be documented somewhere in the official Shopify documentation. |
Great catch! This is working! Thanks a lot. |
@bakura10 Hey! I’m curious about what led you to bring this up in this repo instead of the preset's repo, which has some documentation on declarations. I’m just trying to get a better understanding of how you got here. Did the mention of the "graphql-codegen" script in the template docs influence your choice, or was it something else? Thanks for clarifying! |
Hi @frandiox , When I searched "Shopify graphql codegen" on Google, this repo came first :D. |
Helo @frandiox , I am currently creating a library to interact with metafields/metaobjects, and I am still having quite a lot of issues with enums. I've found that there is a |
For reference, I've been able to do it by not using the preset, with this config: export default {
// For syntax highlighting / auto-complete when writing operations
schema: 'https://shopify.dev/admin-graphql-direct-proxy/2025-04',
documents: ['./src/**/*.{js,ts,jsx,tsx}'],
projects: {
default: {
// For type extraction
schema: 'https://shopify.dev/admin-graphql-direct-proxy/2025-04',
extensions: {
codegen: {
generates: {
'./src/types/admin.types.d.ts': {
plugins: ['typescript'],
config: { enumsAsTypes: true }
}
},
},
},
},
},
}; |
We pass your config to the tool here: https://github.com/Shopify/graphql-codegen/blob/main/src/preset.ts#L134 I'd suggest opening a new issue so that the new maintainers can check it 🙏 |
This should enable using enums in the generated file when its extension is
.ts
instead of.d.ts
.