Code samples for ts react apollo with mutations
Is there a complete code sample for how to use the Hocs for a mutation?
I’m pretty new to graphql and can’t figure out how to actually use these.
@ardatan can you please assist? :)
You can use withYourMutationName that is generated with react-apollo plugin.
withYourMutationName()(YourBaseComponent);
class YourBaseComponent<YourMutationNameDataProps>{
render(){
this.mutate({ variables: {} })
}
}
@dotansimha Are there any plans to add additional documentation on this? I'm trying to figure out how to use the generated mutation components but I'm not having much luck digging through ts without docs.
From what I can gather, the mutation component forwards a 'mutation function' that fires the mutation accepting some options?
<UpdateUserComponent>
{mutate => (
<Button onClick={() => mutate(someOptions)}>Mutate</Button>
)}
</UpdateUserComponent>
Am I close?
Hi @Flash619 !
The output from the codegen is has the same signature and usage as Apollo.
You can find the documentation here: https://www.apollographql.com/docs/react/api/react-apollo
The only difference is that GraphQL Codegen wraps the original <Mutation> with a custom name, adds the type-safety to it, and automatically sets the GraphQL operation, so you can just use it as-is without the need to pass the GraphQL document or type generics.