@derive Jason.Encoder

Hi All, I have an embedded Json object in Ash which is consumed by GraphQL. I have configured graphQL to use json instead of json_string like described here => https://hexdocs.pm/ash_graphql/use-json-with-graphql.html But now I get a Jason.Encoder error. In Ecto this can be solved by adding @derive Jason.Encoder in the module. Is there a way in Ash to do this?
6 Replies
ZachDaniel
ZachDaniel•2y ago
is it an embedded resource? like use Ash.Resource, data_layer: :embedded?
drumusician
drumusicianOP•2y ago
yes exactly
ZachDaniel
ZachDaniel•2y ago
You want to use the graphql extension in that embedded resource and give it a type
drumusician
drumusicianOP•2y ago
ah cool, I'll try that. Thanks!
ZachDaniel
ZachDaniel•2y ago
Keep in mind, this will mean that the graphql reponse will no longer be json, but will be a properly structured type, so if you do that it may require some changes 🙂
drumusician
drumusicianOP•2y ago
yeah that's fine, it's a greenfield thing so I can model it like I want. I guess even better to have it like that ok, changed to use the graphql extension and added a type. Worked like a charm! Thanks again!

Did you find this page helpful?