将嵌套查询从 GraphQL 转换为 Graphene 不起作用
Translating nested query from GraphQL to Graphene not working
所以我有一个 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)
所以我有一个 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)