플라스크 응용 프로그램을 위해 그래 핀에서 일종의 일반적인 생성 돌연변이를 만들려고합니다. 변형을 생성하기위한 구문은 일반적으로 다음과 같습니다.
class CreateMutation(graphene.Mutation):
class Arguments:
model_attribute1
model_attribute2
...
def mutate(root, info, model_attribute1, model_attribute2):
create model here
일종의 일반 생성 돌연변이 클래스를 만들고 싶습니다. 이렇게하려면 Arguments 클래스를 동적으로 만든 다음 mutate에 전달해야합니다. 를 사용하여 sqlalchemy 모델에서 변형에 필요한 속성을 얻을 수 있다는 것을 알아 SqlAlchemyModel.__table__.columns
냈지만 이러한 열이 주어지면 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';```
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다