Skip to content

How to implement a custom scalar to check that type is a date #650

Answered by hayes
wakywayne asked this question in Q&A
Discussion options

You must be logged in to vote

If you don't need custom serialization or parsing for your scalars, I would recommend using an existing scalar instead of defining your own. The graphql-scalar package has tons of great scalars that cover most use cases. You can see a fairly simple example of a date scalar added here: https://github.com/hayes/pothos/blob/main/examples/complex-app/src/builder.ts

parsing and serialization are required for converting between JSON (in the request or response) and the values used in your resolvers. For example, with the date scalar, the argument passed to parse would be a iso date string, and the function should return a Date object. Serialization is the opposite, it receives a Date object, an…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@wakywayne
Comment options

@hayes
Comment options

@wakywayne
Comment options

Answer selected by hayes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants