-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
119 lines (113 loc) · 3.46 KB
/
index.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!--
* Copyright (c) 2021 GraphQL Contributors
* All rights reserved.
*
* This code is licensed under the MIT license.
* Use it however you wish.
-->
<!DOCTYPE html>
<html>
<head>
<style>
#graphiql {
height: 100vh;
}
</style>
<!--
This GraphiQL example depends on Promise and AsyncIterator, which are available in
modern browsers, but can be "polyfilled" for older browsers.
GraphiQL itself depends on React DOM.
If you do not want to rely on a CDN, you can host these files locally or
include them directly in your favored resource bunder.
-->
<script SameSite="None; Secure" src="https://static.landbot.io/landbot-3/landbot-3.0.0.js"></script>
<script
crossorigin
src="https://unpkg.com/react@16/umd/react.development.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"
></script>
<!--
These two files can be found in the npm module, however you may wish to
copy them directly into your environment, or perhaps include them in your
favored resource bundler.
-->
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
</head>
<body>
<div id="graphiql">Loading...</div>
<script
src="https://unpkg.com/graphiql/graphiql.min.js"
type="application/javascript"
></script>
<script
src="https://unpkg.com/graphql-ws/umd/graphql-ws.min.js"
type="application/javascript"
></script>
<script>
const wsClient = graphqlWs.createClient({
url: "ws://localhost:3000/graphql",
lazy: false, // connect as soon as the page opens
});
function subscribe(payload) {
let deferred = null;
const pending = [];
let throwMe = null,
done = false;
const dispose = wsClient.subscribe(payload, {
next: (data) => {
pending.push(data);
deferred?.resolve(false);
},
error: (err) => {
if (err instanceof Error) {
throwMe = err;
} else if (err instanceof CloseEvent) {
throwMe = new Error(
`Socket closed with event ${err.code} ${
err.reason || ""
}`.trim()
);
} else {
// GraphQLError[]
throwMe = new Error(err.map(({ message }) => message).join(", "));
}
deferred?.reject(throwMe);
},
complete: () => {
done = true;
deferred?.resolve(true);
},
});
return {
[Symbol.asyncIterator]() {
return this;
},
async next() {
if (done) return { done: true, value: undefined };
if (throwMe) throw throwMe;
if (pending.length) return { value: pending.shift() };
return (await new Promise(
(resolve, reject) => (deferred = { resolve, reject })
))
? { done: true, value: undefined }
: { value: pending.shift() };
},
async return() {
dispose();
return { done: true, value: undefined };
},
};
}
ReactDOM.render(
React.createElement(GraphiQL, {
fetcher: subscribe,
defaultVariableEditorOpen: true,
}),
document.getElementById("graphiql")
);
</script>
</body>
</html>