Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GraphQL module in a NestJS app.
NestJS
import { [1] } from '@nestjs/graphql';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like HttpModule.
Confusing GraphQLModule with ConfigModule.
✗ Incorrect
The GraphQLModule is the main module to integrate GraphQL in NestJS.
2fill in blank
mediumComplete the code to configure GraphQL in NestJS with code-first approach.
NestJS
GraphQLModule.forRoot({
autoSchemaFile: [1],
}), Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string filename instead of true for code-first.
Setting autoSchemaFile to false disables schema generation.
✗ Incorrect
Setting autoSchemaFile to true enables code-first schema generation.
3fill in blank
hardFix the error in the resolver decorator to define a GraphQL query.
NestJS
@[1]() export class SampleResolver { @Query(() => String) hello() { return 'Hello World'; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Controller instead of @Resolver.
Forgetting to decorate the resolver class.
✗ Incorrect
The @Resolver() decorator marks the class as a GraphQL resolver in NestJS.
4fill in blank
hardFill both blanks to define a GraphQL query method with a return type.
NestJS
import { Query, [1] } from '@nestjs/graphql'; @Resolver() export class UserResolver { @Query(() => [2]) getUser() { return 'User1'; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Mutation instead of Resolver.
Using Injectable instead of Resolver.
Using Mutation as return type.
✗ Incorrect
The Resolver decorator is imported to mark classes, and String is used as the GraphQL return type.
5fill in blank
hardFill all three blanks to create a GraphQL mutation method with an argument.
NestJS
import { Mutation, Arg, [1] } from '@nestjs/graphql'; @[2]() export class PostResolver { @Mutation(() => Boolean) createPost(@Arg('[3]') title: string) { return true; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Query instead of Resolver for the class.
Using Injectable instead of Resolver.
Mismatching argument name in @Arg.
✗ Incorrect
The Resolver decorator marks the class, and the argument name title is used in @Arg.