Skip to content

fix(@nestjs/graphql): restore Timestamp scalar parsers in federation factory#3962

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/federation-scalar-restoration
Apr 28, 2026
Merged

fix(@nestjs/graphql): restore Timestamp scalar parsers in federation factory#3962
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/federation-scalar-restoration

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Summary

  • Extend the scalar restoration branch in GraphQLFederationFactory.overrideOrExtendResolvers to cover the built-in Timestamp scalar in addition to DateTime.
  • Also copy serialize from the auto-generated scalar so the round-trip works regardless of which scalar shape the user picked.

Bug

After buildSubgraphSchema re-parses the printed SDL, the resulting executable schema has scalars with default (no-op) parsers. The override step only restored parseValue / parseLiteral for the DateTime scalar — DateTime happened to render correctly anyway because the default serializer hands a Date straight to JSON which produces an ISO string, matching GraphQLISODateTime.serialize's output.

When users opt into dateScalarMode: 'timestamp', the schema uses GraphQLTimestamp whose serialize returns value.getTime(). Without the restoration, that scalar fell back to the default serializer in the federated schema, so resolvers that return a Date ended up with the raw ISO string in the response instead of a numeric epoch.

// before — only DateTime is restored
} else if (isScalarType(type) && type.name === 'DateTime') {
  type.parseLiteral = autoGeneratedScalar.parseLiteral;
  type.parseValue   = autoGeneratedScalar.parseValue;
}

Fix

  • Restore Timestamp alongside DateTime.
  • Also restore serialize so the auto-generated scalar's full implementation comes through.

Test plan

  • New e2e spec packages/apollo/tests/e2e/federation-timestamp-scalar.spec.ts boots an Apollo Federation app with dateScalarMode: 'timestamp', returns a Date(0) from a resolver, and asserts the response value is the numeric 0. Fails on master, passes after the fix.
  • Existing tests/e2e/code-first-federation.spec.ts continues to pass.

…factory

`overrideOrExtendResolvers` re-attaches `parseValue` / `parseLiteral`
from the auto-generated schema only for the `DateTime` scalar. After
`buildSubgraphSchema` re-parses the printed SDL, custom-implementation
scalars come back without their parsers - DateTime happens to look
correct because the default serializer JSON-stringifies a `Date` to ISO
format, but `Timestamp` (the scalar produced by
`dateScalarMode: 'timestamp'`) needs `serialize` to convert a `Date` to
the numeric epoch and was therefore returning the raw ISO string in
federated responses.

Cover both `DateTime` and `Timestamp` in the restoration branch and
also copy `serialize` so the round-trip works regardless of which date
mode the user picked.
@kamilmysliwiec kamilmysliwiec merged commit f4c96d6 into nestjs:master Apr 28, 2026
1 check passed
@kamilmysliwiec
Copy link
Copy Markdown
Member

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants