0
0
NestJSframework~5 mins

Object types and input types in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an Object Type in NestJS GraphQL?
An Object Type defines the shape of data that the GraphQL API returns. It is a class decorated with @ObjectType() that describes fields and their types for the API response.
Click to reveal answer
beginner
What is an Input Type in NestJS GraphQL and how is it used?
An Input Type is a class decorated with @InputType() used to define the shape of data sent by clients to the API, such as arguments for mutations or queries.
Click to reveal answer
beginner
How do you define a simple Object Type with two fields: id (number) and name (string)?
Use a class with @ObjectType() and decorate fields with @Field(). Example:
@ObjectType()
class User {
  @Field()
  id: number;

  @Field()
  name: string;
}
Click to reveal answer
intermediate
Why should Input Types be separate from Object Types in NestJS GraphQL?
Separating Input Types from Object Types helps keep input validation clear and prevents exposing internal fields in API responses. It also avoids circular references.
Click to reveal answer
intermediate
How do you reuse fields between Object Types and Input Types in NestJS?
You can create a base class with shared fields and extend it in both @ObjectType() and @InputType() classes to avoid repeating code.
Click to reveal answer
Which decorator is used to define an Object Type in NestJS GraphQL?
A@ObjectType()
B@InputType()
C@Entity()
D@Controller()
What decorator marks a class as an Input Type in NestJS GraphQL?
A@Field()
B@Input()
C@ArgsType()
D@InputType()
Why should Input Types and Object Types be separate in NestJS GraphQL?
ATo improve database performance
BTo reduce server memory usage
CTo avoid exposing internal fields and circular references
DTo enable REST API compatibility
Which decorator is used to define fields inside Object or Input Types?
A@Column()
B@Field()
C@Property()
D@Param()
How can you reuse fields between Object Types and Input Types in NestJS?
ABy using inheritance with a shared base class
BBy copying code manually
CBy using interfaces only
DBy using decorators only
Explain the difference between Object Types and Input Types in NestJS GraphQL and why both are important.
Think about what data the server sends versus what it receives.
You got /4 concepts.
    Describe how to create a reusable set of fields for both Object Types and Input Types in NestJS.
    Consider how inheritance works in classes.
    You got /4 concepts.