Hi everyone, Iet's say I have an example with type User and Group that are related to each other. Is there a way to create a new User and connect to Group in the same mutation? Right now, I have two separate queries:
1) Create User
2) Connect the two nodes
s
Stephen Jensen
05/11/2018, 9:16 PM
Sure! You can call a mutation and then do any calls you want in it that might be related to User, Group, getting that random temperature from an external API, cooking brownies, whatever! Whatever you are doing, that's the business of the resolver and as long as your input types and output types match what you define in the schema, you should be good.
h
HarryC
05/11/2018, 9:34 PM
Hm.. I don't need any business logic, just execute the mutations in sequence in one
mutation {}
HarryC
05/11/2018, 9:35 PM
If I do :
mutation {
one: createUser()
two: connectUserToGroup()
}
will it run synchronously?
s
Stephen Jensen
05/11/2018, 9:53 PM
I’m saying run both functions in the single resolver. Resolvers should be made to call other independent functions that do different tasks. This helps with automated testing and reducing code duplication.
Stephen Jensen
05/11/2018, 9:54 PM
To answer your question, make them asyc await if you need them sequential