Is it possible to define an Object inside InputType? or can i define an InputType inside an InputType?

346 views Asked by At

A survey contains an array of question. Is it possible to have an array of InputType or Question?

@InputType()
export class SurveyInput {
  @Field(() => String)
  name: string
  @Field(() => String)
  status: string
  @Field(() => String)
  category: string
  @Field(() => String)
  initiativeId: string
  @Field(() => QuestionInput)
  questions: QuestionInput[]
}
@InputType()
export class QuestionInput {
  @Field(() => String)
  question: string
  @Field(() => String)
  maxPoint: number
}
1

There are 1 answers

0
Ahmad Alhaj-Karim On

That's how i solved it at the end

@InputType()
export class SurveyInput {

  @Field(() => String)
  name: string
  @Field(() => String)
  status: string
  @Field(() => String)
  category: string
  @Field(() => String)
  initiativeId: string

  @Field(() => [QuestionInput])
  questions: QuestionInput[]
}


@InputType()
export class QuestionInput {

  @Field(() => String)
  question: string

  @Field(() => Number)
  maxPoint: number
}