Skip to content
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

[bug report] Can't run a subscription in local. #112

Closed
Boblebol opened this issue Sep 10, 2020 · 6 comments · Fixed by #113
Closed

[bug report] Can't run a subscription in local. #112

Boblebol opened this issue Sep 10, 2020 · 6 comments · Fixed by #113

Comments

@Boblebol
Copy link

Bug Report

Presentation

I try to create a subscription in my api, i can't make it work.
I try to run a subscription with the tutorial example to be sure it's come from my configuration, but I can't make it work too.

Execution environment

  • tartiflette: 1.2.1
  • tartiflette-aiohttp: 1.3.0
  • Python: 3.7.5
  • Executed in docker: No

GraphQL Schema & Query:

I follow the getting started up to step 10. Running a subscription.

So my schema for the subscription is

enum CookingStatus {
  COOKING
  COOKED
}

type CookingTimer {
  remainingTime: Int!
  status: CookingStatus!
}

type Subscription {
  launchAndWaitCookingTimer(id: Int!): CookingTimer
}

I try with multiple python clients and graphiql.

from gql import gql, Client, WebsocketsTransport

transport = WebsocketsTransport(url='wss://localhost:8080/graphql')

client = Client(
    transport=transport,
    fetch_schema_from_transport=True,
)

query = gql('''
    subscription {
  launchAndWaitCookingTimer(id: 1) {
    remainingTime
    status
  }
}
''')

for result in client.subscribe(query):
    print (result)
from graphql_client import GraphQLClient

query = """
   subscription {
  launchAndWaitCookingTimer(id: 1) {
    remainingTime
    status
  }
}
"""

def callback(_id, data):
    print("got new data..")
    print(f"msg id: {_id}. data: {data}")

with GraphQLClient('wss://localhost:8080') as client:
    sub_id = client.subscribe(query, callback=callback)
    client.stop_subscribe(sub_id)
from python_graphql_client import GraphqlClient

# Instantiate the client with a websocket endpoint.
client = GraphqlClient(endpoint="wss://localhost:8080/ws")

# Create the query string and variables required for the request.
query = """
   subscription {
  launchAndWaitCookingTimer(id: 1) {
    remainingTime
    status
  }
}
"""

# Asynchronous request
import asyncio

data = asyncio.run(client.subscribe(query=query, handle=print))

Stack trace

With each client or graphiql for each subscription the tartiflette server gave me the same error:

======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
Error handling request
Traceback (most recent call last):
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 158, in handler_wrapper
    return await result
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/tartiflette_aiohttp/_subscription_ws_handler.py", line 265, in __call__
    self._context = await self._context_factory(request)
TypeError: object _AsyncGeneratorContextManager can't be used in 'await' expression
Error handling request
Traceback (most recent call last):
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 158, in handler_wrapper
    return await result
  File "/home/alex/.pyenv/versions/product-api/lib/python3.7/site-packages/tartiflette_aiohttp/_subscription_ws_handler.py", line 265, in __call__
    self._context = await self._context_factory(request)
TypeError: object _AsyncGeneratorContextManager can't be used in 'await' expression

The Previous error does not make the client quit or stop, and my query and mutations works fine with clients or graphiql.

On clientside I have the following stack trace

$ python test_subscription.py
### waiting for 1 minute with nothing then the followin error append 
Traceback (most recent call last):
  File "recipes_manager/test_query.py", line 19, in <module>
    for result in client.subscribe(query):
  File "/home/alex/.pyenv/versions/tartiflette/lib/python3.7/site-packages/gql/client.py", line 176, in subscribe
    loop.run_until_complete(generator_task)
  File "/home/alex/.pyenv/versions/3.7.5/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
    return future.result()
  File "/home/alex/.pyenv/versions/tartiflette/lib/python3.7/site-packages/gql/client.py", line 164, in subscribe
    result = loop.run_until_complete(generator_task)
  File "/home/alex/.pyenv/versions/3.7.5/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
    return future.result()
  File "/home/alex/.pyenv/versions/tartiflette/lib/python3.7/site-packages/gql/client.py", line 132, in subscribe_async
    async with self as session:
  File "/home/alex/.pyenv/versions/tartiflette/lib/python3.7/site-packages/gql/client.py", line 189, in __aenter__
    await self.transport.connect()
  File "/home/alex/.pyenv/versions/tartiflette/lib/python3.7/site-packages/gql/transport/websockets.py", line 514, in connect
    websockets.connect(self.url, **connect_args,), self.connect_timeout,
  File "/home/alex/.pyenv/versions/3.7.5/lib/python3.7/asyncio/tasks.py", line 449, in wait_for
    raise futures.TimeoutError()
concurrent.futures._base.TimeoutError

And the result on graphiql:
image

Conclusion

Do you have any idea why I can't run some subscription ?
Thank's by advance.

@abusi
Copy link
Contributor

abusi commented Sep 10, 2020

Hi ! Thanks for this bug report, i'll look at it.

@abusi
Copy link
Contributor

abusi commented Sep 23, 2020

@Boblebol I'll transfer this issue to Tartiflette-aiohttp, the bug is there :p.
fix is incoming soon, sorry for the delays.

@abusi abusi transferred this issue from tartiflette/tartiflette Sep 23, 2020
@Boblebol
Copy link
Author

Thank's a lot 👍

@abusi
Copy link
Contributor

abusi commented Sep 24, 2020

@Boblebol It seems to do the job for me, can you tell me if it's okay for you ?

@upcFrost
Copy link

+1

tried the fix from the PR locally, works ok for me

@Boblebol
Copy link
Author

@abusi working for me too 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants