Skip to content

@FieldResolver not working on extended classes #533

Closed
@victorstein

Description

@victorstein

Describe the bug
When requesting data from a @FieldResolver from an extended class the field resolver gets triggered in the current class instead of the extended class.

To Reproduce
Given the base class below:

  @Resolver(() => returnType, { isAbstract: true })
  abstract class CRUDBaseResolver {

    @Query(() => returnType, { name: `${prefix}ById` })
    @Authorized(findById)
    async findById(
      @Args() { id }: byIdInterface,
      @Ctx() { permissions, user }: any
    ): Promise<T[]> {
       // ...search logic
    }

    @Query(() => paginationOutput, { name: `${prefix}s`, nullable: true })
    @Authorized(readAll)
    readAll (
      @Args() { perPage, page, filters = [], sort = [] }: paginationInterface,
      @Ctx() { permissions, user }: any
    ): paginationOutput {
       // ... pagination logic
    }

    @Mutation(() => Boolean, { name: `delete${capitalize(prefix)}ById` })
    @Authorized(deleteById)
    async deleteById (
      @Args() { id }: byIdInterface
    ): Promise<boolean> {
      //  ... deletion logic
    }

    @FieldResolver(() => User, { name: 'createdBy' })
    async createdBy (
      @Root() root: any
    ) {
      if (validator.isMongoId(root.createdBy)) {
        return userModel.findById(root.createdBy)
      }
      return root.createdBy
    }

  }

And the following extended class

@Resolver()
export default class ProjectResolvers extends CRUDProject {
  @Mutation(() => Project)
  @Authorized(['create_projects'])
  async createProject (
    @Args() {
      // ...some args
    }: createProjectInterface
  ): Promise<Project> {
    // ... creation logic
  }
}

Whenever I run a query or a mutation from the base class (e.g. findById) the @FieldResolver decorator responds as expected, thus resolving the database call; however, when running the createProject mutation from the extended class the @FieldResolver doesn't fire on the base class, it fires on the extended class.

Expected behavior
The @FieldResolver from the base class should handle the calls for that specific field.

Logs
N/A

Enviorment (please complete the following information):

  • OS: Windows 10
  • Node: 12.9.0
  • Package version: ^0.17.6
  • TypeScript version: ^3.7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Question ❔Not future request, proposal or bug issueSolved ✔️The issue has been solved

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions