【发布时间】:2021-03-06 17:07:33
【问题描述】:
我正在关注 GraphQL-core 3 文档。为什么会出现这个问题?
代码:
import asyncio
from graphql import (
graphql, GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString)
async def resolve_hello(obj, info):
await asyncio.sleep(3)
return 'world'
schema = GraphQLSchema(
query=GraphQLObjectType(
name='RootQueryType',
fields={
'hello': GraphQLField(
GraphQLString,
resolve=resolve_hello)
}))
async def main():
query = '{ hello }'
print('Fetching the result...')
result = await graphql(schema, query)
print(result)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
finally:
loop.close()
运行脚本后,终端返回如下错误
错误:
Traceback (most recent call last):
File "server.py", line 16, in <module>
resolve=resolve_hello)
TypeError: __init__() got an unexpected keyword argument 'resolve'
【问题讨论】: