Skip to content

graphql-server v3.0.0b1 does not work with aiohttp in async mode with graphiql #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ketanbshah opened this issue Oct 7, 2020 · 3 comments · Fixed by #67
Closed

graphql-server v3.0.0b1 does not work with aiohttp in async mode with graphiql #64

ketanbshah opened this issue Oct 7, 2020 · 3 comments · Fixed by #67
Labels
good first issue First-time contributors that open a new issue type: bug An issue or pull request relating to a bug

Comments

@ketanbshah
Copy link

ketanbshah commented Oct 7, 2020

I had to change graphqlview.py at line 155 as follows

exec_res = (
    [ex if ex is None or isinstance(ex, ExecutionResult) else await ex for ex in execution_results]
    if self.enable_async
    else execution_results
)

from

exec_res = (
    [await ex for ex in execution_results]
    if self.enable_async
    else execution_results
)
@r-owen
Copy link
Contributor

r-owen commented Oct 15, 2020

Thank you for this fix.

The problem I was observing was in an aiohttp app that called:

GraphQLView.attach(..., enable_async=True, graphiql=True)

Setting enble_async=True caused the following exception (and I can't use False because I want my resolvers to be coroutines):

Traceback (most recent call last):
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/safir/middleware.py", line 141, in bind_logger
    response = await handler(request)
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/graphql_server/aiohttp/graphqlview.py", line 239, in _dispatch
    return await handler(request)
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/graphql_server/aiohttp/graphqlview.py", line 156, in __call__
    if self.enable_async
  File "/Users/rowen/UW/LSST/tsrepos/owl/.tox/run/lib/python3.7/site-packages/graphql_server/aiohttp/graphqlview.py", line 155, in <listcomp>
    [await ex for ex in execution_results]
"TypeError: object ExecutionResult can't be used in 'await' expression"

@KingDarBoja
Copy link
Contributor

I didn't noticed these issues (weren't at my notifications list), but gonna checkout the linked PR and provide extra tests for handling this case. Thank you 🚀

KingDarBoja added a commit that referenced this issue Oct 17, 2020
* Fix enable_async=True in aiohttp

Apply the fix suggested by ketanbshah in
#64

* Apply the same fix to sanic

* tests: add tests for graphiql enabled plus async

Co-authored-by: Manuel Bojato <[email protected]>
Co-authored-by: KingDarBoja <[email protected]>
@KingDarBoja
Copy link
Contributor

Next release will contain this change :) Thanks for reporting and submitting a PR.

@KingDarBoja KingDarBoja added good first issue First-time contributors that open a new issue type: bug An issue or pull request relating to a bug labels Oct 17, 2020
@KingDarBoja KingDarBoja added this to the GraphQL-Server (V3) milestone Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue First-time contributors that open a new issue type: bug An issue or pull request relating to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants