Created
January 24, 2018 15:17
-
-
Save xonlly/fad80a53dfa8744605e7f95abf1c99dc to your computer and use it in GitHub Desktop.
ApolloQueryPromise(client<context>, query<string>, variables<object>, options<object>).then(...)
This file contains 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
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