我正在用graphql(aiohttp_graphql)创建一个aiohttp api,并给出了这个问题。为什么?
aiohttp版本:aiohttp==3.7.3 -吉特+https://github.com/graphql-python/aiohttp-graphql.git@5F75803010761DD7DE33B44BC92F30B2695F2D523#egg=aiohttp#U图形
这是我的代码:
import asyncio
from aiohttp import web
from aiohttp_graphql import GraphQLView
from graphql.execution.executors.asyncio import AsyncioExecutor
from graphql import (graphql, GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString)
async def resolve_hello(root, info):
await asyncio.sleep(3)
return 'World!'
Schema = GraphQLSchema(
query=GraphQLObjectType(
name='HelloQuery',
fields={
'hello': GraphQLField(
GraphQLString,
resolve=resolve_hello),
},
))
app = web.Application()
GraphQLView.attach(
app,
route_path='/graphql',
schema=Schema,
graphiql=True,
executor=AsyncioExecutor())
if __name__ == '__main__':
web.run_app(app)
运行GraphiQL时:
query {
hello
}
图形结果:
{
"errors": [
{
"message": "String cannot represent value: <coroutine resolve_hello>",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"hello"
]
}
],
"data": {
"hello": null
}
}
终端返回:运行时警告:从未等待协同路由“resolve\u hello”
目前没有回答
相关问题 更多 >
编程相关推荐