-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapollo-client.ts
41 lines (36 loc) · 1.1 KB
/
apollo-client.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
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { RestLink } from "apollo-link-rest";
import { RetryLink } from "@apollo/client/link/retry";
const theGraphLink = new HttpLink({
uri:
process.env.NEXT_PUBLIC_SUBGRAPH_URL ??
"https://api.thegraph.com/subgraphs/name/treppers/genesisproject"
});
const apiLink = new RestLink({
uri: "/api",
responseTransformer: (response) => response.json()
});
const theNFTxLink = new HttpLink({
uri: "https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v2"
});
const theSushiSwapLink = new HttpLink({
uri: "https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork"
});
const dispatcherLink = new RetryLink().split(
(operation) => operation.getContext()?.restful,
apiLink,
new RetryLink().split(
(operation) => operation.getContext()?.nftx,
theNFTxLink,
new RetryLink().split(
(operation) => operation.getContext()?.sushiswap,
theSushiSwapLink,
theGraphLink
)
)
);
const client = new ApolloClient({
cache: new InMemoryCache(),
link: dispatcherLink
});
export default client;