Type-graphql: Failure while deserializing an input type with a nested array field

Created on 1 Mar 2021  路  7Comments  路  Source: MichalLytek/type-graphql

Describe the Bug
While trying to pass an input with a nested array field, the object comes up empty on the resolver

To Reproduce

@ObjectType()
@InputType('InnerInput')
export class Inner {
  @Field((type) => String)
  aString: string

  @Field((type) => Int)
  aNumber: number
}
@InputType()
export class Outer {
  @Field((type) => [[Inner]])
  nested: Inner[][]
}



md5-51b8bceea54167a15a848aa646ac3e53



@Resolver()
export class TestResolver {
  @Query((type) => Inner)
  test(@Arg('input', (type) => Outer) input: Outer) {
    return input[0][0].nested
  }
}



md5-aa2ce18a929323f4ba221075d257cdb2



{
  test(input: {nested: [[{aString: "test", aNumber: 90}]]}) {
    aString
    aNumber
  }
}

Expected Behavior
The query should return the object {aString: "test", aNumber: 90}. Instead, it returns the error "Cannot read property '0' of undefined"

Environment (please complete the following information):

  • OS: Windows 10 build 19042.844
  • Node 14.15.5
  • Package version 1.1.1
  • TypeScript version 4.2.2
Bug Community Solved

All 7 comments

Yes, I know the nested array on Arg passed, but this is not the same:

@Arg('input', (type) => Outer)

this is a nested array inside the InputType decorated class
vs

@Arg("inputs", type => [[[SampleInput]]])

here the input is a nested array

I'll create a test case shortly

Thanks 馃槈

Fixed by f9499e2 馃敀

thanks for the quick fix @MichalLytek!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robertchung97 picture robertchung97  路  3Comments

tafelito picture tafelito  路  3Comments

winuxue picture winuxue  路  4Comments

maplesteve picture maplesteve  路  3Comments

MichalLytek picture MichalLytek  路  3Comments