【问题标题】:How to make a query based on ID in react native with graphql?如何在与graphql的本机反应中基于ID进行查询?
【发布时间】:2019-04-08 22:40:21
【问题描述】:

我想根据job_id: ID! 进行查询,但似乎我做错了什么,我想了解是什么。

所以我在这里接受工作 ID。

render() {
 const { job } = this.props.navigation.state.params;
 const job_id = job._id;
 ........
}

所以现在我想在这里使用job_id 进行查询

const GET_APPLICATIONS = gql`
  query getJobApplicationsForThisJob($job_id: ID!) {
    getJobApplicationsForThisJob(job_id: $job_id) {
      _id
    }
  }
`;

const DELETE_JOB = gql`
  mutation deteleJob($_id: ID!) {
      deleteJob(_id: $_id) {
        message
      }
    }
`;

const mutationConfig = {
    props: ({ mutate, ownProps }) => ({
        deleteJob: (_id) => mutate({ variables: { _id } }),
        ...ownProps,
    })
}

export default compose(
    withApollo,
    graphql(GET_APPLICATIONS, { name: "getApplications" }),
    graphql(DELETE_JOB, mutationConfig)
)(JobDetails);

但我最终得到以下错误

Invariant Violation: The operation 'getJobApplicationsForThisJob' wrapping 'JobDetails' is expecting variable 'job_id' but it was not found in the props passed to 'Apollo(JobDetails)'

有什么想法吗?

【问题讨论】:

    标签: react-native graphql apollo


    【解决方案1】:

    问题解决了。

    我用过这样的 HOC

    export default compose(
        withApollo,
        graphql(GET_APPLICATIONS, { name: "getApplications", options: (props) => ({ variables: { job_id: props.navigation.state.params.job._id } }) }),
        graphql(DELETE_JOB, mutationConfig)
    )(JobDetails);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 2021-04-23
      • 2021-09-05
      • 2018-08-15
      • 2020-05-23
      • 2022-11-25
      • 1970-01-01
      相关资源
      最近更新 更多