Using react-relay v15.
I have a component that gets a list of orders.
const data = useLazyLoadQuery<OrdersQueryType>(OrdersQuery, {});
I have another component that can delete orders via a mutation.
mutation DeleteOrderMutation($orderId: ID!) {
deleteOrder(input: { orderId: $orderId }) {
order {
id @deleteRecord
}
}
}
If the data originally had three orders in it, after the mutation runs, it has 2 orders in it, and a null element where the deleted order was.
Can this be avoided so that the array only has two entries? Adding null checks for arrays contents is not ideal.
Is there a subscription set up for your original query? If configured correctly adding a subscription would dynamically update your local relay store and you would not need to manually delete the record with @deleteRecord. The following is from relay docs:
I hope this helps, thanks for reading!