-
I read the docs and I see that there is a way to implement custom scalars, but I don't see how the addScalarType function works.I have added the code to my schema as instructed in the docs.:
I tried doing this from the docs:but obviously that represents a function that I don't know how to make
So now I tried something like this:
I do not have the slightest clue what these serialize and parse value do and I cant find there definitions in the docs |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
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, and needs to turn it in to a iso date string so it can be accurately represented in the JSON response. Generally I would recommend using the existing implementations so you don't have to define these methods yourself, unless you need something very custom |
Beta Was this translation helpful? Give feedback.
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…