Questions
3 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?
03 / 25

How does NestJS schema-first approach differ in setup and when would you choose it over code-first?

Schema-first uses typePaths to point at .graphql SDL files and a definitions config to generate TypeScript interfaces from them. Resolvers reference the generated types. Choose schema-first when the SDL is the team's API contract or when frontend developers write the schema and backend implements against it.

Schema-first setup and resolver
Schema-first vs code-first decision guide:
  1. 1

    Choose schema-first when the SDL is the team's shared API contract (API-design-first workflow).

  2. 2

    Choose schema-first when frontend developers write the schema and backend implements against it.

  3. 3

    Choose code-first when TypeScript is the single source of truth and you want full IDE support.

  4. 4

    Schema-first risk: interface drift — SDL and generated TypeScript can diverge if code generation is skipped.

  5. 5

    Code generation must be re-run whenever the SDL changes — automate this in CI.

Difficulty: 5/10
Topics: schema-first vs code-first, GraphQL SDL integration, type generation

Scenario Questions

0-2 years experience
  1. 1

    You need to add a new GraphQL query to a NestJS service using the schema‑first approach. Walk me through the files you would create or modify and how NestJS wires them together.

  2. 2

    If you forget to import the generated GraphQL types module after switching to schema‑first, what runtime error would you see and why?

2-5 years experience
  1. 1

    We have an existing NestJS code‑first GraphQL API, and the product wants to expose a third‑party SDL file. How would you migrate the relevant parts to schema‑first, and what pitfalls might cause mismatched resolvers?

  2. 2

    During a sprint a teammate added a new field to the SDL but the corresponding resolver never fired. How would you debug that issue in a schema‑first setup?

5-8 years experience
  1. 1

    At scale we have dozens of microservices each exposing GraphQL schemas. Discuss the trade‑offs of using schema‑first across services versus code‑first, focusing on build pipelines, type safety, and runtime performance.

  2. 2

    Suppose you need to generate TypeScript types from a large SDL for validation in a NestJS gateway. What design would you choose to keep the generated types in sync without slowing CI, and why might schema‑first be advantageous here?

8+ years experience
  1. 1

    Our organization is consolidating multiple legacy GraphQL services, some built with schema‑first, others with code‑first. Propose a migration strategy that minimizes downtime and maintains contract stability, and argue when you would keep schema‑first for new services.

  2. 2

    If we plan to expose the GraphQL API to external partners and want to version the contract, how does choosing schema‑first affect our versioning, documentation, and cross‑team governance compared to code‑first?

Follow-up Questions

  • What are the main drawbacks of schema‑first in a fast‑changing codebase?
  • How does NestJS handle input validation when using a schema‑first approach?
  • Can you mix schema‑first and code‑first in the same project, and what issues might arise?