How to ergonomically add/remove to an array of embedded resource in graphql
The docs state flatly that if you do updates on an array'd embedded resource it simply calls destroy on them all, and then recreates them. This makes sens as you typically atomically replace the json blurb on read/write.
I have to model this as embedded as I am sharing the table with a legacy system in a transition period, or I would just model it as actual rows and use manage_relationship.
Right now I am looking for the most ergonomic way to have addFoo and removeFoo mutations in my parent resource.
I have modeled up a custom type for a generic addFoo action that loads the parent resource and adds it to the embed list.
Then I hae a custom removeFoo action that loads the list, removes based on finding the ID and then writing it again.
This sort of feels more clunky than my usage of cast_embed in regular ecto based elixir dev, but I am not sure if there is something obvious I am missing here?
3 Replies
Does the embed have primary keys?
Actually nvm that won't help
I'd probably use a custom update action to do it personally
Not a generic action
I could see a case for builtin changes to do this sort of stuff
the embeds do have keys, thats how I implement the deletes
the custom update you mean is to have an arg foo and do a custom change and return the parent?
that is actually what the legacy graphql does I see now so yeah
The main issue right now is that embedded types do not create proper input types
it just ends up as JsonString
using:
Aha, when its an embedded resource you can just put it straight in as the type for the argument apparently... I thought that wasnt working.. has something changed?
It's only for non embedded resources