Skip to content

Abstract ObjectType is allowed in Schema #564

Closed
@twavv

Description

@twavv

I have code that looks approximately like this.

@InterfaceType("Animal")
abstract class AnimalGQLInterface {
    @Field(() => String)
    abstract name: Promise<string>;
}

@ObjectType("AnimalBase", {
  isAbstract: true,
  implements: [AnimalGQLInterface],
})
abstract class Animal implements AnimalGQLInterface {
  abstract readonly id: string;

  async get name() {
    return nameService.getAnimalName(this.id);
  }
}

@ObjectType()
class Cat extends Animal {
  /* ... */
}

@ObjectType()
class Dog extends Animal {
  /* ... */
}

In other places, I accidentally wrote this:

// Incorrect: uses Animal instead of AnimalGQLInterface for decorator
@Field(() => [Animal])
pets: Animal[];

The correct code there was

@Field(() => [AnimalGQLInterface])
pets: Animal[];

Despite the fact that isAbstract: true was set on Animal, the resulting GraphQL schema includes AnimalBase as a type.

What should it do?

It should throw an error that abstract type made it into the GraphQL schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions