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

What is the difference between @ObjectType() and @InputType() in NestJS GraphQL and why can't you reuse the same class for both?

Difficulty: 5/10
GraphQL schema, NestJS decorators, type safety

@ObjectType() defines a GraphQL output type that can contain resolvers, computed fields, and relations. @InputType() defines a GraphQL input type where all fields must be serializable scalars or nested input types. They are distinct schema types and NestJS will throw a runtime error if you try to use an @ObjectType() as a mutation argument.

ObjectType vs InputType and MappedTypes bridge
Key differences:
  1. 1

    @ObjectType() — output only; can contain resolver methods, computed properties, and lazy-loaded relations.

  2. 2

    @InputType() — input only; all fields must be serializable scalars or nested @InputType() classes.

  3. 3

    GraphQL schema has separate type registries for Input and Object types — they cannot be mixed.

  4. 4

    OmitType(User, ['id'], InputType) re-registers fields from an @ObjectType() as an @InputType().

  5. 5

    PickType, PartialType, and OmitType from @nestjs/mapped-types bridge output and input types safely.

Scenario Questions

0-2 years experience

  1. 1You need to add a new mutation that creates a user. How would you define the DTO class for the mutation arguments using NestJS GraphQL decorators?
  2. 2If you accidentally annotate a class with @ObjectType instead of @InputType for a mutation argument, what runtime symptom would you expect?
  3. 3How would you share common fields between a User object type and a CreateUser input without copying code?

2-5 years experience

  1. 1During a code review you notice a teammate reused the same class for both @ObjectType and @InputType, causing schema generation to fail. Walk me through how you would diagnose and fix it.
  2. 2You need to add class‑validator decorators to a mutation input. How does using @InputType versus @ObjectType affect where those validators run?
  3. 3You have a nested object in your schema. Explain why you can't just reuse the nested @ObjectType class for the input and how you would structure the input types.

5-8 years experience

  1. 1Design a pattern for sharing common fields across many GraphQL object types and input types in a large NestJS codebase while respecting GraphQL constraints.
  2. 2Your service exposes both read and write APIs for the same domain model. Discuss the trade‑offs of keeping separate @ObjectType and @InputType classes versus using a shared base class with inheritance.
  3. 3If you need to generate TypeScript client types from your GraphQL schema, how does the separation of @ObjectType and @InputType impact the generated types and client code?

8+ years experience

  1. 1Your organization is migrating a monolithic NestJS GraphQL API to micro‑services. How would you refactor existing @ObjectType/@InputType definitions to support versioning and cross‑service contracts while avoiding duplication?
  2. 2Multiple teams need to evolve the same domain model independently. What governance or tooling would you put in place to keep @ObjectType and @InputType definitions in sync without breaking other services?
  3. 3Discuss the long‑term maintenance implications of tightly coupling business logic to GraphQL decorators, and propose an alternative architecture that decouples the domain model from schema definitions.

Follow-up Questions

  • What error would you see if you used an @ObjectType as a mutation argument?
  • Can you give an example of extending shared fields without duplicating the whole class?
  • How does this distinction affect auto‑generated TypeScript types for the client?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.