-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.ts
50 lines (43 loc) · 1.25 KB
/
main.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
import type { ApolloClientElement } from '@apollo-elements/components/apollo-client';
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client/core";
import '@apollo-elements/components/apollo-client';
import '@power-elements/json-viewer/json-viewer';
import './component';
/*****************
* APOLLO CLIENT *
*****************/
async function setupClient(element: ApolloClientElement) {
// Do any async work here, like fetching a token;
await Promise.resolve();
element.client = new ApolloClient({
link: new HttpLink({
uri: 'https://api.spacex.land/graphql'
}),
cache: new InMemoryCache({
typePolicies: {
Launch: {
fields: {
/**
* Define `selected` on launch
*/
selected: {
read(prev) {
return prev ?? false;
},
merge(_, next) {
return next;
},
},
},
}
}
}),
});
}
async function main() {
document.getElementById('dependencies').textContent = `DEPENDENCIES`;
// You can set up multiple apollo clients here and assign them based on ID or data-attrs
document.querySelectorAll('apollo-client')
.forEach(setupClient)
}
main();