aiohttp-graphql AsyncioExecutor GraphQLLocatedError: объект 'NoneType' не вызывается - PullRequest
0 голосов
/ 13 января 2019

Я начинаю с asyncio + GraphQL, но не могу заставить работать даже самый простой пример:

from aiohttp import web
from aiohttp_graphql import GraphQLView
from graphql.execution.executors.asyncio import AsyncioExecutor
from graphql import GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString

async def resolve_hello(root, info):
    return 'World!'

Schema = GraphQLSchema(
    query=GraphQLObjectType(
        name='RootQueryType',
        fields={
            'hello': GraphQLField(
                type=GraphQLString,
                resolver=resolve_hello),
        },
    ))

app = web.Application()
GraphQLView.attach(
    app,
    route_path='/graphql',
    schema=Schema,
    graphiql=True,
    executor=AsyncioExecutor)

if __name__ == '__main__':
    web.run_app(app)

Консоль

$ venv/bin/python example.py
======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
An error occurred while resolving field RootQueryType.hello
Traceback (most recent call last):
  File "/.../venv/lib/python3.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/.../venv/lib/python3.7/site-packages/graphql/execution/executors/asyncio.py", line 69, in execute
    result = fn(*args, **kwargs)
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
  File "/.../venv/lib/python3.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/.../venv/lib/python3.7/site-packages/graphql/execution/executors/asyncio.py", line 69, in execute
    result = fn(*args, **kwargs)
graphql.error.located_error.GraphQLLocatedError: 'NoneType' object is not callable

Сообщение об ошибке в интерфейсе / graphql graphiql:

{
  "errors": [
    {
      "message": "wait_until_finished() missing 1 required positional argument: 'self'"
    }
  ]
}

1 Ответ

0 голосов
/ 13 января 2019

Проблема была в настройке исполнителя:

GraphQLView.attach(
    ...
    executor=AsyncioExecutor)

должно быть

GraphQLView.attach(
    ...
    executor=AsyncioExecutor())
...