@@ -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,21 +50,27 @@ 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
const cache = new InMemoryCache ( )
54
60
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,
56
72
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,
68
74
resolvers : {
69
75
Section : {
70
76
scrollY : ( ) => 0
@@ -79,10 +85,14 @@ const stateLink = withClientState({
79
85
}
80
86
} )
81
87
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
+ }
85
95
86
- const link = ApolloLink . from ( [ errorLink , stateLink , restLink , networkLink ] )
96
+ initializeCache ( )
87
97
88
- export const apollo = new ApolloClient ( { link , cache } )
98
+ apollo . onResetStore ( initializeCache )
0 commit comments