diff --git a/aiohttp_graphql/graphqlview.py b/aiohttp_graphql/graphqlview.py index dfe27fc..c20dbe0 100644 --- a/aiohttp_graphql/graphqlview.py +++ b/aiohttp_graphql/graphqlview.py @@ -4,10 +4,9 @@ from promise import Promise from aiohttp import web from graphql.type.schema import GraphQLSchema -from graphql.execution.executors.asyncio import AsyncioExecutor +from graphql import format_error as default_format_error from graphql_server import ( HttpQueryError, - default_format_error, encode_execution_results, json_encode, load_json_body, @@ -21,7 +20,6 @@ class GraphQLView: # pylint: disable = too-many-instance-attributes def __init__( self, schema=None, - executor=None, root_value=None, context=None, pretty=False, @@ -34,14 +32,13 @@ def __init__( max_age=86400, encoder=None, error_formatter=None, - enable_async=True, + field_resolver=None, subscriptions=None, - **execution_options, + **execution_options ): # pylint: disable=too-many-arguments self.schema = schema - self.executor = executor self.root_value = root_value self.context = context self.pretty = pretty @@ -54,7 +51,7 @@ def __init__( self.max_age = max_age self.encoder = encoder or json_encode self.error_formatter = error_formatter or default_format_error - self.enable_async = enable_async and isinstance(self.executor, AsyncioExecutor) + self.field_resolver = field_resolver self.subscriptions = subscriptions self.execution_options = execution_options assert isinstance( @@ -139,19 +136,13 @@ async def __call__(self, request): batch_enabled=self.batch, catch=is_graphiql, # Execute options - return_promise=self.enable_async, root_value=self.root_value, context_value=self.get_context(request), middleware=self.middleware, - executor=self.executor, + field_resolver=self.field_resolver, **self.execution_options, ) - if is_graphiql and self.enable_async: - # catch errors like run_http_query does when async - execution_results = [ - result.catch(lambda value: None) for result in execution_results - ] awaited_execution_results = await Promise.all(execution_results) result, status_code = encode_execution_results( awaited_execution_results, @@ -197,7 +188,7 @@ def process_preflight(self, request): @classmethod def attach(cls, app, *, route_path="/graphql", route_name="graphql", **kwargs): view = cls(**kwargs) - app.router.add_route("*", route_path, _asyncify(view), name=route_name) + return app.router.add_route("*", route_path, _asyncify(view), name=route_name) def _asyncify(handler): diff --git a/setup.py b/setup.py index c1440d1..150d16c 100644 --- a/setup.py +++ b/setup.py @@ -23,9 +23,12 @@ keywords="api graphql protocol aiohttp", packages=find_packages(exclude=["tests"]), install_requires=[ - "graphql-core>=2.3,<3", - "graphql-server-core>=1.2,<2", - "aiohttp>=3,<4", + 'graphql-core-next', + 'aiohttp>=4.0.0a', + 'pytest-runner', + 'graphql-server-core@git+https://github.com/x0y-gt/graphql-server-core#egg=graphql-server-core-1.1', + 'promise', + 'asyncio', ], extras_require={ "test": [