Is it possible to map scalars (Date) client-side?

I would like to automatically translate values queried with the scalar type Date to JavaScript Date objects client-side.

There are many examples on how to do this mapping server-side, but can the equivalent be done server-side by passing something to new ApolloClient?


new ApolloClient({
  scalars: {
    Date: {
      parseLiteral: value => new Date(value),
      serialize: value => value.toISOString()
1 Like

So currently, there is no functionality to do that. I personally would love for something like this to exist. The proposed solution right now is to use cache read functions to deserialize scalars on a per field basis (Customizing the behavior of cached fields - Client (React) - Apollo GraphQL Docs).

The feature request for custom scalars should also have more information! Support for custom scalars · Issue #2 · apollographql/apollo-feature-requests · GitHub

1 Like