@dpeek this is the expected behaviour since if we call set in Dgraph the same thing happens. If you replace set with remove it will function the way you expect it. Though I do understand that setting it to null you would expect it to run that way.
Understood that this is how dgraph works, but it will be surprising for GraphQL users that donât know that. It also seems that right now thereâs no way to remove an edge from the graphql endpoint?
One suggestion might be to generate separate add{TypeName}{CapitalisedFieldName} / delete{TypeName}{CapitalisedFieldName} mutations in the schema that allow append/delete, and then update should delete and replace?
Thereâs both set and remove options in the update mutations. So it is possible to both add and remove edges.
This models the way itâs always worked in Dgraph.
Thereâs a reason to have these two behaviours : say for example Iâve got 1,000,000 followers, and the app wants to add one more follower - does it really need to fetch all 1,000,000 from Dgraph, add the one, and then send back a mutation for 1,000,000+1. Thatâs why thereâs set and remove mutations in Dgraph. Set really only does addition of edges, remove does deletion of edges. That might not be made clear enough in the docs.
Often that correctly models the way an app attaches updates to clickable components in a UI: e.g. you click follow, it just sends an update set mutation for the one new follower. The mutation/UI doesnât have to know the full current state, it just needs to know about the change it wants to make.
I wonder because GraphQL is another level of abstraction up, if there needs to be a third option for âjust make it exactly as I have serialized it from my clientâ. E.g: the client doesnât want to write code to work out whatâs different, whatâs been added, whatâs been removed. etc. it just wants to make a mutation.
An example could be something like âtagsâ on a post - the user has clicked around to add and remove some tags as part of editing a post. In the handler for save, the frontend dev doesnât want to write code to compute the tags added and the tags removed, they just want to say that the post has been edited, now looks like this, please save it in the update mutation. On the backend we can open a transaction, compute the diffs and save as per the Dgraph set and remove primitives.
GraphCool used to have addTypeField / removeTypeField and setTypeField / unsetTypeField mutations for this very reason â update would replace all while the the others would append / delete. I totally get what you are saying about aligning with how dgraph works, Iâm just saying thatâs itâs confusing from a user perspective, particularly for to-one edges.
Right now, to replace an edge my mutations looks like this:
Fairly sure (for edges to nodes, not scalars)⌠see âBut inverse edges not cleaned upâ above.
I think it is doing what dgraph does and adding an edge, and then whether you get the old the new back is luck of the draw as to which edge is first. Setting it to null certainly doesnât workâŚ