Last active
January 11, 2017 14:37
-
-
Save Thunderbird7/3ccc73b9765233853b6bfc93d3679fc0 to your computer and use it in GitHub Desktop.
Apollo Query Redux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apollo Client query in Action... | |
import apolloClient from './client' | |
import gql from 'graphql-tag' | |
const client = apolloClient() | |
export function getMyProfile() { | |
const myQuery = { | |
query: gql` | |
query { | |
profile { | |
id | |
firstname | |
lastname | |
positions | |
} | |
} | |
`, | |
forceFetch: true | |
} | |
return dispatch => { | |
client.query(myQuery) | |
.then((gqlResult) => { | |
const { errors, data } = gqlResult | |
if (data) { | |
console.log(data.profile) | |
dispatch({type: 'GET_PROFILE_SUCCESS', payload: data.profile}) | |
} | |
if (errors) { | |
console.log('got some GraphQL execution errors', errors); | |
dispatch({type: 'GET_PROFILE_FAILURE', error: errors}) | |
} | |
}).catch((e) => { | |
console.error(e) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment