Python 石墨烯的通用模型突变

Python 石墨烯的通用模型突变,python,graphql,graphene-python,graphene-sqlalchemy,Python,Graphql,Graphene Python,Graphene Sqlalchemy,我正在尝试在石墨烯中创建一种通用的突变,用于烧瓶应用。为了创建变异,语法通常如下所示: class CreateMutation(graphene.Mutation): class Arguments: model_attribute1 model_attribute2 ... def mutate(root, info, model_attribute1, model_attribute2): create mo

我正在尝试在石墨烯中创建一种通用的突变,用于烧瓶应用。为了创建变异,语法通常如下所示:

class CreateMutation(graphene.Mutation):
    class Arguments:
        model_attribute1
        model_attribute2
        ...

    def mutate(root, info, model_attribute1, model_attribute2):
        create model here
我想创建一些泛型的createmutation类。为此,我需要动态创建Arguments类,然后将其传递到mutate。我已经发现我可以通过
SqlAlchemyModel.\uuu table\uuuu.columns
从sqlalchemy模型中获取突变所需的属性,但是我在弄清楚如何创建给定这些列的Arguments类时遇到了困难。

尝试以下方法:

def create_class(args: dict[str, str]):
    class Arguments: pass
    for arg in args:
        setattr(Arguments, arg, args[arg])
    return Arguments

x = create_class({'thing': '100'}); assert x.thing == '100';```

您应该创建一个返回类参数的函数
create_class
,然后分配class.Arguments=create_class(),也可以使用
类型(类名、继承、属性)