0

我想通过使用以下查询在 graphiql 中创建一个家具对象,其中出现错误Cannot query field "furniture" on type "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()

为什么我会收到这样的错误?

4

1 回答 1

0

您不能在“突变”范围内查询家具。这是两个独立的动作:

mutation {
  newFurniture(input: {name: "graphFurniture", content: "This furniture is cool", category: "Bedroom Items"}) {
    clientMutationId
  }
}

query {
  furniture {
    name
    content
    category {
      name
    }
  }
}
于 2017-11-09T04:59:21.473 回答