graphql使用先前的突变返回结果的多个突变? [英] graphql multiple mutations using prior mutation return results?

查看:76
本文介绍了graphql使用先前的突变返回结果的多个突变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道突变是顺序的,所以对我来说有意义的是,如果突变1创建一个实体并返回一个ID,则突变2应该可以访问该ID.但是,我在网上看不到任何示例,并且似乎无法使其正常工作.我看到有人说您需要在路线的resolve函数中处理此问题,但是如果我可以在查询中得到此消息,则似乎多余的代码.

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.

例如,我有以下帐户属于客户的帐户,因此在创建之前需要clientId.但是,这不起作用...

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...

我想做的是可能的吗? createAccount的resolve函数是否具有createClient的返回数据?

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

推荐答案

尽管这很有用,但目前尚无法实现.
参见此PR .

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

这篇关于graphql使用先前的突变返回结果的多个突变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆