diff --git a/src/apolloclient.js b/src/apolloclient.js index e8dcec1..fa5f3db 100644 --- a/src/apolloclient.js +++ b/src/apolloclient.js @@ -17,11 +17,11 @@ import { import { isConnectedQuery } from "./graphql/query"; const httpLink = new HttpLink({ - uri: "/graphql", + uri: "http://localhost:8081/", }); const wsLink = new WebSocketLink({ - uri: `ws://${window.location.host}/graphql`, + uri: `ws://localhost:8081`, options: { reconnect: true, }, @@ -55,17 +55,17 @@ const client = new ApolloClient({ ]), cache: new InMemoryCache({ possibleTypes: { - Vector: ["NumberVector", "SwitchVector", "TextVector", "LightVector"], + IndiVector: ["NumberVector", "SwitchVector", "TextVector", "LightVector"], }, typePolicies: { - Query: { + /*Query: { fields: { device(_, { toReference, args }) { - return toReference({ __typename: "Device", id: args.id }); + return toReference({ __typename: "IndiDevice", id: args.id }); }, }, - }, - Device: { + },*/ + IndiDevice: { fields: { messages: { read(val = []) { @@ -78,6 +78,69 @@ const client = new ApolloClient({ }), }); +const GETDEVICE = gql` + query device($id: String!) { + device(id: $id) { + id + ...DeviceInfo + messages @client + properties { + id + name + ...PropertyVector + } + } + } + + ${deviceInfoFragment} + ${propertyVectorFragment} +`; + +const NEW_PROPERTY = gql` + subscription newProperty { + newIndiProp { + id + name + device { + id + } + ...PropertyVector + } + } + + ${propertyVectorFragment} +`; + +client + .subscribe({ + query: NEW_PROPERTY, + }) + .subscribe(({ data }) => { + const res = client.readQuery({ + query: GETDEVICE, + variables: { id: data.newIndiProp.device.id }, + }); + client.writeQuery({ + query: GETDEVICE, + variables: { id: res.device.id }, + data: { + device: { + ...res.device, + /*drivers: + data.newProperty.name === "DRIVER_INFO" + ? data.newProperty.vector.values[3].text + : res.device.drivers, + connected: + data.newProperty.name === "CONNECTION" + ? data.newProperty.vector.values[0].switch + : res.device.connected,*/ + properties: [...res.device.properties, data.newIndiProp], + }, + }, + }); + }); + +/* const CONNECTED = gql` subscription connected { connected @@ -315,5 +378,5 @@ client }, }); }); - +*/ export default client; diff --git a/src/components/indi/device.js b/src/components/indi/device.js index c841e9b..95e809c 100644 --- a/src/components/indi/device.js +++ b/src/components/indi/device.js @@ -69,7 +69,7 @@ const Device = ({ device, messages, onMessagesClosed }) => { width={size} > -