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