question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscription error

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

{
  "error": {
    "message": "Subscription field must return Async Iterable. Received: { pubsub: { ee: [Object], subscriptions: {}, subIdCounter: 0 }, pullQueue: [], pushQueue: [], running: true, allSubscribed: null, eventsArray: [\"onCategory\"] }"
  }
}

Expected behavior

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

  @Subscription(() => [Category])
  public onCategory() {
    return pubSub.asyncIterator('onCategory');
  }

Environment


Nest version: 6.8.2

 
For Tooling issues:
- Node version: v12.11.1  
- Platform:  macOS Catalina

Others:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
rmaes4commented, Apr 14, 2020

Just stumbled across this and ran into the same issue. My solution was to extend ClassSerializerInterceptor and basically have it apply to everything except GQL subscriptions. This way I won’t have to manually add decorators all around my code base minus subscription resolvers and instead I can register it as a global interceptor.

my-class-serializer.interceptor.ts

import {
  CallHandler,
  ClassSerializerInterceptor,
  ExecutionContext,
  Injectable
} from '@nestjs/common';
import { Observable } from 'rxjs';

@Injectable()
export class MyClassSerializerInterceptor extends ClassSerializerInterceptor {
  constructor(protected readonly reflector: any) {
    super(reflector);
  }
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    if ((context.getType() as string) === 'graphql') {
      const op = context.getArgByIndex(3).operation.operation;
      if (op === 'subscription') {
        return next.handle();
      }
    }
    return super.intercept(context, next);
  }
}

And register it like so

main.ts

...
app.useGlobalInterceptors(
    new MyClassSerializerInterceptor(app.get(Reflector))
  );
...
0reactions
Simolationcommented, May 24, 2022

It works when excluding all subscriptions from the serializer, but what if I want the response to be serialized? I have fields which need to be transformed, but I can’t do that as the serializer tries to transform the AsyncIterable. When doing the serialization in resolve it does work, but how do I serialize additional resolved values which are not included in the data which is transported over the PubSub?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 - Checking for server errors from subscribe
subscribe() method can take a third argument that is called on completion if there are no errors. For reference: [onNext] ( Function ):...
Read more >
Fix problems with subscriptions - Android - Google Play Help
Find missing subscriptions If you can't find your subscriptions, check that you're signed in to the correct account. Make sure to sign in...
Read more >
RxJs Error Handling: Complete Practical Guide
In this post, we will cover the following topics: The Observable contract and Error Handling; RxJs subscribe and error callbacks; The catchError ...
Read more >
Subscription Error Message on Account Page
This error will be triggered whenever a user's subscription has become Inactive AND when their Auto-Rebill is set to Enabled.
Read more >
We've run into a problem with your Microsoft 365 subscription
Provides troubleshooting steps to fix the "We've run into a problem with your Microsoft 365 subscription, and we need your help to fix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found