From 4d7d27aff5b16333122c0b99896deb5ceb681623 Mon Sep 17 00:00:00 2001 From: Anthony Hinsinger Date: Tue, 19 Oct 2021 09:42:08 +0200 Subject: [PATCH] Remove prop subscription --- src/apolloclient.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/apolloclient.js b/src/apolloclient.js index 8992427..cb71dc1 100644 --- a/src/apolloclient.js +++ b/src/apolloclient.js @@ -140,6 +140,40 @@ client }); }); +const REMOVE_PROPERTY = gql` + subscription delIndiProp { + delIndiProp { + id + device { + id + } + } + } +`; + +client + .subscribe({ + query: REMOVE_PROPERTY, + }) + .subscribe(({ data }) => { + const res = client.readQuery({ + query: GETDEVICE, + variables: { id: data.delIndiProp.device.id }, + }); + client.writeQuery({ + query: GETDEVICE, + variables: { id: res.device.id }, + data: { + device: { + ...res.device, + properties: res.device.properties.filter( + (p) => p.id !== data.delIndiProp.id + ), + }, + }, + }); + }); + const NEW_VALUE = gql` subscription newIndiValue { newIndiValue {