graphql multiple mutations using prior mutation return results?

只愿长相守 提交于 2019-12-11 02:29:47

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/44441566/graphql-multiple-mutations-using-prior-mutation-return-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!