Graphene Python 突变列表输入

Graphene Python mutation list input

我有一个看起来像这样的突变

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)

在这里,我试图一次传递一个用户列表来更新我的代码中的一些值。但是突变正在抛出错误。有人可以举个例子建议突变的列表输入吗?

使用类似于 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)

在上面的代码中,为了传递用户 ID 列表和字符串列表,我使用了 list(ID) 和 list(String)。成功了