fix(@nestjs/graphql): restore Timestamp scalar parsers in federation factory#3962
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Apr 28, 2026
Conversation
…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.
Member
|
lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GraphQLFederationFactory.overrideOrExtendResolversto cover the built-inTimestampscalar in addition toDateTime.serializefrom the auto-generated scalar so the round-trip works regardless of which scalar shape the user picked.Bug
After
buildSubgraphSchemare-parses the printed SDL, the resulting executable schema has scalars with default (no-op) parsers. The override step only restoredparseValue/parseLiteralfor theDateTimescalar —DateTimehappened to render correctly anyway because the default serializer hands aDatestraight to JSON which produces an ISO string, matchingGraphQLISODateTime.serialize's output.When users opt into
dateScalarMode: 'timestamp', the schema usesGraphQLTimestampwhoseserializereturnsvalue.getTime(). Without the restoration, that scalar fell back to the default serializer in the federated schema, so resolvers that return aDateended up with the raw ISO string in the response instead of a numeric epoch.Fix
TimestampalongsideDateTime.serializeso the auto-generated scalar's full implementation comes through.Test plan
packages/apollo/tests/e2e/federation-timestamp-scalar.spec.tsboots an Apollo Federation app withdateScalarMode: 'timestamp', returns aDate(0)from a resolver, and asserts the response value is the numeric0. Fails on master, passes after the fix.tests/e2e/code-first-federation.spec.tscontinues to pass.