Browse Source

Start upgrading to astraw-server

master
Anthony Hinsinger 4 years ago
parent
commit
25717b1d85
  1. 79
      src/apolloclient.js
  2. 2
      src/components/indi/device.js
  3. 6
      src/devices.js
  4. 7
      src/graphql/fragment.js

79
src/apolloclient.js

@ -17,11 +17,11 @@ import { @@ -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({ @@ -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({ @@ -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 @@ -315,5 +378,5 @@ client
},
});
});
*/
export default client;

2
src/components/indi/device.js

@ -69,7 +69,7 @@ const Device = ({ device, messages, onMessagesClosed }) => { @@ -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({

6
src/devices.js

@ -22,8 +22,8 @@ const GETDEVICES = gql` @@ -22,8 +22,8 @@ const GETDEVICES = gql`
}
}
${deviceInfoFragment}
${propertyVectorFragment}
${deviceInfoFragment}
`;
const CONNECT = gql`
@ -50,7 +50,7 @@ const useIndiState = () => { @@ -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 = () => { @@ -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={() => {

7
src/graphql/fragment.js

@ -1,15 +1,14 @@ @@ -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` @@ -53,7 +52,7 @@ const vectorFragment = gql`
`;
const propertyVectorFragment = gql`
fragment PropertyVector on Property {
fragment PropertyVector on IndiProperty {
vector {
id
...VectorData

Loading…
Cancel
Save