【问题标题】:Cannot query field "furniture" on type "RootMutation"无法在“RootMutation”类型上查询字段“家具”
【发布时间】:2018-04-21 22:31:31
【问题描述】:

我想通过使用以下查询在 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()

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

【问题讨论】:

    标签: python django graphql graphene-python


    【解决方案1】:

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

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

    【讨论】:

    • 我遇到未命名的问题,当单击未命名时,我得到“此匿名操作必须是唯一定义的操作。”
    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 2021-02-03
    • 2021-06-03
    • 2021-10-09
    • 2018-08-30
    • 2021-07-26
    • 2020-05-31
    • 2021-11-13
    相关资源
    最近更新 更多