Apollo-client: QUESTION: Custom Scalar Support in Apollo 2.0

Created on 27 Nov 2017  路  8Comments  路  Source: apollographql/apollo-client

Currently, what is the recommended approach to handling custom scalars in Apollo 2 OR Is it possible to instruct apollo-client to apply a particular conversion on a given query field. I know this question has been asked in the past, but has there been any movement on this now that Apollo 2.0 is here. Is there any best practice OR can we get some heads up on what is coming in this regard.

Most helpful comment

+1 in desperate need of scalars support!

All 8 comments

I would like to know the answer too, for example I have a custom GraphQL type that represents date/time and is formatted in ISO8601. Obviously over the wire this is transferred as a string, but in the client it would be nice to have it converted automatically to a Javascript Date object from the query results.

I've just been looking into how to do exactly this. I'd add, it'd be nice to be able to handle things like dates through a library rather than using JavaScript's own Date (e.g. parse with moment / luxon / js-joda).

Would it need to handle conversions in the opposite direction (e.g. for mutations)?

This blog post is the only mention of custom scalars for 2.0 that I can find. It says:

When combined, links and custom stores can be used for incredible new features.

  • Parsing of custom scalars like Dates

Custom Scalars are very important and usefull for Mutations where the input can be a custom InputType

I think this is already long overdue, same is asked here: https://github.com/apollographql/apollo-client/issues/585 August 2016.

Can't ApolloClient accept a Hydrator and from (__typename, object we can identify the scalars inside object and perform our own implementation ?

+1 in desperate need of scalars support!

@peggyrayzis looks like this is a duplicate issue of #585

Was this page helpful?
0 / 5 - 0 ratings