2

I am using NestJS with TypeORM to connect with a MongoDB server running on a docker image. I am getting this error when trying to start the application:

type-metadata.storage.js:263
            throw new cannot_determine_host_type_error_1.CannotDetermineHostTypeError(item.schemaName, objectTypeRef === null || objectTypeRef === void 0 ? void 0 : objectTypeRef.name);
                  ^
Error: Cannot determine a GraphQL host type  (CreateClassInput?) for the "students" field. Make sure your class is decorated with an appropriate decorator (e.g., @ObjectType()).
    at TypeMetadataStorageHost.compileExternalFieldResolverMetadata

The field resolver is for a field named students. Students is an array of StudentOutput objects. The parent of students is defined in a GraphQL @ObjectType() class named ClassOutput:

@ObjectType()
export class ClassOutput extends PartialType(UpdateClassInput) {
  @IsUUID('4', { each: true })
  @Field(() => String)
  class_id: string;

  @Field(() => [StudentOutput], { defaultValue: [] })
  students: StudentOutput[];

The resolver properly lists ClassOutput as the parent GraphQL type for the students field.

@ResolveField()
  students(@Parent() classGQLObject: ClassOutput): Promise<StudentOutput[]> {
    return this.studentsService.findStudentsByIDArray(classGQLObject);
  }

Changing the decorator of ClassOutput from @ObjectType() to @InputType() did not resolve the error. This is how the `students field is defined in the TypeORM entity class:

@Entity('classes')
export class ClassesEntity {
  @ObjectIdColumn()
  _id: ObjectID;

  @PrimaryColumn()
  class_id: string;

  @Column({ type: 'array', default: [] })
  students: StudentOutput[];

Why is GraphQL unable to find the parent type of students when the parent type is defined in the resolver function thru students(@Parent() classGQLObject: ClassOutput), the decorated GraphQL classClassOutput, and the entity?

Joachim Rives
  • 471
  • 6
  • 19

0 Answers0