#Passing a provider to an imported library

1 messages · Page 1 of 1 (latest)

whole dock
#

Is there a way to pass a provider into an imported library? I have the following module which which relies on a GraphQLSubgraphWrapperModule which is suppose to use the Module passed in the 3rd param in graphql module's include to restrict the resolvers to use to only the resolvers from this module. But the GraphqlModule ends up trying to instantiate the FileResolver and the FileService and doesn't have access to the providers of this module. And shouldn't really need it if the correct module was "instantiating" its own providers.

FileResolver has a single dependency on FileService and FileService has a single injection dependency on MINIO_PROVIDER

If more module signatures are needed then I can post them. I am assuming I am missing something simple here.


@Module({
  imports: [],
  providers: [MINIO_PROVIDER, FileService, FileResolver],
  exports: [ FileService,FileResolver ],
})
export class NewRepoFileLibModule {
  static forSubGraph(subGraphPath?: string): DynamicModule {
    return {
      module: NewRepoFileLibModule,
      imports: [
        DiscoveryModule,
        GraphQLSubgraphWrapperModule.register(
          'file',
          schemaPath,
          [NewRepoFileLibModule],
          'fileSchemaProvider',
          subGraphPath ? subGraphPath : '/graphql'
        ),
      ],
      exports: [ FileService,FileResolver ],

    };
  }
}

#

Not entirely sure where the circular dependency is as the inner modules shouldn't be "instantiating" anything to my knowledge.
Error message:

[Nest] 44259 - 12/02/2025, 10:21:25 PM LOG [InjectorLogger] Nest encountered an undefined dependency. This may be due to a circular import or a missing dependency declaration.
[Nest] 44259 - 12/02/2025, 10:21:25 PM ERROR [ExceptionHandler] UndefinedDependencyException [Error]: Nest can't resolve dependencies of the FileService (?). Please make sure that the argument dependency at index [0] is available in the current context.

cedar agate
#

I think that not directly as “provider instances”. @whole dock

#

I prefer wiring the wrapper and feature module together from a root module to avoid circular imports.