Skip to content

Commit

Permalink
feat: allow providing abstract type (#2503)
Browse files Browse the repository at this point in the history
* feat: allow providing abstract type

* feat: allow abstract type in Injector.get

* add changeset
  • Loading branch information
n1ru4l authored Oct 23, 2024
1 parent 2071592 commit cf6e51f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-lamps-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-modules': minor
---

Support passing an abstract class to `Injector.get` call and `Provider` value.
7 changes: 5 additions & 2 deletions packages/graphql-modules/src/di/injector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, InjectionToken, Provider } from './providers';
import { Type, InjectionToken, Provider, AbstractType } from './providers';
import {
ResolvedProvider,
resolveProviders,
Expand Down Expand Up @@ -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<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: any): T;
abstract get<T>(
token: Type<T> | InjectionToken<T> | AbstractType<T>,
notFoundValue?: any
): T;
}

export class ReflectiveInjector implements Injector {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-modules/src/di/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface FactoryProvider<T> extends BaseProvider<T> {
}

export interface BaseProvider<T> extends ProviderOptions {
provide: Type<T> | InjectionToken<T>;
provide: Type<T> | InjectionToken<T> | AbstractType<T>;
}

export interface TypeProvider<T> extends Type<T> {}
Expand Down

0 comments on commit cf6e51f

Please sign in to comment.