Config in useFactory not injected
See original GitHub issueI’m submitting a…
[ ] Regression
[ x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
My configService is not injected into GraphQLModule.forRootAsync -> useFactory
Expected behavior
config.getArray should be a existing function
Minimal reproduction of the problem with instructions
app.module
GraphQLModule.forRootAsync({
imports: [
ClientModule,
AuthModule,
UserModule,
AggregationModule,
],
useFactory: async (config: ConfigService) => ({
include: [
ClientModule,
AuthModule,
UserModule,
AggregationModule,
],
autoSchemaFile: 'schema.gql', // https://github.com/nestjs/graphql/issues/205
context: (req: any) => (req),
cors: {
origin: config.getArray('FRONTEND_URL'),
},
debug: config.isDevelopment(),
playground: config.isDevelopment(),
}),
inject: [ConfigService],
}),
config.service
import { Injectable } from '@nestjs/common';
import { join } from 'path';
import * as dotenv from 'dotenv';
@Injectable()
export class ConfigService {
constructor() {
dotenv.config({
path: join(__dirname, '../../.env'),
});
}
getString(key: string): string {
return process.env[key];
}
getBoolean(key: string): boolean {
if ('true' === process.env[key]) {
return true;
}
return false;
}
getArray(key: string, separator: string = ','): any[] {
return process.env[key].split(separator);
}
isProduction(): boolean {
return 'production' === process.env.ENVIRONMENT;
}
isDevelopment(): boolean {
return 'development' === process.env.ENVIRONMENT;
}
}
Before Upgrading to the newest NestJS Version this worked as expected. Now, running npm run start:dev throws a [0] [Nest] 7066 - 2019-09-27 13:55:37 [ExceptionHandler] config.getArray is not a function +33ms
Exception.
What is the motivation / use case for changing the behavior?
Environment
Nest version: 6.7.2
Node Version: 12.7.0
OS: Linux
```
"dependencies": {
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
"@nestjs/graphql": "^6.5.2",
"@nestjs/jwt": "^6.1.1",
"@nestjs/mongoose": "^6.1.2",
"@nestjs/passport": "^6.1.0",
"@nestjs/platform-express": "^6.7.2",
"apollo-server-express": "^2.9.4",
"argon2": "^0.24.1",
"class-transformer": "^0.2.3",
"class-validator": "^0.9.1",
"dotenv": "^8.1.0",
"graphql": "^14.5.8",
"graphql-tools": "^4.0.5",
"graphql-type-json": "^0.3.0",
"luxon": "^1.19.3",
"mongoose": "^5.7.1",
"ms": "^2.1.2",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.7.1",
"rxjs": "^6.5.3",
"type-graphql": "^0.17.5",
"url-parse": "^1.4.7"
},
"devDependencies": {
"@nestjs/testing": "^6.7.2",
"@types/bcrypt": "^3.0.0",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.1",
"@types/jest": "^23.3.13",
"@types/node": "^10.14.19",
"@types/supertest": "^2.0.7",
"@types/url-parse": "^1.4.3",
"concurrently": "^4.1.2",
"jest": "^23.6.0",
"nodemon": "^1.19.2",
"prettier": "^1.15.3",
"shipit-cli": "^5.1.0",
"shipit-deploy": "^5.1.0",
"shipit-shared": "^4.4.2",
"supertest": "^3.4.1",
"ts-jest": "24.0.2",
"ts-node": "8.1.0",
"tsconfig-paths": "3.8.0",
"tslint": "5.16.0",
"typescript": "3.4.3",
"wait-on": "^3.2.0"
},```
Others:
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Nestjs: cannot inject ConfigService while testing
You either need to set { isGlobal: true } as an option for the ConfigModule or you need to add imports: [ConfigModule] to...
Read more >Configuring dependency providers - Angular
The Creating and injecting services topic describes how to use classes as ... useFactory - allows you to define a function that constructs...
Read more >Secrets of Dependency Injection with Angular
Dependency injection (DI) is a design pattern in which a class asks for dependencies from external sources (the injectors) rather than creating them...
Read more >OktaAuthModule Not Resolving Correctly When Using Factory ...
Hi, The OktaAuthModule is not correctly resolving when using it in the ... import { Injectable } from '@angular/core'; import { appConfig, ...
Read more >Dependency Providers - Angular
It can also be useExisting , useValue , or useFactory . ... Although the AppConfig interface plays no role in dependency injection, it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed in 6.5.3 😃
@kamilmysliwiec tested and fix validated! Fastest turnaround time of all time 😃