【发布时间】:2020-04-03 11:48:46
【问题描述】:
我希望打开一个 GraphQL 突变端点,其中发送一个 id 和字符串。然后这将根据 ID 收集项目并更改对象中的值,并将更改保存在数据库中的项目中。
看起来像这样:
Query SomeMutation{
ExampleMutation(input: {id: 1, Status: "Something"}){
ExampleObject{
id
Status
}
}
}
我目前有以下设置:
(Schema.py)
class Mutation(graphene.ObjectType):
ExampleMutation = ExampleMutation.Field()
(Schema_ExampleObject.py)
class Captcha(SQLAlchemyObjectType):
class Meta:
model = ExampleObjectModel
interfaces = (relay.Node,)
(ExampleMutation.py)
class Attributes:
id = graphene.Int(description="Id")
status = graphene.String(description="Status")
class ExampleMutationInput(graphene.InputObjectType, Attributes):
pass
class ExampleSolution(graphene.Mutation):
ExampleObject= graphene.Field(lambda: ExampleObject, description="Example Object")
class Arguments:
input = ExampleMutationInput(required=True)
def mutate(self, info, input):
data = input
# **** Here I want to query an item from the DB based on the ID and change a value in it, then save it in the DB and return the new object to the GraphQL. ****
return ExampleMutation(exampleobject=exampleobject)
我在网上查看了解决方案,发现可以通过以下方式调用库:
item = ExampleObject.query.filter(blablanla)
但是对象没有“查询”之类的功能,所以我很困惑。
【问题讨论】:
标签: python flask-sqlalchemy graphene-python