Passing variables to graphql query with react-apollo -
i have problem passing in variable options graphql query. if console.log(ownprops.match.params.id) correct id.
however im getting error:
error: operation 'selectcustomer' wrapping 'apollo(apollo(withrouter(consumer)))' expecting variable: 'id' not found in props passed 'apollo(apollo(apollo(withrouter(consumer))))'
export
const consumerwithmutations = graphql(selectcustomer, { name : 'selectcustomer', options: (ownprops) => ({ variables: { id: ownprops.match.params.id } }) })(graphql(deletecustomer, { name: 'deletecustomer' })(withrouter(consumer))) export default graphql(selectcustomer)(consumerwithmutations);
query
const selectcustomer = gql` query selectcustomer($id: string!) { consumer(id: $id) { id firstname lastname dateofbirth ...
you're attempting wrap component same query hoc twice -- first time within definition of consumerwithmutations
, again inside export statement.
you don't pass options hoc inside export statement, selectcustomer
query can't find id
variable specified, why see error you're getting.
modify export statement this:
export default consumerwithmutations;
and should work.
i highly recommend utilizing compose
when you're using multiple hocs -- helps keep code readable. check out example here.
Comments
Post a Comment