You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the GraphQL Codegen to automatically generate TypeScript types for my Shopify queries. I am running into issues using properties that have Scalar types, as these are shown as type any. For example, Product['created_at'] has type any, when it really should be string since it has the scalar type of DateTime which is an extension of a string.
The helper functions from @shopify/api-codegen-preset don't seem to provide scalar types by default, nor any way to manually provide these types. Since these types are managed by Shopify and relate specifically to the API, it would make the most sense to me for these to be automatically provided by the helper setup functions.
Use the .graphqlrc.ts file as outlined above in this issue.
Attempt to use a scalar property (eg. Product['createdAt']).
Debug logs
There is a temporary solution I've found – after using the shopifyApiProject() helper function, I managed to manually force the config to include scalars like so:
This seems to work, as the admin.types.d.ts file now includes the expected types for scalars. However it's not my favourite solution since it relies on hardcoding the scalar types, and also updating them if they are change (or new scalars are added) in future. Additionally, I have to mutate the setup object and provide a hack-y union type to keep type safety.
Could we have these scalars included by default? And if not, could we at least have a documented option added to the shopifyApiProject helper function that allows us to manually provide these without the workaround?
The text was updated successfully, but these errors were encountered:
Hi @sleepdotexe this is a great issue description and a good suggestion. We'll take a look at what we can add to shopifyApiProject, but in the meanwhile I'm glad that your workaround is working for you.
We're labeling this issue as stale because there hasn't been any activity on it for 60 days. While the issue will stay open and we hope to resolve it, this helps us prioritize community requests.
You can add a comment to remove the label if it's still relevant, and we can re-evaluate it.
Issue summary
Before opening this issue, I have:
@shopify/*
package and version:@shopify/api-codegen-preset@1.0.0
@shopify/shopify-api@11.0.0
{ logger: { level: LogSeverity.Debug } }
in my configuration, when applicableI am using the GraphQL Codegen to automatically generate TypeScript types for my Shopify queries. I am running into issues using properties that have Scalar types, as these are shown as type
any
. For example,Product['created_at']
has typeany
, when it really should bestring
since it has the scalar type ofDateTime
which is an extension of a string.The helper functions from
@shopify/api-codegen-preset
don't seem to provide scalar types by default, nor any way to manually provide these types. Since these types are managed by Shopify and relate specifically to the API, it would make the most sense to me for these to be automatically provided by the helper setup functions.According to https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#scalars, it should theoretically be possible to provide scalars to the codegen.
Here is an example
.graphqlrc.ts
:Expected behavior
Using the
.graphqlrc.ts
above, the inbuilt Shopify Scalars should be automatically generated inadmin.types.d.ts
like so:...Which allows the properties to have correct types in files.
Actual behavior
The Shopify scalars have types of
any
....Which means properties are not typed correctly.
Steps to reproduce the problem
Product['createdAt']
).Debug logs
There is a temporary solution I've found – after using the
shopifyApiProject()
helper function, I managed to manually force the config to include scalars like so:This seems to work, as the
admin.types.d.ts
file now includes the expected types for scalars. However it's not my favourite solution since it relies on hardcoding the scalar types, and also updating them if they are change (or new scalars are added) in future. Additionally, I have to mutate the setup object and provide a hack-y union type to keep type safety.Could we have these scalars included by default? And if not, could we at least have a documented option added to the
shopifyApiProject
helper function that allows us to manually provide these without the workaround?The text was updated successfully, but these errors were encountered: