python-3.x - 将嵌套查询从 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)
推荐阅读
- scala - 多次连接后 Spark 数据集无法解析列
- java - JavaFX 更新画面
- unity3d - 第一次按下转义时光标不可见,但随后的所有时间都是
- javascript - 如何仅使用 ChartjsPluginStacked100 javascript,没有打字稿
- spring - 我应该使用 Traefik 的 GZIP 压缩还是服务器的压缩?
- abaqus - Abaqus 显示具有不同缩放比例的轴
- python - 如何从输入中获取整数列表(不带引号)并在函数中使用它来计算数字
- java - 防止不当输入处理攻击
- python - 如何为绘图条形图中的某些条形设置特定颜色?
- android - Android Studio 签名的 APK 构建失败:com.android.build.gradle.internal.tasks.Workers$ActionFacade