GraphQL mutation several resources in a single submit/transaction?
In the case where you have a root object say "inventory", then sub objects off them which have specific fields e.g. book or drink.
I'm able to use graphql to load several objects at once, but i can't work out how to mutate several at once - is this something that should be possible? Ideally as a complex mutation, where you provide details of both the parent and child objects?
3 Replies
Hi @a_c_m. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is possible to perform mutations on multiple resources in a single transaction using GraphQL with refine. This is especially relevant when dealing with complex data models like the one you described, with a root object (inventory) and sub-objects (book, drink).
Refine supports working with GraphQL data providers, which allows you to use custom GraphQL queries and mutations. Here's how you can approach this:
1. First, you'll need to define a custom GraphQL mutation that handles updating multiple resources.
2. Then, you can use the
useCustomMutation
hook provided by refine to execute this complex mutation.
Here's an example of how you might structure this:
This approach allows you to update multiple resources in a single transaction. The exact structure of your mutation and input will depend on your specific GraphQL schema and requirements.
It's worth noting that the ability to perform such complex mutations is more dependent on your GraphQL server implementation rather than refine itself. Refine provides the tools to work with whatever GraphQL schema you have set up.
For more detailed information on working with GraphQL in refine, you can refer to the GraphQL Data Provider documentation.
If you need to customize how the GraphQL queries and mutations are built or handled, you can also look into the options available for the GraphQL data provider, as described in the GraphQL Options documentation.
Remember that the exact implementation will depend on your specific GraphQL schema and server capabilities. You may need to adjust the mutation structure based on how your backend handles complex updates across multiple resources.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@703579194784874506> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
rival-blackOP•4w ago
how can i use that technique with useForm?