Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions aiohttp_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down