Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument set through Custom Parameter Decorator is empty when using inheritance with a FieldResolver #1453

Closed
maurocolella opened this issue May 7, 2023 · 2 comments
Assignees
Labels
Community 👨‍👧 Something initiated by a community Invalid 👎 This doesn't seem right

Comments

@maurocolella
Copy link

maurocolella commented May 7, 2023

Describe the Bug
I have a custom parameter decorator on a field resolver applied through inheritance.

Unfortunately, with this structure, the parameter returned is empty (although as far as I can tell the decorator is executed and returns the correct value).

This is using "type-graphql": "^1.2.0-rc.1"

To Reproduce
Abstract base class (sample):

export function createBaseResolver<T extends ClassType>(_suffix: string, objectTypeCls: T) : any {
  @Resolver(of => objectTypeCls, { isAbstract: true })
  abstract class BaseResolver {
    @Authorized()
    @HasBranch()
    @FieldResolver(returns => Boolean)
    async onboarded(
      @CurrentSession() user: AuthContext,
    ): Promise<boolean> {
      console.log({ user }) // # empty

     // # logic here

      return false
    }
  }

  return BaseResolver
}

Custom parameter decorator:

export const CurrentSession = (): ParameterDecorator => {
  return createParamDecorator<any>(
    ({ context }) : AuthContext => context?.auth?.user,
  )
}

Usage:

const EntityBaseResolver = createBaseResolver('entity', Entity)

@Resolver(Entity)
export class EntityResolver extends EntityBaseResolver {
  constructor(
    private entityService: EntityService,
  ) {
    super()
  }

Expected Behavior
I would expect the decorator to correctly inject the user as an argument into the field resolver.

Logs
No error. But user is defined in the decorator, undefined in the field resolver.

Environment (please complete the following information):

  • OS: Ubuntu Linux 22.0.4
  • Node v14.8.2
  • Package version ^1.2.0-rc.1 (please check if the bug still exist in newest release)
  • TypeScript version ^4.5.2

Additional Context
This is transpiled and executed in dev using ts-node, eq.

"ts-node": "^10.2.0"
"ts-node-dev": "^1.1.8"
ts-node-dev --inspect --exit-child -r tsconfig-paths/register --respawn src/main/index.ts
@MichalLytek MichalLytek added Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community labels May 8, 2023
@MichalLytek MichalLytek self-assigned this May 8, 2023
@MichalLytek MichalLytek added this to the 2.0 release milestone May 8, 2023
@MichalLytek
Copy link
Owner

MichalLytek commented May 3, 2024

@maurocolella

Sorry but I'm unable to reproduce:

/* eslint-disable max-classes-per-file */
import {
  type ClassType,
  Field,
  FieldResolver,
  Float,
  ObjectType,
  Query,
  Resolver,
  createParamDecorator,
} from "type-graphql";

const CustomDecorator = () => createParamDecorator(() => 21.37);

function createBaseResolver<T extends ClassType>(_suffix: string, objectTypeCls: T): any {
  @Resolver(() => objectTypeCls)
  abstract class BaseResolver {
    @FieldResolver(() => Float)
    async baseResolverField(@CustomDecorator() value: number): Promise<number> {
      console.log({ value });
      return value;
    }
  }

  return BaseResolver;
}

@ObjectType()
class TestEntity {
  @Field()
  testField!: string;
}

const TestEntityBaseResolver = createBaseResolver("entity", TestEntity);

@Resolver(TestEntity)
export class TestEntityResolver extends TestEntityBaseResolver {
  constructor() {
    super();
    console.log("TestEntityResolver constructor called");
  }

  @Query()
  testEntity(): TestEntity {
    return {
      testField: "test",
    };
  }
}

image

@MichalLytek MichalLytek added Need More Info 🤷‍♂️ Further information is requested and removed Bug 🐛 Something isn't working labels May 10, 2024
@maurocolella
Copy link
Author

@MichalLytek appreciate the feedback. I have since changed projects, but to be fair it was on a pretty large, somewhat clunky codebase. If similar issues are not noted by other users, I think it can be closed without risks.

@MichalLytek MichalLytek closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
@MichalLytek MichalLytek added Invalid 👎 This doesn't seem right and removed Need More Info 🤷‍♂️ Further information is requested labels May 12, 2024
@MichalLytek MichalLytek removed this from the 2.0 release milestone May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Invalid 👎 This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants
@maurocolella @MichalLytek and others