-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
39 lines (35 loc) · 758 Bytes
/
client.js
File metadata and controls
39 lines (35 loc) · 758 Bytes
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
import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
const httpLink = createHttpLink({
uri: "https://api.github.com/graphql",
});
const authLink = setContext((_, { headers }) => {
const token = process.env.GITHUB_TOKEN;
return {
headers: {
...headers,
authorization: `Bearer ${token}`,
},
};
});
const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
repository: {
merge(existing = {}, incoming) {
// Define your custom merge logic here
return {
...existing,
...incoming,
};
},
},
},
},
},
});
export const client = new ApolloClient({
cache,
link: authLink.concat(httpLink),
});