Questions
4 of 25
1How do you bootstrap a NestJS GraphQL application in code-first mode?
2How do you define a GraphQL object type, enum, and union in code-first NestJS?
3How does NestJS schema-first approach differ in setup and when would you choose it over code-first?
4How do you implement a subscription using PubSub in NestJS GraphQL?
5What is the N+1 problem in GraphQL and how does DataLoader solve it?
6How do you make a DataLoader available in the GraphQL context so every resolver can access it in NestJS?
7How do you handle DataLoader cache invalidation and avoid serving stale data in NestJS?
8How do you pass arguments to a GraphQL query and validate them using @Args and input types in NestJS?
9How do you define a GraphQL mutation in NestJS and what input type conventions should you follow?
10What is the difference between @ObjectType() and @InputType() in NestJS GraphQL and why can't you reuse the same class for both?
11How do you add authorization guards to GraphQL resolvers in NestJS?
12How do you implement query complexity analysis to prevent expensive GraphQL queries in NestJS?
13How do you test a NestJS GraphQL resolver with TestingModule?
14How do you implement and use a custom GraphQL scalar type in NestJS?
15How do you handle GraphQL errors and return partial results for mutations in NestJS?
16How do you filter subscription events so each client only receives events relevant to them in NestJS?
17How do you implement schema stitching or federation for a micro-frontend GraphQL architecture in NestJS?
18What is the difference between code-first and schema-first approaches in NestJS GraphQL?
19What is a resolver in NestJS GraphQL and how do you define a root query resolver?
20What are field resolvers in NestJS GraphQL and when do you use them instead of fetching all data in the root query?
21How do you access the GraphQL context including the authenticated user inside a resolver in NestJS?
22What is a GraphQL subscription and how do you enable it in NestJS?
23How do you scale GraphQL subscriptions across multiple NestJS instances?
24How do you implement a DataLoader in NestJS and scope it correctly per request?
25How do you implement cursor-based pagination in NestJS GraphQL using the Relay Connection spec?
04 / 25

How do you implement a subscription using PubSub in NestJS GraphQL?

Register PubSub as a provider using an injection token. In the mutation, publish the event after the write. In the subscription resolver method, return pubSub.asyncIterator() with the event name. The @Subscription() return type arrow function and the event payload key must match the asyncIterator event name.

PubSub subscription with publish and subscribe
PubSub subscription rules:
  1. 1

    Register PubSub with an injection token — inject it into resolvers via @Inject(PUB_SUB).

  2. 2

    The object key in publish() must match the subscription field name: { postCreated: post }.

  3. 3

    asyncIterator() argument must match the event name used in publish().

  4. 4

    In-memory PubSub works only in single-process deployments — use Redis PubSub for multiple instances.

  5. 5

    Publish after the database write completes — never publish on a failed or rolled-back write.

Difficulty: 5/10
Topics: GraphQL Subscriptions, NestJS PubSub, Resolver design

Scenario Questions

0-2 years experience
  1. 1

    We need a simple real‑time chat feature where a client subscribes to new messages. Walk me through how you'd set up a GraphQL subscription using NestJS's PubSub in a single module.

  2. 2

    If you forget to call pubSub.publish after creating a message, what will the subscriber see and why?

  3. 3

    How would you write a unit test to verify that your subscription resolver receives the published events?

2-5 years experience
  1. 1

    Our product team wants to add a subscription for order status updates, but the status changes are emitted from a separate microservice via a message queue. How would you integrate that with NestJS PubSub and what trade‑offs would you consider?

  2. 2

    During a load test, you notice that some subscription events are being dropped. What debugging steps would you take in the NestJS GraphQL layer?

  3. 3

    Explain why you might choose NestJS's built‑in PubSub versus an external Redis PubSub adapter in a mid‑scale deployment.

5-8 years experience
  1. 1

    Design a scalable subscription system for a live dashboard that streams metrics from thousands of devices. How would you structure the PubSub, resolver, and any back‑pressure handling in NestJS?

  2. 2

    What are the implications of using the default in‑memory PubSub in a horizontally scaled NestJS cluster, and how would you modify the architecture to support multiple instances?

  3. 3

    How would you secure subscription connections to ensure only authorized users receive events, and what changes are needed in the GraphQL subscription handshake?

8+ years experience
  1. 1

    Our organization is moving from a monolith to a micro‑frontend architecture, and we need to migrate existing GraphQL subscriptions to a shared event bus. What architectural changes would you propose for the NestJS PubSub layer to avoid coupling and support versioned schemas?

  2. 2

    Consider long‑term maintenance of subscription contracts across several teams. How would you establish a strategy for deprecating fields, handling breaking changes, and ensuring backward compatibility in the NestJS GraphQL subscription implementation?

  3. 3

    If we wanted to replace the PubSub implementation with a cloud‑native service like AWS AppSync, what migration path would you outline, and what pitfalls should we watch for in the existing NestJS codebase?

Follow-up Questions

  • What would you monitor in production to ensure the subscription pipeline stays healthy?
  • Can you compare the performance characteristics of in‑memory PubSub versus Redis?
  • How does the GraphQL subscription handshake differ from a regular query in NestJS?