apollo-tote
apollo-tote copied to clipboard
👜 A declarative approach to handling Apollo GraphQL queries in React
apollo-tote
👜 A declarative approach to handling Apollo queries in React
Installation
yarn add apollo-tote
or
npm install --save apollo-tote
Usage Examples
- Fetch
current userquery. If an api token exists but is no longer valid (ie: cleared database), log user out.
<ApolloTote
query={`
query {
user {
id
}
}
`}
test={data => !!(data && data.user && data.user.id)}
handleFail={() => Store.dispatch({ type: 'LOG_OUT' })}
handlePass={() => Store.dispatch({ type: 'LOG_IN' })}
renderError={error => this._renderError(error)}
renderLoading={() => <App.Loading />}
render={() => <App />}
/>
- Render loading component until data comes back.
<ApolloTote
query={`
query {
user {
imageUrl
}
}
`}
renderLoading={() => <Avatar.Loading />}
render={value => <Avatar imageUrl={value.user.imageUrl} />}
/>
PropTypes
skip: Boolean - Should we skip over query and just render?query: String - Your graphql queryvariables: String - Graphql query variablestest: Function (Optional) - helper to handle a successful query's responsehandlePass: Function (Optional) - a function to render a successfultesthandleFail: Function (Optional) - a function to render a failedtestrenderError: Function - error functionrenderLoading: Function - loading functionrender: Function - a function that renders the result of your query