-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.ts
53 lines (43 loc) · 1.25 KB
/
index.ts
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
// Run with: yarn bench
import ws from "ws";
import { WebSocketLink } from "apollo-link-ws";
import { SubscriptionClient } from "subscriptions-transport-ws";
import { InMemoryCache } from "apollo-cache-inmemory";
import ApolloClient from "apollo-client";
import { gql } from "apollo-server";
const GRAPHQL_ENDPOINT = "localhost:4000/graphql";
const client = new SubscriptionClient(`ws://${GRAPHQL_ENDPOINT}`, { reconnect: true }, ws);
const link = new WebSocketLink(client);
const cache = new InMemoryCache();
const apolloClient = new ApolloClient({ link, cache });
console.log("Connecting to GraphQL...");
const SUBSCRIPTION = gql`
subscription account($args: EventInput!) {
account(args: $args) {
id
values {
sequenceNumber
thresholds {
low
medium
high
}
}
}
}`;
client.onError((error) => console.log("An error occured!", error.target));
let eventCount = 0;
for (let n = 0; n < 7000; n++) {
apolloClient.subscribe({
fetchPolicy: "network-only",
query: SUBSCRIPTION,
variables: {
args: {}
}
}).subscribe({
next (data: any) {
eventCount += 1;
}
});
}
setTimeout(() => { console.log("Finished.", eventCount, "events received."); }, 10000);