nuwave / nuwave/lighthouse

Provide event to hook when client joins a subscription channel

Open
#1,617 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

What problem does this feature proposal attempt to solve?

There's not a clear method provided to hook when a user joins a Lighthouse/GraphQL subscription channel. There are a variety of cases where this would be useful. As one example, in some use cases a race condition can exist where the client subscribes to a channel at the same time that some other job action is queued, meant to update the client as the job progresses. If the job is completed before the subscription channel can be authenticated, the client could miss a status update event. This can be solved by submitting a broadcast package immediately to users as they join the channel, but there is presently not a method provided to achieve this.

Which possible solutions should be considered?

Provide an event for when a user is authenticated on a broadcast channel which can be processed via "encodeTopic" and "filter" methods similar to the broadcast event structure, then leave it to developer to decide how to handle such cases. In the race condition case, a broadcast event could then be fired within which targets the newly joined user with a broadcast event containing the current status of the job. In other cases, this could be used to broadcast to other users when a user joins a channel (similar to what a Laravel Echo presence channel does automatically, except GraphQL/Lighthouse requires a different approach more like the above).

Unfortunately GraphQL clients like Apollo also don't provide a solution for hooking to subscription events to follow up with a good ol' API query to update the state, though this solution would itself create another less risky race condition.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Lighthouse subscription-channel authentication and the existing broadcast event structure, especially the encodeTopic and filter methods mentioned in the proposal. Done means a documented event hook is available when a user is authenticated on a channel and can target that newly joined user or other users as needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.