I'm getting the CannotDetermineGraphQLTypeError and can't fix it

1.1k views Asked by At

My code:

@InputType()
export class RegisterUserInput implements Partial<User> {
  @Field()
  id!: number;

  @Field()
  userName!: string;

  @Field()
  firstName!: string;

  @Field()
  lastName!: string;

  @Field()
  password!: string;

  @Field()
  role!: string;

  @Field((type) => [Assignment])
  assignments!: Assignment[];
}

CannotDetermineGraphQLTypeError: Cannot determine GraphQL input type for 'assignments' of 'RegisterUserInput' class. Does the value used as its TS type or explicit type is decorated with a proper decorator or is it a proper input value?

4

There are 4 answers

0
Yazeer On BEST ANSWER

Check if the user class has the @ObjectType() decorator. else delete your build folder and rebuild again

1
toomusa On

This is still a temporary work-around but it worked for me.

https://www.npmjs.com/package/graphql-type-json

  @Field((type) => [GraphQLJSONObject])
  assignments!: Assignment[];
0
Goutham On

You should be using InputType instead for Assignment

@InputType() // Define Assignments a separate InputType
class Assignment{
  @Field()
      name: string;
}
1
Lord Vordemolt On

Thank you to who answered, I found a solution by using 'simple-array' type.