Skip to content

Commit a0533b6

Browse files
committed
Update to Apollo 2.5
1 parent a32be98 commit a0533b6

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,21 +50,27 @@ 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
const cache = new InMemoryCache()
5460

55-
const stateLink = withClientState({
61+
const typeDefs = gql`
62+
type Query {
63+
loginInProgress: Boolean
64+
}
65+
type Mutation {
66+
setSectionScroll(id: String!, scrollY: Int!): Boolean
67+
}
68+
`
69+
70+
export const apollo = new ApolloClient({
71+
link,
5672
cache,
57-
defaults: {
58-
loginInProgress: false
59-
},
60-
typeDefs: `
61-
type Query {
62-
loginInProgress: Boolean
63-
}
64-
type Mutation {
65-
setSectionScroll(id: String!, scrollY: Int!): Boolean
66-
}
67-
`,
73+
typeDefs,
6874
resolvers: {
6975
Section: {
7076
scrollY: () => 0
@@ -79,10 +85,14 @@ const stateLink = withClientState({
7985
}
8086
})
8187

82-
const restLink = new RestLink({
83-
uri: 'https://api.openweathermap.org/data/2.5/'
84-
})
88+
const initializeCache = () => {
89+
cache.writeData({
90+
data: {
91+
loginInProgress: false
92+
}
93+
})
94+
}
8595

86-
const link = ApolloLink.from([errorLink, stateLink, restLink, networkLink])
96+
initializeCache()
8797

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

0 commit comments

Comments
 (0)