Is it possible run a mutation on another graphqlType from within a mutation? I'm not sure if this is a good idea or not. Ideally it would be nice to have create mutations for each one of graphql data types and then call into each of those functions when needed. Hopefully this keeps things more DRY.
For example I have 2 graphql types "projects" and "rooms". For every project a room needs to be created and the ID placed in the project for reference later.
Still learning the ropes with graphql so any insight on whats good practice would be awesome.
While GraphQL allows the client to freely shape query and response, mutations (create, update or delete operations) are by design atomic.
Update mutations take filter as an input to select specific objects. You can specify set and remove operations on fields belonging to the filtered objects. It returns the state of the objects after updating. Note Executing an empty remove {} or an empty set{} doesn't have any effect on the update mutation.
I'm sure you figured out a solution to your problem long ago, but why not just make a mutation that captures the entire process, like createProjectAndRoom
? I think it's a mistake to think of GraphQL resolvers as mapping very rigidly to single actions on single models.
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