Search code examples
reactjsrelayjsgraphql

How to delete a node fetched by Relay from all connections that include it?


Relay provides the NODE_DELETE mutation config to "remove the node from a connection and delete the associated record from the store".

But what happens when for instance node A is included as a connection from nodes B1, B2, B3... (an unknown number of them), and our application has Relay containers showing those B nodes and their respective connections to A? If we delete A just from the B1 connection via NODE_DELETE, will all Relay containers get updated, or just the one showing B1?


Solution

  • Since every node has a globally unique ID, Relay knows that the nodes with IDs specified in deletedIDFieldName were deleted, and can exclude them from all connections in which they existed.