Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a simple input type using NestJS GraphQL decorators.
NestJS
import { InputType, Field } from '@nestjs/graphql'; @InputType() export class CreateUserInput { @Field() name: [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean for a text field.
Forgetting to specify the type.
✗ Incorrect
The 'name' field should be a string type to accept text input for the user's name.
2fill in blank
mediumComplete the code to add an optional email field to the input type.
NestJS
import { InputType, Field } from '@nestjs/graphql'; @InputType() export class UpdateUserInput { @Field({ nullable: true }) email?: [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-string type for email.
Not marking the field as optional.
✗ Incorrect
Email addresses are text, so the type should be string. The field is optional with '?' and nullable true.
3fill in blank
hardFix the error in the input type by completing the decorator to specify the field type explicitly.
NestJS
import { InputType, Field, Boolean } from '@nestjs/graphql'; @InputType() export class FilterUserInput { @Field(() => [1]) isActive: boolean; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using TypeScript types instead of GraphQL types in the decorator.
Omitting the type function in the decorator.
✗ Incorrect
The @Field decorator needs the GraphQL Boolean type for a boolean field.
4fill in blank
hardFill both blanks to create an input type with a list of strings field.
NestJS
import { InputType, Field } from '@nestjs/graphql'; @InputType() export class TagsInput { @Field(() => [[1]]) tags: [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Boolean or number types instead of string.
Not matching GraphQL and TypeScript types.
✗ Incorrect
The GraphQL type for a list of strings is [String], and the TypeScript type is string[].
5fill in blank
hardFill all three blanks to define an input type with street, city, and zipCode fields.
NestJS
import { InputType, Field, Int } from '@nestjs/graphql'; @InputType() export class AddressInput { @Field() street: [1]; @Field() city: [2]; @Field(() => [3]) zipCode: number; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing TypeScript and GraphQL types incorrectly.
Using lowercase 'number' in GraphQL decorator.
✗ Incorrect
Street and city are text fields, so TypeScript type is string. zipCode is a number, so GraphQL type is Int.