Skip to content

Commit

Permalink
fix(container): use .get() and .resolve() methods properly
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Jun 10, 2020
1 parent dd5699e commit 7acd23d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/typegraphql-options.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TypeGraphQLFeatureModuleOptions,
} from "./types";
import { REQUEST_CONTEXT_ID } from "@nestjs/core/router/request/request-constants";
import { InstanceWrapper } from "@nestjs/core/injector/instance-wrapper";

@Injectable()
export default class TypeGraphQLOptionsFactory implements GqlOptionsFactory {
Expand All @@ -35,6 +36,7 @@ export default class TypeGraphQLOptionsFactory implements GqlOptionsFactory {

const featureModuleOptionsArray: TypeGraphQLFeatureModuleOptions[] = [];
const resolvers: ClassType[] = [];
const providersMetadataMap = new Map<Function, InstanceWrapper<any>>();

for (const module of this.modulesContainer.values()) {
for (const provider of module.providers.values()) {
Expand All @@ -47,6 +49,7 @@ export default class TypeGraphQLOptionsFactory implements GqlOptionsFactory {
);
}
if (globalResolvers.includes(provider.metatype)) {
providersMetadataMap.set(provider.metatype, provider);
resolvers.push(provider.metatype as ClassType);
}
}
Expand All @@ -62,6 +65,13 @@ export default class TypeGraphQLOptionsFactory implements GqlOptionsFactory {
contextId = ContextIdFactory.create();
context[REQUEST_CONTEXT_ID] = contextId;
}
const providerMetadata = providersMetadataMap.get(cls)!;
if (
providerMetadata.isDependencyTreeStatic() &&
!providerMetadata.isTransient
) {
return this.moduleRef.get(cls, { strict: false });
}
return this.moduleRef.resolve(cls, contextId, { strict: false });
},
};
Expand Down

0 comments on commit 7acd23d

Please sign in to comment.