const fetchSubjectList = dispatch => { dispatch(subjectListIsLoading()); fetchAllSubjects() .then(result => { if (result.data) { dispatch(subjectListIsFetched(result.data.subjects)); } if (result.errors) { dispatch(subjectListFetchError(result.errors)); } }) .catch(error => { dispatch(subjectListFetchError([error.message])); }); }
graphql(forget, { props: ({ mutate }) => ({ forget: (email) => mutate({ variables: { email }, update: (proxy, { data }) => { // Read the data from our cache for this query. let cached = proxy.readQuery({ query: userProfile }) // Errors cached.errors = data.errors // User cached.user = cached.user || { _id: null, name: null, status: null, __typename: 'User' } cached.user.status = data.forget.status // Write our data back to the cache. proxy.writeQuery({ query: userProfile, data: cached }) } }) }) })(Forget)
graphql(signup, { props: ({ mutate }) => ({ signup: (email, password) => mutate({ variables: { email, password }, update: (proxy, { data }) => { // Keep session data.signup && persist.willSetSessionToken(data.signup.sessionToken) // Read the data from our cache for this query. let cached = proxy.readQuery({ query: userProfile }) // Errors cached.errors = data.errors // User cached.user = data.signup ? data.signup.user : { _id: null, name: null, status: null, __typename: 'User' } // Authen cached.authen = { isLoggedIn: data.signup ? data.signup.isLoggedIn : null, sessionToken: data.signup ? data.signup.sessionToken : null, __typename: 'Authen' } // Write our data back to the cache. proxy.writeQuery({ query: userProfile, data: cached }) } }) }) })(SignUp)
graphql(logout, { props: ({ mutate }) => ({ logout: () => mutate({ update: (proxy, { data }) => { // Clear session persist.willRemoveSessionToken() // Read the data from our cache for this query. let cached = proxy.readQuery({ query: userProfile }) // Errors cached.errors = data.errors // User cached.user = data.logout.user ? data.logout.user : { _id: null, name: null, status: null, __typename: 'User' } // Authen cached.authen = { isLoggedIn: data.logout.isLoggedIn, sessionToken: data.logout.sessionToken, __typename: 'Authen' } // Write our data back to the cache. proxy.writeQuery({ query: userProfile, data: cached }) } }) }) })(Logout)
const initiatefetchAllFaculties = dispatch => { dispatch(facultyListIsLoading()); return fetchAllFaculties() .then(result => { if (result.data) { dispatch(facultyListIsFetched(result.data.faculties)); } if (result.errors) { dispatch(facultyListFetchError(result.errors)); } }) .catch(error => { dispatch(facultyListFetchError([error.message])); }); }
cached.errors = data.errors
graphql(loginWithFacebook, { props: ({ mutate }) => ({ loginWithFacebook: (deviceInfo, accessToken) => mutate({ variables: { deviceInfo, accessToken }, update: (proxy, { data }) => { // Keep session persist.willSetSessionToken(data.loginWithFacebook.sessionToken) // Read the data from our cache for this query. let cached = proxy.readQuery({ query: userProfile }) // Errors cached.errors = data.errors // User cached.user = data.loginWithFacebook.user // Authen cached.authen = { isLoggedIn: data.loginWithFacebook.isLoggedIn, sessionToken: data.loginWithFacebook.sessionToken, __typename: 'Authen' } // Write our data back to the cache. proxy.writeQuery({ query: userProfile, data: cached }) } }) }) })
const mapDispatchToProps = dispatch => ({ fetchData() { dispatch(myProfileIsLoading()); return fetchMyProfile() .then(result => { if (result.data) { dispatch(myProfileIsFetched(result.data.myProfile)); } if (result.errors) { dispatch(myProfileFetchError(result.errors)); } }) .catch(error => { dispatch(myProfileFetchError([error.message])); }); }, })
const initiatefetchAllFaculties = dispatch => { dispatch(facultyListIsLoading()); return fetchAllFaculties() .then(result => { if (result.data) { dispatch(facultyListIsFetched(result.data.faculties)); } if (result.errors) { dispatch(facultyListFetchError(result.errors)); } }) .catch(error => { dispatch(facultyListFetchError([error.message])); }); }
const fetchSubjectList = dispatch => { dispatch(subjectListIsLoading()); fetchAllSubjects() .then(result => { if (result.data) { dispatch(subjectListIsFetched(result.data.subjects)); } if (result.errors) { dispatch(subjectListFetchError(result.errors)); } }) .catch(error => { dispatch(subjectListFetchError([error.message])); }); }
const mapDispatchToProps = dispatch => ({ fetchData() { dispatch(myProfileIsLoading()); return fetchMyProfile() .then(result => { if (result.data) { dispatch(myProfileIsFetched(result.data.myProfile)); } if (result.errors) { dispatch(myProfileFetchError(result.errors)); } }) .catch(error => { dispatch(myProfileFetchError([error.message])); }); }, })