Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Injected services are undefined #387

Closed
pitazzo opened this issue Apr 2, 2021 · 1 comment
Closed

Injected services are undefined #387

pitazzo opened this issue Apr 2, 2021 · 1 comment

Comments

@pitazzo
Copy link

pitazzo commented Apr 2, 2021

Hey there,
I've tried to implement the basic example provided in the README file, but wherever I inject a service in my code, it's resolved as undefined. No error messages nor warnings are displayed.

Here is my app.module.ts:

@Module({
  imports: [
    GraphQLFederationModule.forRoot({
      context: ({ req }) => ({
        uid: req.headers.uid,
        role: req.headers.role,
      }),
      typePaths: ['./**/*.graphql'],
      resolvers: { Upload: GraphQLUpload },
      definitions: {
        path: join(process.cwd(), 'src/graphql.ts'),
      },
    }),
    DevicesModule,
    FirebaseAdminModule.forRootAsync({
      useFactory: () => ({
        credential: admin.credential.applicationDefault()
      })
    }),
    SecretsModule.forRoot({
      keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
      projectId: process.env.GCP_PROJECT_ID,
      env: process.env.ENVIRONMENT === 'DEV' ? 'DEV' : 'PROD',
    }),
    SetupModule,
  ],
  providers: [],
})
export class AppModule {}

This is the service where I try to inject the Firebase Services:

export class SetupService {
  constructor(
    private database: FirebaseDatabaseService,
    private storage: FirebaseStorageService,
  ) {}

  async foo(bar: string): Promise<boolean> {
    console.log(this.database) // prints undefined
    // ...
  }
}

This is the module where my service is contained:

@Module({
    providers: [SetupResolver, SetupService]
})
export class SetupModule {}

Is there anything wrong with my code that I'm not able to see?

@pitazzo
Copy link
Author

pitazzo commented Apr 7, 2021

I forgot adding @Injectable() in my service, 100% my fault

@pitazzo pitazzo closed this as completed Apr 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant