0

I want to make a query based on job_id: ID! but seem like something I am doing wrong and I want to understand what.

So here I am taking the job id.

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

So now I want to use that job_id for my query here

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);

But I end up with the following error

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

Any idea?

1 Answer 1

1

Problem solved.

I have used the HOC like this

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.