无法在“RootMutation”类型上查询字段“家具”
Posted
技术标签:
【中文标题】无法在“RootMutation”类型上查询字段“家具”【英文标题】:Cannot query field "furniture" on type "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()
为什么我会收到这样的错误?
【问题讨论】:
【参考方案1】:您不能在“变异”范围内查询家具。这是两个独立的动作:
mutation
newFurniture(input: name: "graphFurniture", content: "This furniture is cool", category: "Bedroom Items")
clientMutationId
query
furniture
name
content
category
name
【讨论】:
我遇到未命名的问题,当单击未命名时,我得到“此匿名操作必须是唯一定义的操作。”以上是关于无法在“RootMutation”类型上查询字段“家具”的主要内容,如果未能解决你的问题,请参考以下文章
带有官方 Graphql 教程的“无法在 CreateUser 类型上查询字段 'id'”
gatsby graphql 无法在“Query”类型上查询字段“allTribeEvents”