graphql icon indicating copy to clipboard operation
graphql copied to clipboard

`@Directive` on abstract `@ObjectType` is not applied to inherited classes

Open NilsMoller opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

Having a base @ObjectType({ isAbstract: true }) class decorated with @Directive('@key(fields: "id")') does not apply that directive to inherited classes.

Minimum reproduction code

N/A

Steps to reproduce

  1. Copy sample 31 for code-first federation.
  2. Add a model.base.ts to users-application/src/users/models:
@ObjectType({
  isAbstract: true,
})
@Directive('@key(fields: "id")')
export class ModelBase {
  @Field((type) => ID)
  id: number;
}
  1. Update the user.model.ts:
@ObjectType()
export class User extends ModelBase {
  @Field()
  name: string;
}
  1. Start the projects (gateway last)
  2. See the error in the gateway console

Expected behavior

The directive is applied to all inheriting classes.

Package version

12.0.8

Graphql version

"@apollo/gateway": "2.2.3",
"@apollo/server": "4.7.5",
"@nestjs/apollo": "12.0.3",
"@nestjs/graphql": "12.0.3",
"graphql": "16.6.0",
"graphql-tools": "9.0.0",

NestJS version

^10.0.3

Node.js version

18.17.0

In which operating systems have you tested?

  • [ ] macOS
  • [X] Windows
  • [ ] Linux

Other

  • Tried with both federation 1 and 2.
  • I presume this is an issue not specifically related to federation, but I do not know enough about directives to test other configurations for now.
  • I have tested this with the (currently) latest versions in my own project with the same results:
"@apollo/server": "^4.9.1",
"@nestjs/apollo": "^12.0.7",
"@nestjs/graphql": "^12.0.8",
"graphql": "^16.7.1",

NilsMoller avatar Aug 10 '23 09:08 NilsMoller

Would you like to create a PR for this issue?

kamilmysliwiec avatar Nov 08 '23 09:11 kamilmysliwiec