From cf6e51f7e0f331da33f4c4e66297f0e3f4b0dfa1 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Wed, 23 Oct 2024 11:29:11 +0200 Subject: [PATCH] feat: allow providing abstract type (#2503) * feat: allow providing abstract type * feat: allow abstract type in Injector.get * add changeset --- .changeset/perfect-lamps-cheat.md | 5 +++++ packages/graphql-modules/src/di/injector.ts | 7 +++++-- packages/graphql-modules/src/di/providers.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/perfect-lamps-cheat.md diff --git a/.changeset/perfect-lamps-cheat.md b/.changeset/perfect-lamps-cheat.md new file mode 100644 index 0000000000..bc47a0aeca --- /dev/null +++ b/.changeset/perfect-lamps-cheat.md @@ -0,0 +1,5 @@ +--- +'graphql-modules': minor +--- + +Support passing an abstract class to `Injector.get` call and `Provider` value. diff --git a/packages/graphql-modules/src/di/injector.ts b/packages/graphql-modules/src/di/injector.ts index 5d964cc5e8..df36e446f0 100644 --- a/packages/graphql-modules/src/di/injector.ts +++ b/packages/graphql-modules/src/di/injector.ts @@ -1,4 +1,4 @@ -import { Type, InjectionToken, Provider } from './providers'; +import { Type, InjectionToken, Provider, AbstractType } from './providers'; import { ResolvedProvider, resolveProviders, @@ -27,7 +27,10 @@ type ExecutionContextGetter = () => ExecutionContext | never; // We use ReflectiveInjector everywhere // but we don't want to leak its API to everyone export abstract class Injector { - abstract get(token: Type | InjectionToken, notFoundValue?: any): T; + abstract get( + token: Type | InjectionToken | AbstractType, + notFoundValue?: any + ): T; } export class ReflectiveInjector implements Injector { diff --git a/packages/graphql-modules/src/di/providers.ts b/packages/graphql-modules/src/di/providers.ts index 7ef34ab0d7..6d7f93f01a 100644 --- a/packages/graphql-modules/src/di/providers.ts +++ b/packages/graphql-modules/src/di/providers.ts @@ -43,7 +43,7 @@ export interface FactoryProvider extends BaseProvider { } export interface BaseProvider extends ProviderOptions { - provide: Type | InjectionToken; + provide: Type | InjectionToken | AbstractType; } export interface TypeProvider extends Type {}