File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { ApolloClient } from 'apollo-client'
2
2
import { InMemoryCache } from 'apollo-cache-inmemory'
3
- import { split } from 'apollo-link'
3
+ import { ApolloLink , split } from 'apollo-link'
4
4
import { WebSocketLink } from 'apollo-link-ws'
5
5
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'
9
10
10
11
import { errorLink } from './errorLink'
11
12
@@ -48,8 +49,16 @@ const networkLink = split(
48
49
authedHttpLink
49
50
)
50
51
51
- const link = errorLink . concat ( networkLink )
52
-
53
52
const cache = new InMemoryCache ( )
54
53
54
+ const stateLink = withClientState ( {
55
+ cache,
56
+ defaults : {
57
+ loginInProgress : false
58
+ } ,
59
+ resolvers : { }
60
+ } )
61
+
62
+ const link = ApolloLink . from ( [ errorLink , stateLink , networkLink ] )
63
+
55
64
export const apollo = new ApolloClient ( { link, cache } )
Original file line number Diff line number Diff line change @@ -30,8 +30,12 @@ initAuthHelpers({
30
30
} )
31
31
32
32
export const login = ( ) => {
33
+ apollo . writeData ( { data : { loginInProgress : true } } )
34
+
33
35
auth0Login ( {
34
36
onCompleted : e => {
37
+ apollo . writeData ( { data : { loginInProgress : false } } )
38
+
35
39
if ( e ) {
36
40
console . error ( e )
37
41
return
Original file line number Diff line number Diff line change @@ -14,12 +14,13 @@ export const USER_QUERY = gql`
14
14
id
15
15
}
16
16
}
17
+ loginInProgress @client
17
18
}
18
19
`
19
20
20
21
export const withUser = graphql ( USER_QUERY , {
21
- props : ( { data : { currentUser, loading } } ) => ( {
22
+ props : ( { data : { currentUser, loading, loginInProgress } } ) => ( {
22
23
user : currentUser ,
23
- loggingIn : loading
24
+ loggingIn : loading || loginInProgress
24
25
} )
25
26
} )
You can’t perform that action at this time.
0 commit comments