Challenge - 5 Problems
NestJS GraphQL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this NestJS GraphQL query resolver?
Consider this NestJS GraphQL query resolver code. What will be the output when the query
getGreeting is called?NestJS
import { Query, Resolver } from '@nestjs/graphql'; @Resolver() export class GreetingResolver { @Query(() => String) getGreeting(): string { return 'Hello, NestJS!'; } }
Attempts:
2 left
💡 Hint
Look at the return value inside the
getGreeting method.✗ Incorrect
The
getGreeting method returns the string 'Hello, NestJS!'. The GraphQL query will return this exact string.📝 Syntax
intermediate2:00remaining
Which option correctly defines a mutation to add a user in NestJS GraphQL?
You want to create a mutation named
addUser that accepts a name string and returns a boolean. Which code snippet is correct?Attempts:
2 left
💡 Hint
Mutations use the @Mutation decorator and arguments must be decorated with @Args.
✗ Incorrect
Option A correctly uses @Mutation with a return type and decorates the argument with @Args. Other options either use @Query or miss @Args decorator.
❓ state_output
advanced2:00remaining
What is the value of
userCount after these mutations?Given this NestJS resolver code, what is the value of
userCount after calling addUser twice?NestJS
import { Mutation, Resolver } from '@nestjs/graphql'; @Resolver() export class UserResolver { private userCount = 0; @Mutation(() => Number) addUser(): number { this.userCount += 1; return this.userCount; } }
Attempts:
2 left
💡 Hint
Each call to addUser increases userCount by 1 and returns it.
✗ Incorrect
The private variable userCount starts at 0. Each mutation call increments it by 1. After two calls, userCount is 2.
🔧 Debug
advanced2:00remaining
What error does this NestJS GraphQL mutation code produce?
This mutation is intended to update a user's email but causes an error. What error is raised?
NestJS
import { Mutation, Args, Resolver } from '@nestjs/graphql'; @Resolver() export class UserResolver { @Mutation(() => Boolean) updateEmail(@Args('email') email: string): boolean { this.email = email; return true; } }
Attempts:
2 left
💡 Hint
Check if 'this.email' is defined in the class.
✗ Incorrect
The class does not define 'email' property, so 'this.email = email' causes a TypeScript compile error: Property 'email' does not exist on type 'UserResolver'.
🧠 Conceptual
expert2:00remaining
Which statement best describes the difference between queries and mutations in NestJS GraphQL?
Choose the most accurate description of queries and mutations in NestJS GraphQL.
Attempts:
2 left
💡 Hint
Think about what each operation does to data.
✗ Incorrect
Queries are for reading data without changing it. Mutations change data and can have side effects like updating a database.