Open DanielRose opened 3 years ago
graphql-typed-client has something like this: https://github.com/helios1138/graphql-typed-client#custom-scalar-type-mapping
Was looking for this tonight for https://github.com/prisma/nexus-prisma/pull/56#discussion_r656678366.
@remorses also, is this feature on the roadmap?
@remorses it would be really really great to have it
fwiw I am working on making graphql-request
type safe and it will have custom scalar support. The PR for it is almost done.
Using the CLI option
--scalar
, it is possible to set the Typescript type of custom scalars. However, that only modifies the generated interfaces. The actual value of the scalar is unchanged.For easier working with the scalar values after a query/subscription, they may need to be deserialized differently than the default. The same with a mutation: the scalars may need to be serialized differently than the default. While it is possible to do this manually, it would be much easier and less error-prone if this could be done by passing custom serializer/deserializer functions.
For example, a custom scalar could be "Date". The actual values will be transferred as strings. For easier usage, it would be much better if they were deserialized after a query into a Javascript Date or Luxon DateTime. For a mutation, the Date/DateTime would probably need to be serialized as string again (instead of hoping the default serialization will work).