Performance: Subscriptions
MEDIUM IMPACT
Subscriptions impact the real-time data flow and responsiveness of the application, affecting interaction speed and server-client communication efficiency.
import { Resolver, Subscription, Args } from '@nestjs/graphql'; import { PubSub } from 'graphql-subscriptions'; const pubSub = new PubSub(); @Resolver() export class MessageResolver { @Subscription(() => String, { filter: (payload, variables) => payload.channelId === variables.channelId, }) messageAdded(@Args('channelId') channelId: string) { return pubSub.asyncIterator('messageAdded'); } }
import { Resolver, Subscription } from '@nestjs/graphql'; import { PubSub } from 'graphql-subscriptions'; const pubSub = new PubSub(); @Resolver() export class MessageResolver { @Subscription(() => String) messageAdded() { return pubSub.asyncIterator('messageAdded'); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unfiltered global subscription | N/A | 0 | Minimal paint but high JS and network load | [X] Bad |
| Filtered subscription with args | N/A | 0 | Minimal paint and reduced JS/network load | [OK] Good |