Skip to content

async for not working with subscribe() #341

Closed
@stroncod

Description

@stroncod

Describe the bug
When running the subscribe generator I get this error:

  async for res in self.client.subscribe(subscription):
TypeError: 'async for' requires an object with __aiter__ method, got generator

I'm trying to reproduce this example in the docs: https://gql.readthedocs.io/en/stable/advanced/async_advanced_usage.html
Code is fairly identical except for the client is a class member instead of a function parameter
To Reproduce
Steps to reproduce the behavior:
Run this code

class Session:
    
    @backoff.on_exception(backoff.expo, Exception, max_time=300)
    def __init__(self, url: str):
        self.client = Client(transport=WebsocketsTransport(url=f'wss://{url}/ws'))
        # self.aoi_client = Client(transport=AIOHTTPTransport(url=f'https://{url}/odb'),
        #                         fetch_schema_from_transport=True)

    async def query(self, query: gql):
        return self.client.execute(query)

    async def subscribe(self, subscription: gql):
        """
        Async generator for gql.Client.subscribe
        """
        async for res in self.client.subscribe(subscription):
            print(res)
    
    async def subscribe_all(self):
        
        await self.subscribe(observation_update)

Expected behavior
Iterate through the generator

System info (please complete the following information):

  • OS: MacOS Catalina
  • Python version: 3.9
  • gql version: latest
  • graphql-core version: latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions