如何解决将嵌套查询从 GraphQL 转换为 Graphene 不起作用
所以我有一个 GraphQL API,我向它写了一个查询,它可以工作并在 GraphiQL 中向我发送回数据。
query dishes {
dishes {
name
recipeNote
description
}
}
这是我对石墨烯的翻译
class Dish(ObjectType):
name = String()
recipeNote = String()
description = String()
class Query(ObjectType):
first = Field(Dish)
def resolve_first(parent,info):
return parent
query_string = "{ first { dishes { name recipeNote description } } }"
result = schema.execute(
query_string)
print(result)
print(result.data)
但是这给了我一个错误 {'errors': [{'message': 'Cannot query field "dishes" on type "Dish".','locations': [{'line': 1,'column': 11}]}]}
解决方法
from graphene import List,ObjectType,String
class Dish(ObjectType):
name = String()
recipeNote = String()
description = String()
class Query(ObjectType):
dishes = List(Dish)
def resolve_dishes(parent,info):
return [Dish(name='',recipeNote='',description=''),...]
query_string = "query dishes {
dishes {
name
recipeNote
description
}
}"
result = schema.execute(
query_string)
print(result)
print(result.data)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。