type-graphql: Adding any @FieldResolver crashes build

Describe the Bug Adding the @ Field decorator to a model does nothing and adding the @ FieldResolver decorator to a Resolver crashes the build process. Either this is a bug or I have done something wrong.

Adding any @ FieldResolver decorator will cause this, even one that simply returns a preset string.

To Reproduce

model

@ObjectType("Album")
export class AlbumModel {
  @Field(() => ID)
  id: string;

  @Field()
  title: string;

[1]
  // @Field(() => [SocialLinkModel])
  // social: SocialLinkModel[];

[2]
 // @Field(() => [SocialLinkModel])
 // social(@Root() album: AlbumEntity) {
 //   return album.social?.links ?? [];
 // }

}

@ObjectType("SocialLink")
export class SocialLinkModel {
  @Field(() => ID)
  id: string;

  @Field()
  site: string;

  @Field()
  url: string;
}

[3] In addition, doing this in place of [2] causes the same issue

 @Field(() => [SocialLinkModel])
  social(@Root() album: AlbumEntity): SocialLinkModel[] {
    return [{ id: "2", url: "foo", site: 1 }];
  }

resolvers

@Resolver((_of) => AlbumModel)
export class AlbumResolver {

[1]
  @FieldResolver(() => [SocialLinkModel])
  async social(@Root() album: AlbumEntity) {
    return album.social?.links ?? [];
  }

  @Query(() => [AlbumModel])
  albums() {
    return AlbumEntity.find({ relations : ["social","social.links"] });
  }
}

Expected Behavior [1]: Either the The schema should be able to build with the resolveProperty and work as expected. or [2] or [3]: The @Field should return the value in the return function.

Logs [1]

(node:76612) UnhandledPromiseRejectionWarning: Error: Unable to find type metadata for input type or object type named ''
    at /Users/me/documents/api/node_modules/type-graphql/dist/metadata/metadata-storage.js:183:27
    at Array.forEach (<anonymous>)
    at MetadataStorage.buildFieldResolverMetadata (/Users/me/documents/api/node_modules/type-graphql/dist/metadata/metadata-storage.js:167:21)
    at MetadataStorage.build (/Users/me/documents/api/node_modules/type-graphql/dist/metadata/metadata-storage.js:100:14)
    at Function.generateFromMetadataSync (/Users/me/documents/api/node_modules/type-graphql/dist/schema/schema-generator.js:27:51)
    at Function.generateFromMetadata (/Users/me/documents/api/node_modules/type-graphql/dist/schema/schema-generator.js:15:29)
    at Object.buildSchema (/Users/me/documents/api/node_modules/type-graphql/dist/utils/buildSchema.js:9:61)

[2] and [3] image

Environment (please complete the following information):

  • OS: [macOS 10.15.4]
  • Node (v12.16.3)
  • Package version [^1.0.0-rc.1] and [0.18.0-beta.17]
  • TypeScript version [^3.8.3]
  • TypeORM version [^0.2.24]

Additional Context Thanks for taking the time to look at this. Love this framework, would love to figure this out so I can continue using it!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I bet you have target: es5 in your tsconfig.json file 😛 https://typegraphql.com/docs/installation.html#typescript-configuration

im having same problem, any update?

I changed to ES2020 and it works.