1- from collections import Mapping
1+ from collections . abc import Mapping
22from functools import partial
33
4- from aiohttp import web
54from promise import Promise
6-
5+ from aiohttp import web
76from graphql .type .schema import GraphQLSchema
87from graphql .execution .executors .asyncio import AsyncioExecutor
98from graphql_server import (
1817from .render_graphiql import render_graphiql
1918
2019
21- class GraphQLView : # pylint: disable = too-many-instance-attributes
20+ class GraphQLView : # pylint: disable = too-many-instance-attributes
2221 def __init__ (
2322 self ,
2423 schema = None ,
@@ -35,8 +34,7 @@ def __init__(
3534 max_age = 86400 ,
3635 encoder = None ,
3736 error_formatter = None ,
38- enable_async = True ,
39- ):
37+ enable_async = True ):
4038 # pylint: disable=too-many-arguments
4139 # pylint: disable=too-many-locals
4240
@@ -55,9 +53,7 @@ def __init__(
5553 self .encoder = encoder or json_encode
5654 self .error_formatter = error_formatter or default_format_error
5755 self .enable_async = enable_async and isinstance (
58- self .executor ,
59- AsyncioExecutor ,
60- )
56+ self .executor , AsyncioExecutor )
6157 assert isinstance (self .schema , GraphQLSchema ), \
6258 'A Schema is required to be provided to GraphQLView.'
6359
@@ -76,14 +72,13 @@ async def parse_body(self, request):
7672 r_text = await request .text ()
7773 return {'query' : r_text }
7874
79- elif request .content_type == 'application/json' :
75+ if request .content_type == 'application/json' :
8076 text = await request .text ()
8177 return load_json_body (text )
8278
83- elif request .content_type in (
79+ if request .content_type in (
8480 'application/x-www-form-urlencoded' ,
85- 'multipart/form-data' ,
86- ):
81+ 'multipart/form-data' ):
8782 # TODO: seems like a multidict would be more appropriate
8883 # than casting it and de-duping variables. Alas, it's what
8984 # graphql-python wants.
@@ -143,6 +138,11 @@ async def __call__(self, request):
143138 executor = self .executor ,
144139 )
145140
141+ if is_graphiql and self .enable_async :
142+ # catch errors like run_http_query does when async
143+ execution_results = [
144+ result .catch (lambda value : None )
145+ for result in execution_results ]
146146 awaited_execution_results = await Promise .all (execution_results )
147147 result , status_code = encode_execution_results (
148148 awaited_execution_results ,
0 commit comments