nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 397 forks source link

Cannot resolve nested Resolvers in nested modules #3396

Closed leandroluk closed 3 days ago

leandroluk commented 3 days ago

Is there an existing issue for this?

Current behavior

I have an application with this structure with code:

src/
|-- app.module.ts
|-- resources/
    |-- resources.module.ts
    |-- root/
        |-- root.module.ts
        |-- root.resolver.ts
src/resources/root/root.resource.ts
```ts import {ModuleRef} from '@nestjs/core'; import {Query, Resolver} from '@nestjs/graphql'; @Resolver() export class RootResolver { @Query(() => String, {description: 'Application is healthy'}) async healthcheck(): Promise { return "Works!" } //#endregion } ```
src/resources/root/root.module.ts
```ts import {Global, Module, Provider} from '@nestjs/common'; import {RootResolver} from './root.resolver'; const providers = Array().concat(RootResolver); @Global() @Module({ providers, exports: providers }) export class RootModule {} ```
src/resources/resources.module.ts
```ts import {Global, Module} from '@nestjs/common'; import {RootModule} from './root/root.module'; const modules = [RootModule]; @Global() @Module({ imports: modules, exports: modules }) export class ResourcesModule {} ```
src/app.module.ts
```ts import {ApolloDriver, ApolloDriverConfig} from '@nestjs/apollo'; import {Global, Module, Provider} from '@nestjs/common'; import {GraphQLModule} from '@nestjs/graphql'; import {ResourcesModule} from './resources'; @Global() @Module({ imports: [ GraphQLModule.forRoot({ include: [ResourcesModule], driver: ApolloDriver }), ResourcesModule, ], }) export class AppModule {} ```

Based on @nestjs/graphql, if I have nested a Resource all I have to do is add the nested module that contains the Resource but when I start the application I get the error "Error: Query root type must be provided."

I even tried to directly import the RootModule in the GraphqlModule but the code is still showing the same error.

The only way to get rid of the error is to declare the RootProvider directly in the AppModule

Minimum reproduction code

maybe isn't necessary when all expected code is declarated belo

Steps to reproduce

  1. create minimal project with @nestjs/graphql
  2. create described classes
  3. run application

Expected behavior

Expected to application starts normally

Package version

12.2.1

Graphql version

graphql: 16.9.0 @apollo/server: 4.11.2

NestJS version

10.0.0

Node.js version

20.17.0

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 3 days ago

Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the #⁠ 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.