我想在graphiql中创建一个家具对象,使用以下查询,我收到错误无法查询字段"家具"在类型" RootMutation" 。
这是我为创建家具对象所做的查询
mutation {
newFurniture(input: {name: "graphFurniture", content: "This furniture is cool", category: "Bedroom Items"}) {
clientMutationId
}
furniture{ // error is shown here
name
content
category {
name
}
}
}
这是我的变异代码
class FurnitureNode(DjangoObjectType):
class Meta:
model = Furniture
class NewFurniture(graphene.ClientIDMutation):
furniture = graphene.Field(FurnitureNode)
class Input:
name = graphene.String()
content = graphene.String()
category = graphene.String()
@classmethod
def mutate_and_get_payload(cls, input, context, info):
furniture = Furniture(name=input.get('name'), content=input.get('content'),
category=Category.objects.get(name=input.get('category')))
furniture.save()
return NewFurniture(furniture=furniture)
class NewFurnitureMutation(graphene.ObjectType):
new_furniture = NewFurniture.Field()
为什么我会收到这样的错误?
答案 0 :(得分:0)
您无法在“突变”范围内查询家具。这是两个单独的行动:
mutation {
newFurniture(input: {name: "graphFurniture", content: "This furniture is cool", category: "Bedroom Items"}) {
clientMutationId
}
}
query {
furniture {
name
content
category {
name
}
}
}