Skip to content

Commit 2c31d18

Browse files
committed
Update to Apollo 2.5
1 parent 881daea commit 2c31d18

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

src/lib/apollo.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { createHttpLink } from 'apollo-link-http'
66
import { getMainDefinition } from 'apollo-utilities'
77
import { setContext } from 'apollo-link-context'
88
import { getAuthToken } from 'auth0-helpers'
9-
import { withClientState } from 'apollo-link-state'
109
import { RestLink } from 'apollo-link-rest'
10+
import gql from 'graphql-tag'
1111

1212
import { errorLink } from './errorLink'
1313

@@ -50,6 +50,12 @@ const networkLink = split(
5050
authedHttpLink
5151
)
5252

53+
const restLink = new RestLink({
54+
uri: 'https://api.openweathermap.org/data/2.5/'
55+
})
56+
57+
const link = ApolloLink.from([errorLink, restLink, networkLink])
58+
5359
export const cache = new InMemoryCache({
5460
cacheRedirects: {
5561
Query: {
@@ -59,19 +65,19 @@ export const cache = new InMemoryCache({
5965
}
6066
})
6167

62-
const stateLink = withClientState({
68+
const typeDefs = gql`
69+
type Query {
70+
loginInProgress: Boolean
71+
}
72+
type Mutation {
73+
setSectionScroll(id: String!, scrollY: Int!): Boolean
74+
}
75+
`
76+
77+
export const apollo = new ApolloClient({
78+
link,
6379
cache,
64-
defaults: {
65-
loginInProgress: false
66-
},
67-
typeDefs: `
68-
type Query {
69-
loginInProgress: Boolean
70-
}
71-
type Mutation {
72-
setSectionScroll(id: String!, scrollY: Int!): Boolean
73-
}
74-
`,
80+
typeDefs,
7581
resolvers: {
7682
Section: {
7783
scrollY: () => 0
@@ -86,10 +92,14 @@ const stateLink = withClientState({
8692
}
8793
})
8894

89-
const restLink = new RestLink({
90-
uri: 'https://api.openweathermap.org/data/2.5/'
91-
})
95+
const initializeCache = () => {
96+
cache.writeData({
97+
data: {
98+
loginInProgress: false
99+
}
100+
})
101+
}
92102

93-
const link = ApolloLink.from([errorLink, stateLink, restLink, networkLink])
103+
initializeCache()
94104

95-
export const apollo = new ApolloClient({ link, cache })
105+
apollo.onResetStore(initializeCache)

0 commit comments

Comments
 (0)