forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
86 lines (79 loc) · 1.95 KB
/
client.js
File metadata and controls
86 lines (79 loc) · 1.95 KB
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
import 'isomorphic-unfetch'
import {
ApolloClient,
createHttpLink,
InMemoryCache,
makeVar,
} from '@apollo/client'
import { relayStylePagination } from '@apollo/client/utilities'
import { setContext } from '@apollo/client/link/context'
import { i18n } from '@lingui/core'
export function createCache() {
return new InMemoryCache({
typePolicies: {
Query: {
fields: {
findMyDomains: relayStylePagination(),
findMyDmarcSummaries: relayStylePagination(),
findMyOrganizations: relayStylePagination(['isAdmin']),
},
},
Organization: {
fields: {
domains: relayStylePagination(),
affiliations: relayStylePagination(),
},
},
Period: {
keyFields: ['month', 'year', 'domain'],
fields: {
detailTables: {
merge(existing = {}, incoming) {
return { ...existing, ...incoming }
},
},
},
},
DetailTables: {
fields: {
dkimFailure: relayStylePagination(),
dmarcFailure: relayStylePagination(),
spfFailure: relayStylePagination(),
fullPass: relayStylePagination(),
},
},
Domain: {
fields: {
status: {
merge(existing, incoming, { mergeObjects }) {
return mergeObjects(existing, incoming)
},
},
},
},
},
})
}
export const cache = createCache()
export const currentUserVar = makeVar({
jwt: null,
tfaSendMethod: null,
userName: null,
})
const httpLink = createHttpLink({
uri: '/graphql',
})
const headersLink = setContext((_, { headers }) => {
const language = i18n.locale
return {
headers: {
...headers,
...(currentUserVar().jwt && { authorization: currentUserVar().jwt }),
'Accept-Language': language,
},
}
})
export const client = new ApolloClient({
link: headersLink.concat(httpLink),
cache,
})