@@ -6,8 +6,8 @@ import { createHttpLink } from 'apollo-link-http'
6
6
import { getMainDefinition } from 'apollo-utilities'
7
7
import { setContext } from 'apollo-link-context'
8
8
import { getAuthToken } from 'auth0-helpers'
9
- import { withClientState } from 'apollo-link-state'
10
9
import { RestLink } from 'apollo-link-rest'
10
+ import gql from 'graphql-tag'
11
11
12
12
import { errorLink } from './errorLink'
13
13
@@ -50,6 +50,12 @@ const networkLink = split(
50
50
authedHttpLink
51
51
)
52
52
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
+
53
59
export const cache = new InMemoryCache ( {
54
60
cacheRedirects : {
55
61
Query : {
@@ -59,19 +65,19 @@ export const cache = new InMemoryCache({
59
65
}
60
66
} )
61
67
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,
63
79
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,
75
81
resolvers : {
76
82
Section : {
77
83
scrollY : ( ) => 0
@@ -86,10 +92,14 @@ const stateLink = withClientState({
86
92
}
87
93
} )
88
94
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
+ }
92
102
93
- const link = ApolloLink . from ( [ errorLink , stateLink , restLink , networkLink ] )
103
+ initializeCache ( )
94
104
95
- export const apollo = new ApolloClient ( { link , cache } )
105
+ apollo . onResetStore ( initializeCache )
0 commit comments