Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom serializer/deserializer for custom scalars #57

Open
DanielRose opened this issue Jun 8, 2021 · 5 comments
Open

Allow custom serializer/deserializer for custom scalars #57

DanielRose opened this issue Jun 8, 2021 · 5 comments

Comments

@DanielRose
Copy link
Contributor

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).

@DanielRose
Copy link
Contributor Author

graphql-typed-client has something like this: https://github.com/helios1138/graphql-typed-client#custom-scalar-type-mapping

@jasonkuhrt
Copy link

Was looking for this tonight for graphql-nexus/nexus-prisma#56 (comment).

@ayoung19
Copy link

@remorses also, is this feature on the roadmap?

@bennyk8y
Copy link

bennyk8y commented Apr 3, 2024

@remorses it would be really really great to have it

@jasonkuhrt
Copy link

fwiw I am working on making graphql-request type safe and it will have custom scalar support. The PR for it is almost done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants