Skip to content

fix(api-codegen-preset): generate string instead of any for custom scalars#3099

Open
byrichardpowell wants to merge 1 commit intomainfrom
worktree-fix/codegen-scalar-types
Open

fix(api-codegen-preset): generate string instead of any for custom scalars#3099
byrichardpowell wants to merge 1 commit intomainfrom
worktree-fix/codegen-scalar-types

Conversation

@byrichardpowell
Copy link
Contributor

@byrichardpowell byrichardpowell commented Mar 13, 2026

WHY are these changes introduced?

Fixes #1154

When using shopifyApiProject() or shopifyApiTypes(), all Shopify-specific custom scalars (DateTime, Money, URL, HTML, FormattedString, Decimal, UnsignedInt64, etc.) were typed as any in the generated output. This is because the @graphql-codegen/typescript plugin defaults unknown scalars to any when no scalars config is provided, and the preset never configured one.

WHAT is this pull request doing?

Adds two config keys to the typescript codegen plugin invocation in shopifyApiTypes():

  • defaultScalarType: 'string' — all custom scalars (current and future) now generate as string, which is the correct runtime type for virtually all Shopify API scalars (DateTime, Money, URL, HTML, etc.)
  • scalars: {JSON: 'unknown'} — overrides the one exception; the JSON scalar generates as unknown rather than string

Because defaultScalarType is used rather than a hardcoded list, any new scalars Shopify adds to the API in future versions are handled automatically without code changes.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)

Checklist

  • I have used pnpm changeset to create a draft changelog entry (do NOT update the CHANGELOG.md files manually)
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

…alars

Shopify API custom scalars (DateTime, Money, URL, HTML, etc.) now resolve
to `string` in generated TypeScript output rather than `any`. The JSON scalar
resolves to `unknown`. Uses the typescript codegen plugin's `defaultScalarType`
and `scalars` options, so any future scalars added to the Shopify API are
handled automatically without code changes.

Fixes #1154

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Admin API GraphQL Codegen does not generate types for scalars

1 participant