0
0
NestJSframework~20 mins

Why GraphQL fits NestJS architecture - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NestJS GraphQL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does GraphQL complement NestJS's modular design?

GraphQL and NestJS both emphasize modularity. Which statement best explains why GraphQL fits well with NestJS's architecture?

AGraphQL forces all logic into a single file, which conflicts with NestJS's modularity.
BGraphQL requires global variables, which NestJS discourages, making them incompatible.
CNestJS only supports REST APIs, so GraphQL cannot be integrated.
DGraphQL's schema-first approach aligns with NestJS's modular modules and decorators, enabling clear API boundaries.
Attempts:
2 left
💡 Hint

Think about how both GraphQL and NestJS organize code and define APIs.

component_behavior
intermediate
2:00remaining
What happens when you add GraphQL module in NestJS?

In a NestJS app, you add the GraphQLModule with autoSchemaFile enabled. What is the main effect on the app's behavior?

NestJS
import { GraphQLModule } from '@nestjs/graphql';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    GraphQLModule.forRoot({
      autoSchemaFile: true,
    }),
  ],
})
export class AppModule {}
AThe app switches to REST API mode and disables GraphQL features.
BGraphQL queries are ignored and only REST endpoints work.
CNestJS generates a GraphQL schema automatically from resolvers and serves a GraphQL playground.
DThe app throws a runtime error because autoSchemaFile is not supported.
Attempts:
2 left
💡 Hint

Consider what autoSchemaFile does in NestJS GraphQL setup.

lifecycle
advanced
2:00remaining
How does NestJS lifecycle support GraphQL resolver execution?

Which NestJS lifecycle hook is best suited to initialize resources before a GraphQL resolver handles a request?

AonApplicationBootstrap() - runs after the app starts but after resolvers execute.
BonModuleInit() - runs once when the module is initialized, before any resolver runs.
CbeforeApplicationShutdown() - runs after all resolvers finish processing.
DonModuleDestroy() - runs before the module is destroyed, unrelated to resolver execution.
Attempts:
2 left
💡 Hint

Think about when you want to prepare resources before any resolver runs.

📝 Syntax
advanced
2:00remaining
Identify the correct GraphQL resolver syntax in NestJS

Which code snippet correctly defines a GraphQL query resolver in NestJS?

NestJS
import { Resolver, Query } from '@nestjs/graphql';

@Resolver()
export class SampleResolver {
  @Query(() => String)
  hello() {
    return 'Hello World';
  }
}
AThe code correctly defines a GraphQL query resolver returning a string.
BThe @Query decorator is missing a required name parameter, causing a syntax error.
CThe resolver method must be async, so this code will cause a runtime error.
DThe @Resolver decorator requires a type argument, so this code is invalid.
Attempts:
2 left
💡 Hint

Check the NestJS GraphQL docs for minimal resolver syntax.

🔧 Debug
expert
3:00remaining
Why does this NestJS GraphQL resolver throw a runtime error?

Given this resolver code, why does the app throw a runtime error when querying 'greet'?

NestJS
import { Resolver, Query } from '@nestjs/graphql';

@Resolver()
export class GreetResolver {
  @Query(() => String)
  greet() {
    return this.message.toUpperCase();
  }

  private message: string;
}
AThe 'message' property is undefined because it was never initialized, causing a runtime error.
BThe @Query decorator is missing parentheses, causing a syntax error.
CThe method greet() must be async to return a string, so this causes a runtime error.
DThe @Resolver decorator requires a type argument, so this code is invalid.
Attempts:
2 left
💡 Hint

Check if all properties used in the method have values before use.