Skip to content

Instantly share code, notes, and snippets.

@Thunderbird7
Last active January 11, 2017 14:37
Show Gist options
  • Save Thunderbird7/3ccc73b9765233853b6bfc93d3679fc0 to your computer and use it in GitHub Desktop.
Save Thunderbird7/3ccc73b9765233853b6bfc93d3679fc0 to your computer and use it in GitHub Desktop.
Apollo Query Redux
// 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
email
}
}
`,
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