[英]Graphene Python mutation list input
I have a mutation that looks like this我有一个看起来像这样的突变
class ApisInteractiveGlobal(BaseMutation):
success = Boolean()
error = String()
class Arguments:
user_id = List(ID)
api_name = String()
global_apis = Boolean()
my_org_api = Boolean()
def mutate(self, info, user_id=[], api_name=None, global_apis=None, my_org_api=None):
for id in user_id:
user = User.objects.get(id=id)
api = user.apis_interactive.get(name=api_name)
if my_org_api is not None:
api.my_orgapis = my_org_api
if global_apis is not None:
api.global_apis = global_apis
api.save(update_fields=['global_apis', 'my_orgapis'])
return ApisInteractiveGlobal(success=True)
Here, I'm trying to pass a list of users at a time to update some values in my code.在这里,我试图一次传递一个用户列表来更新我的代码中的一些值。 But the mutation is throwing errors.
但是突变会引发错误。 Can someone suggest a list input for the mutation as an example?
有人可以建议突变的列表输入为例吗?
Passing any of list of values of other types is easy using similar to list(String) For example传递任何其他类型的值列表很容易使用类似于 list(String) 例如
class ApisInteractiveGlobal(BaseMutation):
success = Boolean()
error = String()
class Arguments:
user_id = List(ID)
apis = List(String)
global_apis = Boolean()
my_org_api = Boolean()
def mutate(self, info, user_id=[], apis=[], global_apis=None, my_org_api=None):
for id in user_id:
for api in apis:
user = User.objects.get(id=id)
api = user.apis_interactive.get(name=api)
if my_org_api is not None:
api.my_orgapis = my_org_api
if global_apis is not None:
api.global_apis = global_apis
api.save(update_fields=['global_apis', 'my_orgapis'])
return ApisInteractiveGlobal(success=True)
In the above code, to pass a list of user ids and list of strings I've used list(ID) & list(String).在上面的代码中,为了传递用户 ID 列表和字符串列表,我使用了 list(ID) 和 list(String)。 It worked
有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.