Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

graphql multiple mutations using prior mutation return results?

I understand that mutations are sequential, so it makes sense to me that if Mutation 1 creates an entity and returns an id, that Mutation 2 should have access to that id. However I don't see any examples online and can't seem to get it to work. I see that people say you need to handle this in the resolve function of your route but it seems like extra unnecessary code if I can get this in just the query.

For example I have the following where accounts belong to clients and hence need the clientId before being created. However this does not work...

mutation createClientAndAccount($account: AccountInput, $client: ClientInput){
      createClient(client: $client){ clientId }
      createAccount(account: $account, clientId: USE_CLIENT_ID_FROM_ABOVE) { ... } 
    }

I've also tried nesting mutations but didn't have much luck there either...

Is what i'm trying to do possible? Would the resolve function of createAccount have the return data from createClient?

like image 657
Terence Chow Avatar asked May 30 '26 00:05

Terence Chow


1 Answers

This is not possible right now, though would be useful.
See this PR.

like image 102
yachaka Avatar answered Jun 01 '26 20:06

yachaka