Skip to content

Phoenix transport: breaking early from async generator loop requires canceling receive_data_task #225

Closed
@pzingg

Description

@pzingg

I don't know if there is a Slack channel or other forum for the gql project, so I'm posing this here as an issue. I would like to see an example of a subscription that uses one of the async transports (such as PhoenixChannelWebsocketsTransport) for the use case below. It's something that I had working with gql 2.x, after adding my own (probably naive) implementation of Phoenix channels. The target server is Absinthe GraphQL.

The inputs for the process are:

  • a mutation document and variables
  • a subscription document and variables (subscription updates are triggered by the mutation)
  • a coroutine (or asyncio task?) that can act on each subscription update received, as indicated below
  • an optional timeout, after which the subscription will be ended

Then the process is:

  1. Send a subscription request with the coroutine as a parameter.
  2. If the subscription is successful, send a mutation request that will trigger subscription updates.
  3. As each update arrives on the subscription (inside an async generator for loop), the coroutine acts on it (for example printing, or parsing the ExecutionResult and processing results). The coroutine may also, as it parses an update, decide to end the subscription if it decides that no more updates are expected, and return any data it wants.
  4. If the timeout is exceeded, the process will unsubscribe, and return any results collected by the coroutine, as well as an indication that the process ended via a timeout.

It looks like the standard way a subscription is ended is when it receives a "complete" message on the websocket, but in my case I want the client to decide when to stop subscribing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugAn issue or pull request relating to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions