Skip to content

feat(visitor-plugin-common): support object form for the codegenScalarType extension#10893

Open
ifeanyi-ugwu wants to merge 1 commit into
dotansimha:masterfrom
ifeanyi-ugwu:feat/codegen-scalar-type-input-output
Open

feat(visitor-plugin-common): support object form for the codegenScalarType extension#10893
ifeanyi-ugwu wants to merge 1 commit into
dotansimha:masterfrom
ifeanyi-ugwu:feat/codegen-scalar-type-input-output

Conversation

@ifeanyi-ugwu

Copy link
Copy Markdown

Description

The codegenScalarType scalar extension is read as a single string and copied into both the input and output slots of the generated Scalars map:

} else if (scalarType.extensions?.codegenScalarType) {
  result[name] = {
    input:  { isExternal: false, type: scalarType.extensions.codegenScalarType as string },
    output: { isExternal: false, type: scalarType.extensions.codegenScalarType as string },
  };
}

So a schema-first scalar (one that ships codegenScalarType in its type extensions) can't declare a stricter parsed/input type than its wider resolver-return/output type — the two positions the generated Scalars map already distinguishes.

The scalars config option already supports this, via the normalizeScalarType helper that accepts string | { input, output }. This PR routes the extension through that same helper, giving the extension parity:

  • codegenScalarType: 'Foo'{ input: Foo; output: Foo } — unchanged
  • codegenScalarType: { input: 'A', output: 'B' }{ input: A; output: B }

Motivation

Scalar libraries such as graphql-scalars ship one codegenScalarType string per scalar, which can only ever describe one of the two positions. This closes that gap for every schema-first scalar — e.g. DateTime can declare { input: 'Date', output: 'Date | string | number' } (parsed value is a Date; a resolver may return a Date, an ISO string, or a timestamp).

Notes

  • Backward compatible — a string extension behaves exactly as before.
  • The codegenScalarType extension previously had no test coverage; two tests are added (string form + object form).
  • Changeset included (@graphql-codegen/visitor-plugin-common, minor).

…rType extension

Read the `codegenScalarType` scalar extension through the existing
`normalizeScalarType` helper, so it accepts either a string (mapped to both the
input and output slots, unchanged) or `{ input, output }` to map the two
positions independently — matching what the `scalars` config option already
supports. This lets a schema-first scalar declare a stricter parsed/input type
than its accepted resolver-return/output type, instead of collapsing both into
one.
@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ac97787

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/visitor-plugin-common Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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