0
0
NestJSframework~10 mins

Why GraphQL fits NestJS architecture - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AHttpModule
BConfigModule
CGraphQLModule
DDatabaseModule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like HttpModule.
Confusing GraphQLModule with ConfigModule.
2fill in blank
medium

Complete 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'
Atrue
Bfalse
C'schema.gql'
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string filename instead of true for code-first.
Setting autoSchemaFile to false disables schema generation.
3fill in blank
hard

Fix 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'
AModule
BController
CInjectable
DResolver
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Controller instead of @Resolver.
Forgetting to decorate the resolver class.
4fill in blank
hard

Fill 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'
AResolver
BMutation
CString
DInjectable
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Mutation instead of Resolver.
Using Injectable instead of Resolver.
Using Mutation as return type.
5fill in blank
hard

Fill 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'
AResolver
BQuery
Ctitle
DInjectable
Attempts:
3 left
💡 Hint
Common Mistakes
Using Query instead of Resolver for the class.
Using Injectable instead of Resolver.
Mismatching argument name in @Arg.