Challenge - 5 Problems
NestJS Code-First 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 code-first resolver?
Consider this NestJS GraphQL resolver using the code-first approach. What will be the GraphQL query response for
hello()?NestJS
import { Resolver, Query } from '@nestjs/graphql'; @Resolver() export class HelloResolver { @Query(() => String) hello() { return 'Hello, NestJS!'; } }
Attempts:
2 left
💡 Hint
Look at the method name and the returned string value.
✗ Incorrect
The resolver defines a query named 'hello' that returns the string 'Hello, NestJS!'. The GraphQL response wraps this in a 'data' object with the query name as the key.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a GraphQL ObjectType with a field in NestJS code-first?
You want to create a GraphQL ObjectType named
Cat with a string field name. Which code snippet is correct?Attempts:
2 left
💡 Hint
Remember the decorator syntax and type hints for fields.
✗ Incorrect
Option B correctly uses @ObjectType() and @Field() decorators. The field 'name' is a string and @Field() without arguments defaults to String type.
❓ state_output
advanced2:00remaining
What is the output of this NestJS code-first mutation resolver?
Given this mutation resolver, what will be the GraphQL mutation response when calling
incrementCounter twice?NestJS
import { Resolver, Mutation } from '@nestjs/graphql'; @Resolver() export class CounterResolver { private count = 0; @Mutation(() => Number) incrementCounter() { this.count += 1; return this.count; } }
Attempts:
2 left
💡 Hint
Think about the private variable and how it changes with each call.
✗ Incorrect
The private variable 'count' starts at 0 and increments by 1 each time the mutation is called, so the first call returns 1 and the second returns 2.
🔧 Debug
advanced2:00remaining
What error does this NestJS code-first resolver produce?
Examine this resolver code. What error will occur when the GraphQL server starts?
NestJS
import { Resolver, Query } from '@nestjs/graphql'; @Resolver() export class SampleResolver { @Query(() => String) greet() { return 123; } }
Attempts:
2 left
💡 Hint
Look at the return type declared and the actual returned value.
✗ Incorrect
The @Query decorator expects a string return type, but the method returns a number, causing a type mismatch error.
🧠 Conceptual
expert2:00remaining
Why is the code-first approach beneficial in NestJS GraphQL development?
Choose the best explanation for the main advantage of using the code-first approach in NestJS GraphQL.
Attempts:
2 left
💡 Hint
Think about how code-first relates to TypeScript and schema generation.
✗ Incorrect
Code-first uses TypeScript classes and decorators to generate GraphQL schema, improving type safety and developer experience.