Intended outcome:
We want to use the Mutation
component, but conditionally execute on two Mutations (dependent on a prop received by the component it wraps).
I can't find documentation or use-cases that demonstrate this. Would this be a better use case for a HOC using graphql
? or should I have a totally separate mutation function (that does A + B) rather than have one mutation that does A and maybe B?
Actual outcome:
<Mutation
mutation={createMutation}
>
{(createNode) => {
const maybeCreateNewNodes = (propData) =>
createNode({
variables: {
nodes: [newFolderNode],
options,
},
});
if (propData.specialProp) {
doSecondMutation({ variables: { specialProp }})
}
};
return (
<NewtemContainer
twoMutations={maybeCreateNewNodes}
{...props}
/>
);
}}
</Mutation>
Stacking Mutation
components doesn't seem to be a great use-case if I can just do
yield call (firstMutation)
if (specialProp)
yield call(secondMutation)
Version
Thanks for the suggestion @anthonychung14. This is something that could be handled by using HOC's with graphql
and Recompose's branch
functionality. I agree though, it would be helpful to have something like this documented. PR's encouraged! 馃檪
Just a quick update here - we're going to add a new nested mutation section to the docs shortly. This new section will cover:
<Mutation />
component + render props react-adopt
(also covering the pros/cons of this approach)Looking forward to those docs updates! I'm facing this situation, as well.
Same!! :) +1
+1: have need to mutate parent object, straight after create mutation of object itself.
Just managed this with 2 nested Mutation components, used their update props for cache and UI updates.
Question: Would it be equally good practice to nest Mutation component into ApolloConsumer component and use client.mutate({ mutation, variables, update }) ?
Mutations can be more than just 2. So, looking forward for docs updates.
To help provide a more clear separation between feature requests / discussions and bugs, and to help clean up the feature request / discussion backlog, Apollo Client feature requests / discussions are now being managed under the https://github.com/apollographql/apollo-feature-requests repository.
Migrated to: https://github.com/apollographql/apollo-feature-requests/issues/8
Most helpful comment
Just a quick update here - we're going to add a new nested mutation section to the docs shortly. This new section will cover:
<Mutation />
component + render propsreact-adopt
(also covering the pros/cons of this approach)