Added remove props handler
This commit is contained in:
+41
-12
@@ -1,5 +1,3 @@
|
|||||||
import { onError } from "@apollo/client/link/error";
|
|
||||||
import { WebSocketLink } from "@apollo/client/link/ws";
|
|
||||||
import {
|
import {
|
||||||
ApolloClient,
|
ApolloClient,
|
||||||
InMemoryCache,
|
InMemoryCache,
|
||||||
@@ -8,8 +6,9 @@ import {
|
|||||||
HttpLink,
|
HttpLink,
|
||||||
split,
|
split,
|
||||||
} from "@apollo/client";
|
} from "@apollo/client";
|
||||||
|
import { WebSocketLink } from "@apollo/client/link/ws";
|
||||||
|
import { onError } from "@apollo/client/link/error";
|
||||||
import { getMainDefinition } from "@apollo/client/utilities";
|
import { getMainDefinition } from "@apollo/client/utilities";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
propertyVectorFragment,
|
propertyVectorFragment,
|
||||||
vectorFragment,
|
vectorFragment,
|
||||||
@@ -17,12 +16,10 @@ import {
|
|||||||
} from "./graphql/fragment";
|
} from "./graphql/fragment";
|
||||||
import { isConnectedQuery } from "./graphql/query";
|
import { isConnectedQuery } from "./graphql/query";
|
||||||
|
|
||||||
// Create an http link:
|
|
||||||
const httpLink = new HttpLink({
|
const httpLink = new HttpLink({
|
||||||
uri: "/graphql",
|
uri: "/graphql",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a WebSocket link:
|
|
||||||
const wsLink = new WebSocketLink({
|
const wsLink = new WebSocketLink({
|
||||||
uri: `ws://${window.location.host}/graphql`,
|
uri: `ws://${window.location.host}/graphql`,
|
||||||
options: {
|
options: {
|
||||||
@@ -68,15 +65,17 @@ const client = new ApolloClient({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
Device: {
|
||||||
}),
|
fields: {
|
||||||
resolvers: {
|
messages: {
|
||||||
Device: {
|
read(val = []) {
|
||||||
messages() {
|
return val;
|
||||||
return [];
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const CONNECTED = gql`
|
const CONNECTED = gql`
|
||||||
@@ -214,6 +213,36 @@ client
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const REMOVE_PROPERTY = gql`
|
||||||
|
subscription removeProperty {
|
||||||
|
removeProperty {
|
||||||
|
id
|
||||||
|
device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
client
|
||||||
|
.subscribe({
|
||||||
|
query: REMOVE_PROPERTY,
|
||||||
|
})
|
||||||
|
.subscribe(({ data }) => {
|
||||||
|
const res = client.readQuery({
|
||||||
|
query: GETDEVICE,
|
||||||
|
variables: { id: data.removeProperty.device },
|
||||||
|
});
|
||||||
|
client.writeQuery({
|
||||||
|
query: GETDEVICE,
|
||||||
|
variables: { id: res.device.id },
|
||||||
|
data: {
|
||||||
|
device: {
|
||||||
|
...res.device,
|
||||||
|
properties: res.device.properties.filter(p => p.name !== data.removeProperty.id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const NEW_VALUE = gql`
|
const NEW_VALUE = gql`
|
||||||
subscription newValue {
|
subscription newValue {
|
||||||
newValue {
|
newValue {
|
||||||
|
|||||||
Reference in New Issue
Block a user