boostercloud / booster

Booster Framework
https://www.boosterframework.com
Apache License 2.0
414 stars 86 forks source link

Add support for Server-Side Events in commands #1364

Open javiertoledo opened 1 year ago

javiertoledo commented 1 year ago

Feature Request

Description

It would be nice to have a way to use Server-Side Events (SSE) in commands. SSE is a technology that allows a client to receive partial real-time updates from a server using an HTTP connection that is kept alive during the process. This feature can be useful for client applications that need to implement partial updates as some long-during action is performed.

For example, imagine a command that triggers a complex workflow that involves multiple steps and takes some time to complete. The client application could use SSE to receive notifications about the progress of each step and update the UI accordingly.

Possible Solution

One possible solution is to add a new method to the Register class that allows sending events to the client. For example:

@Command({
  authorize: 'all'
})
export class MyCommand {
  public constructor(
    readonly field1: string,
    readonly field2: string
  ) {}

  public async handle(register: Register): Promise<void> {
    // Do some initial work
    register.sendEvent('Step 1 completed')
    // Do some more work
    register.sendEvent('Step 2 completed')
    // Finalize work
    register.sendEvent('Done')
  }
}

The sendEvent method would deliver the events to the client via SSE.

Additional information

There is an open question about how to implement SSE over GraphQL, since Booster Framework uses GraphQL mutations to access commands. There are two possible options:

It would be a good idea to perform a small research on these options and decide which one is more suitable or if there are other options.

Virajjai commented 1 month ago

Hi @javiertoledo can i work on this and could you please explain a bit more.