I am updating the real-time status of the product data with a subscription. Here is my code
useProductSubscription({
varibales: {
ids: productIds
},
onData: ({ data }) => {
const dataUpdated = data.productUpdated;
if (!dataUpdated) return;
const { productId, status } = dataUpdated;
cache.modify({
id: cache.indentify({
__typename: 'Product',
id: productId,
}),
fields: {
status: () => status,
}
});
},
});
The data returned from the subscription update is fine, and I’m using the modify.cache function to update the cached data.
However, sometimes it does not update with the correct latest status and appears to be out of sync. This issue consistently occurs when there are frequent data updates from the subscription within a short period of time. Do you have any ideas about this problem, or could it be that I’m doing something wrong here? Thanks.
Here is data from Apollo Dev Tool
Payload return from subscription
ProductUpdatedPayload:a9297616-8335-4a6d-92fb-d4fb1bb7ab6c {
__typename: Product
id: "a9297616-8335-4a6d-92fb-d4fb1bb7ab6c"
status: "OPEN"
}
Product cache not update correctly
Product:a9297616-8335-4a6d-92fb-d4fb1bb7ab6c {
id: "a9297616-8335-4a6d-92fb-d4fb1bb7ab6c"
status: "CLOSED"
}
I would like update correct latest status as real-time and dont out of sync when receive data from subscription