I have wrapped for both Query and Mutations so I can globally handle the repeat actions that need to happen with each Query, Mutation
. In the query I transform the data so I don't need to worry about all the nodes, edges, etc
I am using react-adopt
to wrap all my query
and mutations
components into one render prop back on the view layer.
<ApolloQuery>
export const ApolloQuery = ({
query: query,
render,
}) => {
return (
<Query query={query}>
{({ data }) => {
return (
<Fragment>
render(data)
</Fragment>
)
}}
</Query>
)
}
export default externalProps => {
return (
<QueryContainer {...externalProps}>
{({ someQueryData, aMutation }) => { //react-adopt render props
const { nestedData } = new apolloClass(someQueryData).start()
return (
<Grid container spacing={16}>
{nestedData.map((ticket, index) => (
{...Mutation button in here}
))}
</Grid>
)
}}
</QueryContainer>
)
}
<ApolloQuery>
<Query query={query}>
{({ data }) => {
const transformedData = new apolloClass(data).start() //move transform into render
return (
<Fragment>
render(transformedData)
</Fragment>
)
}}
</Query>
export default externalProps => {
return (
<QueryContainer {...externalProps}>
{({ someQueryData: { nestedData }, aMutation }) => {
return (
<Grid container spacing={16}>
{nestedData.map((ticket, index) => (
{...Mutation button in here}
))}
</Grid>
)
}}
</QueryContainer>
)
}
So now, the page will not update after a mutation if I move the apolloClass
to transform before the render of the query
Most likely you need to set refetchQueries
or awaitRefetchQueries
in the mutation options to force Apollo updating those queries and hence triggering a re-render.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With