首页 > 解决方案 > 如何在与graphql的本机反应中基于ID进行查询?

问题描述

我想根据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-nativegraphqlapollo

解决方案


问题解决了。

我已经像这样使用了 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);

推荐阅读