You can do it by passing a reference to Apollo Client using the withApollo
higher-order-component, as documented here: https://www.apollographql.com/docs/react/api/react-apollo.html#withApollo
Then, you can call client.query
on the passed in object, like so:
class MyComponent extends React.Component {
runQuery() {
this.props.client.query({
query: gql`...`,
variables: { ... },
});
}
render() { ... }
}
withApollo(MyComponent);
Out of curiosity, what's the goal of running a query on a click event? Perhaps there is a better way to accomplish the underlying goal.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…