根据变量的长度多次进行突变调用 [英] Make a mutation call multiple times depending on length of variable
本文介绍了根据变量的长度多次进行突变调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是否可以从前端多次调用突变?我有一个需要添加到应用程序中的用户,目前该突变只允许一次添加一个用户(我们可以更改突变,但他们想看看我是否可以首先在前端进行批处理).>
这是我目前的突变:
export const SHARE_APP = gql`变异ShareApp($ appId:字符串!$ userId:字符串!){shareApp(appId:$ appIduserId:$ userId){UpdatedApp {ID}}}`;
这可以在前端完成吗?还是我需要更改gql代码以接受ID数组?
解决方案
Mutation
组件, useMutation
钩子和 graphql
HOC全部为您提供一种可以随意使用的方法.
const [share] = useMutation(SHARE_APP)等待Promise.all(appIds.map((appId)=> share({变量:{用户身份,appId,},})))
就这些请求而言,Apollo不支持该功能,因此您必须使用类似 解决方案
The Mutation
component, the useMutation
hook and the graphql
HOC all give you a method that can be used as many times as you like.
const [share] = useMutation(SHARE_APP)
await Promise.all(appIds.map((appId) => share({
variables: {
userId,
appId,
},
})))
As far as batching these requests, Apollo does not support that out of the box so you would have to use a link like apollo-link-batch-http.
这篇关于根据变量的长度多次进行突变调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文