Apollo graphql将查询作为prop函数传递

Apollo graphql将查询作为prop函数传递,graphql,react-apollo,graphql-js,Graphql,React Apollo,Graphql Js,来自react apollo的graphql hoc有助于将组件与查询连接起来。这样查询将执行,结果将作为组件中的道具可用 有没有一种方法可以不直接执行查询,而是将函数作为prop传递给函数,该函数可以作为组件内的正常函数调用执行。因为我有一个查询需要在用户选择组件中的一些选项后执行 乙二醇 getCorrespondingValues(值)“/> 函数getCorrespondingValues(值){ this.props.getValuesQuery(值) } 这可以通过直接使用ap

来自react apollo的graphql hoc有助于将组件与查询连接起来。这样查询将执行,结果将作为组件中的道具可用

有没有一种方法可以不直接执行查询,而是将函数作为prop传递给函数,该函数可以作为组件内的正常函数调用执行。因为我有一个查询需要在用户选择组件中的一些选项后执行

乙二醇


getCorrespondingValues(值)“/>
函数getCorrespondingValues(值){
this.props.getValuesQuery(值)
} 
这可以通过直接使用apollo客户端来实现。但是无论如何都可以在帮助graphql hoc中使用它。因此组件代码不必更改

const getValuesQueryHOC = graphql(YOUR_MUTATION, {
  props: ({ mutate }) => ({
    getValuesQuery: (values) =>
      mutate({
        variables: {
          values
        }
      })
  })
});
export default getValuesQueryHOC(YourComponent)
const getValuesQueryHOC = graphql(YOUR_MUTATION, {
  props: ({ mutate }) => ({
    getValuesQuery: (values) =>
      mutate({
        variables: {
          values
        }
      })
  })
});
export default getValuesQueryHOC(YourComponent)