0
0
NestJSframework~10 mins

Object types and input types in NestJS - Interactive Code Practice

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

Complete 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'
Aboolean
Bnumber
Cstring
DDate
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean for a text field.
Forgetting to specify the type.
2fill in blank
medium

Complete 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'
Astring
Bnumber
Cboolean
DDate
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-string type for email.
Not marking the field as optional.
3fill in blank
hard

Fix 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'
AString
BDate
CNumber
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using TypeScript types instead of GraphQL types in the decorator.
Omitting the type function in the decorator.
4fill in blank
hard

Fill 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'
AString
Bstring[]
CBoolean
Dnumber[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using Boolean or number types instead of string.
Not matching GraphQL and TypeScript types.
5fill in blank
hard

Fill 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'
Astring
Bnumber
CInt
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing TypeScript and GraphQL types incorrectly.
Using lowercase 'number' in GraphQL decorator.