-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathstart-ac.mjs
executable file
·60 lines (55 loc) · 1.45 KB
/
start-ac.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
// for testing, start a few of these, e.g. with
// while true; do echo "foo\nbar\nbaz" | parallel ./start-ac.mjs; sleep 1; done
import { connectApolloClientToVSCodeDevTools } from "@apollo/client-devtools-vscode";
import WebSocket from "ws";
import { ApolloClient, InMemoryCache } from "@apollo/client/core/index.js";
import { MockLink } from "@apollo/client/testing/core/index.js";
import gql from "graphql-tag";
globalThis.WebSocket ||= WebSocket;
const helloWorld = gql`
query {
hello
}
`;
const link = new MockLink([
{
request: { query: helloWorld },
result: { data: { hello: "world" } },
maxUsageCount: 1000,
},
{
request: {
query: gql`
query {
hi
}
`,
},
result: { data: { hi: "universe" } },
maxUsageCount: 1000,
},
]);
const client = new ApolloClient({
link,
cache: new InMemoryCache(),
devtools: { name: process.argv[2] },
});
client.watchQuery({ query: helloWorld }).subscribe({ next() {} });
const { connectedPromise, disconnect, onCleanup } =
connectApolloClientToVSCodeDevTools(
client,
"ws://localhost:7095", // nosemgrep
);
console.log("connecting...");
onCleanup((reason) =>
console.log(
"disconnected",
reason,
/* referencing client here to prevent it from getting garbage connected */ client.version,
),
);
connectedPromise.then(() => {
console.log("connected");
// setTimeout(unregister, 5000, "USERLAND_TIMEOUT");
});