Start upgrading to astraw-server
This commit is contained in:
+71
-8
@@ -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;
|
||||
|
||||
@@ -69,7 +69,7 @@ const Device = ({ device, messages, onMessagesClosed }) => {
|
||||
width={size}
|
||||
>
|
||||
<Box direction="row" justify="end" fill="horizontal">
|
||||
<Button
|
||||
<Button
|
||||
icon={<Trash />}
|
||||
onClick={() => {
|
||||
client.writeFragment({
|
||||
|
||||
+3
-3
@@ -22,8 +22,8 @@ const GETDEVICES = gql`
|
||||
}
|
||||
}
|
||||
|
||||
${deviceInfoFragment}
|
||||
${propertyVectorFragment}
|
||||
${deviceInfoFragment}
|
||||
`;
|
||||
|
||||
const CONNECT = gql`
|
||||
@@ -50,7 +50,7 @@ const useIndiState = () => {
|
||||
};
|
||||
|
||||
const Devices = () => {
|
||||
const connected = useIndiState();
|
||||
//const connected = useIndiState();
|
||||
const { data } = useQuery(GETDEVICES);
|
||||
const [connect] = useMutation(CONNECT);
|
||||
const [disconnect] = useMutation(DISCONNECT);
|
||||
@@ -71,7 +71,7 @@ const Devices = () => {
|
||||
<Box direction="row" gap="xsmall">
|
||||
<Button label="Capture" onClick={() => {}} />
|
||||
<Button label="INDI panel" onClick={() => {}} />
|
||||
{!connected ? (
|
||||
{true ? (
|
||||
<Button
|
||||
label="Connect"
|
||||
onClick={() => {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import gql from "graphql-tag";
|
||||
|
||||
const deviceInfoFragment = gql`
|
||||
fragment DeviceInfo on Device {
|
||||
fragment DeviceInfo on IndiDevice {
|
||||
name
|
||||
connected
|
||||
drivers
|
||||
}
|
||||
`;
|
||||
|
||||
const vectorFragment = gql`
|
||||
fragment VectorData on Vector {
|
||||
fragment VectorData on IndiVector {
|
||||
name
|
||||
label
|
||||
group
|
||||
@@ -53,7 +52,7 @@ const vectorFragment = gql`
|
||||
`;
|
||||
|
||||
const propertyVectorFragment = gql`
|
||||
fragment PropertyVector on Property {
|
||||
fragment PropertyVector on IndiProperty {
|
||||
vector {
|
||||
id
|
||||
...VectorData
|
||||
|
||||
Reference in New Issue
Block a user