@derive Jason.Encoder

tjaco
2023-05-30

tjaco:

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?

zachdaniel:

is it an embedded resource? like use Ash.Resource, data_layer: :embedded ?

tjaco:

yes exactly

zachdaniel:

You want to use the graphql extension in that embedded resource and give it a type

tjaco:

ah cool, I’ll try that. Thanks!

zachdaniel:

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 🙂

tjaco:

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

tjaco:

ok, changed to use the graphql extension and added a type. Worked like a charm! Thanks again!