Skip to content

Add ClsInterceptor to avoid having to use enterWith with GraphQL #5

@andreialecu

Description

@andreialecu

Hey there, just came across this library while investigating my own issues with AsyncLocalStorage losing context inside graphql interceptors.

I'm not (yet) using this library, I have a custom implementation, but I wanted to mention that I eventually got it working via this pattern in the interceptor:

  intercept(...) {
    return new Observable((observer) => {
      storage.run(myContext, () => {
        next
          .handle()
          .pipe(...)
          .subscribe({
            next: (res) => observer.next(res),
            error: (error) => observer.error(error),
            complete: () => observer.complete(),
          });
      });
    });
  }

Seems that wrapping the return in a cold observable is necessary, but this is all that I needed to do.

With this I can use run instead of enterWith, which I noticed was mentioned as a caveat in the readme about not being supported.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions