AIOHTTP with Graphql: TypeError: __init__() got an unexpected keyword argument 'resolve'. Why this problem?
AIOHTTP with Graphql: TypeError: __init__() got an unexpected keyword argument 'resolve'. Why this problem?
我正在关注 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()
脚本运行后,终端returns出现如下错误
错误:
Traceback (most recent call last):
File "server.py", line 16, in <module>
resolve=resolve_hello)
TypeError: __init__() got an unexpected keyword argument 'resolve'
这是 graphql 版本的问题。例如,在版本 0.5.3
上,我遇到了与您相同的问题。
from graphql import (
GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString)
schema = GraphQLSchema(
query=GraphQLObjectType(
name='RootQueryType',
fields={
'hello': GraphQLField(
GraphQLString,
resolve=lambda obj, info: 'world')
}))
>>> TypeError: __init__() got an unexpected keyword argument 'resolve'
刚刚更改为版本 3 或更高版本。
pip install "graphql-core>=3"
我正在关注 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()
脚本运行后,终端returns出现如下错误
错误:
Traceback (most recent call last):
File "server.py", line 16, in <module>
resolve=resolve_hello)
TypeError: __init__() got an unexpected keyword argument 'resolve'
这是 graphql 版本的问题。例如,在版本 0.5.3
上,我遇到了与您相同的问题。
from graphql import (
GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString)
schema = GraphQLSchema(
query=GraphQLObjectType(
name='RootQueryType',
fields={
'hello': GraphQLField(
GraphQLString,
resolve=lambda obj, info: 'world')
}))
>>> TypeError: __init__() got an unexpected keyword argument 'resolve'
刚刚更改为版本 3 或更高版本。
pip install "graphql-core>=3"