问题描述
我有一个问题,将Apollo突变组件与查询组件一起包裹.如果您查看 updatecell 功能,我将能够获得该行的OldValue,NewValue和ID. 如何使用Apollo客户端突变组件将值传递给附加成本突变.
以下是我的代码:
事先感谢您的任何提示.
const APPROVALCHAIN_QUERY = gql` { vApprovalChainApproverCountList{ applicationId applicationName collectionName licenseType cost approvers } } `; const ADDCOST_MUTATION = gql` mutation($cost: String!){ updateCost(cost: $cost){ applicationId cost } } `; class ApprovalChain extends Component { render() { return ( <Query query={APPROVALCHAIN_QUERY} > {({ loading, error, data }) => { if (loading) return <p>Loading...</p>; if (error) return <p>{error.message}</p>; const chain = JSON.parse(JSON.stringify(data.vApprovalChainApproverCountList)); return ( <div> <h1>ApprovalChain</h1> <BootstrapTable keyField="applicationId" data={chain} columns={columns} cellEdit={cellEditFactory({ mode: 'click', blurToSave: true, Need Help ------------->>>**updateCell:** (oldValue, newValue, row) => { console.log(row.applicationId, oldValue, newValue); }, })} /> </div> ); }} </Query> ); } } export default ApprovalChain;
推荐答案
用突变组件包装起来应起作用.尝试这样的事情:
class ApprovalChain extends Component { render() { return ( <Query query={APPROVALCHAIN_QUERY}> {({ loading, error, data }) => { if (loading) return <p>Loading...</p> if (error) return <p>{error.message}</p> const chain = JSON.parse( JSON.stringify(data.vApprovalChainApproverCountList) ) return ( <div> <h1>ApprovalChain</h1> <Mutation mutation={ADDCOST_MUTATION}> {addCost => ( <BootstrapTable keyField="applicationId" data={chain} columns={columns} cellEdit={cellEditFactory({ mode: 'click', blurToSave: true, updateCell: (oldValue, newValue, row) => { console.log(row.applicationId, oldValue, newValue) addCost({ variables: { cost: newValue } }); } })} /> )} </Mutation> </div> ) }} </Query> ) } } export default ApprovalChain
问题描述
I am having an issue wrapping the Apollo mutation component along with the query component. If you look at the updateCell function I am able to get the oldValue, newValue, and ID for the row. How can I pass the values to ADDCOST mutation using Apollo client mutation component.
Below is my code:
Thanks in advance for any tips.
const APPROVALCHAIN_QUERY = gql` { vApprovalChainApproverCountList{ applicationId applicationName collectionName licenseType cost approvers } } `; const ADDCOST_MUTATION = gql` mutation($cost: String!){ updateCost(cost: $cost){ applicationId cost } } `; class ApprovalChain extends Component { render() { return ( <Query query={APPROVALCHAIN_QUERY} > {({ loading, error, data }) => { if (loading) return <p>Loading...</p>; if (error) return <p>{error.message}</p>; const chain = JSON.parse(JSON.stringify(data.vApprovalChainApproverCountList)); return ( <div> <h1>ApprovalChain</h1> <BootstrapTable keyField="applicationId" data={chain} columns={columns} cellEdit={cellEditFactory({ mode: 'click', blurToSave: true, Need Help ------------->>>**updateCell:** (oldValue, newValue, row) => { console.log(row.applicationId, oldValue, newValue); }, })} /> </div> ); }} </Query> ); } } export default ApprovalChain;
推荐答案
Wrapping it up with a Mutation component should work. Try something like this:
class ApprovalChain extends Component { render() { return ( <Query query={APPROVALCHAIN_QUERY}> {({ loading, error, data }) => { if (loading) return <p>Loading...</p> if (error) return <p>{error.message}</p> const chain = JSON.parse( JSON.stringify(data.vApprovalChainApproverCountList) ) return ( <div> <h1>ApprovalChain</h1> <Mutation mutation={ADDCOST_MUTATION}> {addCost => ( <BootstrapTable keyField="applicationId" data={chain} columns={columns} cellEdit={cellEditFactory({ mode: 'click', blurToSave: true, updateCell: (oldValue, newValue, row) => { console.log(row.applicationId, oldValue, newValue) addCost({ variables: { cost: newValue } }); } })} /> )} </Mutation> </div> ) }} </Query> ) } } export default ApprovalChain