0
0
NestJSframework~5 mins

Queries and mutations in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a query in NestJS GraphQL?
A query is a way to ask the server for data without changing anything. It fetches information and returns it to you.
Click to reveal answer
beginner
What is a mutation in NestJS GraphQL?
A mutation is a request to change data on the server, like adding, updating, or deleting something.
Click to reveal answer
intermediate
How do you define a query method in a NestJS resolver?
Use the @Query() decorator above a method inside a resolver class. This method returns the data requested.
Click to reveal answer
intermediate
How do you define a mutation method in a NestJS resolver?
Use the @Mutation() decorator above a method inside a resolver class. This method performs data changes and returns the result.
Click to reveal answer
beginner
Why should queries not change data and mutations should?
Queries are for reading data only to keep things safe and predictable. Mutations change data because they represent actions that modify the server state.
Click to reveal answer
Which decorator is used to define a query in a NestJS GraphQL resolver?
A@Resolver()
B@Query()
C@Mutation()
D@Controller()
What does a mutation do in NestJS GraphQL?
AChanges data on the server
BFetches data without changes
CDefines a new GraphQL type
DHandles HTTP requests
Where do you place the @Mutation() decorator in NestJS?
AAbove a service method
BAbove a controller method
CAbove a resolver method
DAbove a module class
Which of these is true about queries?
AThey fetch data without side effects
BThey modify data
CThey are only used in REST APIs
DThey require authentication always
In NestJS GraphQL, what is the purpose of a resolver?
ATo style the UI components
BTo handle HTTP requests
CTo store data in the database
DTo define how queries and mutations fetch or change data
Explain how queries and mutations differ in NestJS GraphQL and how you define them in a resolver.
Think about reading vs changing data and the decorators used.
You got /5 concepts.
    Describe why it is important to separate queries and mutations in GraphQL and how this helps in building APIs with NestJS.
    Consider safety, clarity, and API design benefits.
    You got /5 concepts.