Skip to content

Instantly share code, notes, and snippets.

@xonlly
Created January 24, 2018 15:17
Show Gist options
  • Save xonlly/fad80a53dfa8744605e7f95abf1c99dc to your computer and use it in GitHub Desktop.
Save xonlly/fad80a53dfa8744605e7f95abf1c99dc to your computer and use it in GitHub Desktop.
ApolloQueryPromise(client<context>, query<string>, variables<object>, options<object>).then(...)
import PropTypes from 'prop-types';
/*
ApolloQueryPromise(client<context>, query<string>, variables<object>, {
skip: ownProps => ownProps.skip,
})
.then((data, res) => console.log('data', data, res))
.catch(error => { ... });
*/
const ApolloQueryPromise = (client, query, variables = {}, config = {}) =>
new Promise((resolve, reject) => {
const overidedConfig = {
...config,
options: {
...(config.options || {}),
// overide options
notifyOnNetworkStatusChange: true,
},
};
client
.query({
...overidedConfig,
query,
variables,
})
.then(res => resolve(res.data, res))
.catch(reject);
});
// context type:
export const CLIENT_CONTEXT_TYPE = PropTypes.object;
export default ApolloQueryPromise;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment