1
1
import React from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import wrapDisplayName from 'recompose/wrapDisplayName'
4
- import { graphql } from 'react-apollo'
4
+ import { graphql , withApollo } from 'react-apollo'
5
+ import { ApolloClient } from 'apollo-client'
5
6
import gql from 'graphql-tag'
6
7
import auth0 from 'auth0-js'
7
8
import { initAuthHelpers , login , logout } from 'auth0-helpers'
@@ -42,10 +43,9 @@ const USER_QUERY = gql`
42
43
`
43
44
44
45
const withUser = graphql ( USER_QUERY , {
45
- props : ( { ownProps, data : { currentUser, loading, refetch } } ) => ( {
46
+ props : ( { ownProps, data : { currentUser, loading } } ) => ( {
46
47
currentUser,
47
48
loading,
48
- refetch,
49
49
ownProps
50
50
} )
51
51
} )
@@ -65,15 +65,15 @@ function withAuth(BaseComponent) {
65
65
login ( {
66
66
onCompleted : ( e , t ) => {
67
67
e && console . log ( e )
68
- this . props . refetch ( )
68
+ this . props . client . reFetchObservableQueries ( )
69
69
this . setState ( { loggingIn : false } )
70
70
}
71
71
} )
72
72
}
73
73
74
74
logout = ( ) => {
75
75
logout ( )
76
- this . props . refetch ( )
76
+ this . props . client . resetStore ( )
77
77
}
78
78
79
79
render ( ) {
@@ -100,11 +100,12 @@ function withAuth(BaseComponent) {
100
100
photo : PropTypes . string . isRequired ,
101
101
hasPurchased : PropTypes . string
102
102
} ) ,
103
- loading : PropTypes . bool . isRequired
103
+ loading : PropTypes . bool . isRequired ,
104
+ client : PropTypes . instanceOf ( ApolloClient ) . isRequired
104
105
}
105
106
106
107
WithAuthWrapper . displayName = wrapDisplayName ( BaseComponent , 'withAuth' )
107
- return withUser ( WithAuthWrapper )
108
+ return withApollo ( withUser ( WithAuthWrapper ) )
108
109
}
109
110
110
111
export default withAuth
0 commit comments