Reporting an example where the usage of ResolverInterface on the resolver break the typings on the property decorated with @FieldResolver.
@Resolver((_of) => Task)
class TaskResolver implements ResolverInterface<Task> {
async category(@Root() task: Task) {
return (dataloader: DataLoader<string, Category>) => {
if (task.categoryId === undefined) return null
return dataloader.load(task.categoryId)
}
}
}
@ObjectType({ description: 'A task is something to do' })
class Task extends TimeStamps {
@GQLField()
_id: string = ''
@MongoField()
@GQLField()
name: string = ''
@MongoField()
@GQLField()
completed: boolean = false
@MongoField()
categoryId?: string
@GQLField({ nullable: true })
category?: Category
}
The error is:
error TS2416: Property 'category' in type 'TaskResolver' is not assignable to the same property in base type 'ResolverInterface<Task>'.
Type '(task: Task) => Promise<(dataloader: DataLoader<string, Category, string>) => Promise<Category> | null>' is not assignable to type '(root: Task, ...args: any[]) => Category | Promise<Category | undefined> | undefined'.
Type 'Promise<(dataloader: DataLoader<string, Category, string>) => Promise<Category> | null>' is not assignable to type 'Category | Promise<Category | undefined> | undefined'.
Type 'Promise<(dataloader: DataLoader<string, Category, string>) => Promise<Category> | null>' is not assignable to type 'Promise<Category | undefined>'.
Property '_id' is missing in type '(dataloader: DataLoader<string, Category>) => Promise<Category> | null' but required in type 'Category'.
46 async category(@Root() task: Task) {
The solution at the moment is not to implement the interface and the implementation works.
It first look ResolverInterface should be enriched in type-graphql, but I am posting here first for opinion and feedback and I'll close the issue if it doesn't make sense to be here.
Reporting an example where the usage of
ResolverInterfaceon the resolver break the typings on the property decorated with @FieldResolver.The error is:
The solution at the moment is not to implement the interface and the implementation works.
It first look
ResolverInterfaceshould be enriched intype-graphql, but I am posting here first for opinion and feedback and I'll close the issue if it doesn't make sense to be here.