Using custom scalars with gqlgen.client #2728
geertjanvdk
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With gqlgen you can define your own scalars, for example, I have a scalar
type Date time.Time
which when encoded/decoded, it is always from/to an ISO-date.This works great, but not so with the
gqlgen.client
. If you use your scalars, you will get an error like:'something.StartDate' expected a map, got 'string'
. Under the hood, gqlgen usesmapstructure
, and that does not know about your scalars.That was until a new feature or fix was released with gqlgen v0.17.33. Now you can define some custom decoding configuration.
It's a bit .. hard to find this in the documentation, so I thought adding a discussion to document, and discuss maybe a better example.
I have a type with all encoding and decoding, etc..:
When I use this in my response in tests, I would get
expected a map, got 'string'
.Using the new method
SetCustomDecodeConfig
, we can add this to thegqlgen.client
like this:Now my custom scalar works, and I can continue testing :)
Maybe it's good to add the above with the documentation?
Beta Was this translation helpful? Give feedback.
All reactions