vendure icon indicating copy to clipboard operation
vendure copied to clipboard

GraphQL Subscriptions

Open michakfromparis opened this issue 1 year ago • 0 comments

As a headless platform, I believe vendure would greatly benefit from an idiomatic way to register new graphql subscriptions. This would allow the admin UI to avoid polling and immediately react to data changes.

Some users have managed to get them working https://github.com/vendure-ecommerce/vendure/discussions/1879 but my personal recent attempts were unfruitful.

What seems to be the approach that is most aligned with vendure's coding standards / architecture would be to use the nest resolver decorators so @Subscription can sit along @Mutation & @Query like in the example below

@Resolver('Entity')
export class EntityResolver {

  @Query('entity')
  @Transaction()
  async entity(@Args('id') id: number) {
    ...
  }

  @Mutation('deleteEntity')
  @Transaction()
  async deleteEntity(@Args('id') id: number) {
    ...
  }

  @Subscription('entityDeleted')
  async entityDeleted() {
    ...
  }
}

michakfromparis avatar Aug 30 '23 07:08 michakfromparis