|
|
|
@ -17,11 +17,11 @@ import { |
|
|
|
import { isConnectedQuery } from "./graphql/query"; |
|
|
|
import { isConnectedQuery } from "./graphql/query"; |
|
|
|
|
|
|
|
|
|
|
|
const httpLink = new HttpLink({ |
|
|
|
const httpLink = new HttpLink({ |
|
|
|
uri: "/graphql", |
|
|
|
uri: "http://localhost:8081/", |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const wsLink = new WebSocketLink({ |
|
|
|
const wsLink = new WebSocketLink({ |
|
|
|
uri: `ws://${window.location.host}/graphql`, |
|
|
|
uri: `ws://localhost:8081`, |
|
|
|
options: { |
|
|
|
options: { |
|
|
|
reconnect: true, |
|
|
|
reconnect: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
@ -55,17 +55,17 @@ const client = new ApolloClient({ |
|
|
|
]), |
|
|
|
]), |
|
|
|
cache: new InMemoryCache({ |
|
|
|
cache: new InMemoryCache({ |
|
|
|
possibleTypes: { |
|
|
|
possibleTypes: { |
|
|
|
Vector: ["NumberVector", "SwitchVector", "TextVector", "LightVector"], |
|
|
|
IndiVector: ["NumberVector", "SwitchVector", "TextVector", "LightVector"], |
|
|
|
}, |
|
|
|
}, |
|
|
|
typePolicies: { |
|
|
|
typePolicies: { |
|
|
|
Query: { |
|
|
|
/*Query: { |
|
|
|
fields: { |
|
|
|
fields: { |
|
|
|
device(_, { toReference, args }) { |
|
|
|
device(_, { toReference, args }) { |
|
|
|
return toReference({ __typename: "Device", id: args.id }); |
|
|
|
return toReference({ __typename: "IndiDevice", id: args.id }); |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
},*/ |
|
|
|
Device: { |
|
|
|
IndiDevice: { |
|
|
|
fields: { |
|
|
|
fields: { |
|
|
|
messages: { |
|
|
|
messages: { |
|
|
|
read(val = []) { |
|
|
|
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` |
|
|
|
const CONNECTED = gql` |
|
|
|
subscription connected { |
|
|
|
subscription connected { |
|
|
|
connected |
|
|
|
connected |
|
|
|
@ -315,5 +378,5 @@ client |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
*/ |
|
|
|
export default client; |
|
|
|
export default client; |
|
|
|
|