nestjs/graphql Nest can't resolve dependencies of the GraphQLModule... HttpAdapterHost at index [0]

456 Views Asked by At

I have two package with their own package.json

{
  "name": "stock",
  "dependencies": {
    "@apollo/federation": "^0.37.1",
    "@apollo/subgraph": "^2.1.3",
    "@nestjs/apollo": "^10.0.9",
    "@nestjs/axios": "^1.0.0",
    "@nestjs/common": "^8.4.7",
    "@nestjs/core": "^8.4.4",
    "@nestjs/graphql": "^10.0.22",
    "@nestjs/platform-express": "^8.4.4",
    "apollo-server-core": "^3.10.2",
    "apollo-server-express": "^3.10.2",
  }
}

first package stock

@Module({
  imports: [
    GraphQLModule.forRoot<ApolloFederationDriverConfig>({
      driver: ApolloFederationDriver,
      typePaths: [join(__dirname, '..', 'src', 'schema.gql')],
      playground: false,
      plugins: [ApolloServerPluginLandingPageLocalDefault()],
    }),
  ],

})

export class StockModule { }



Second package test has the same package.json

In this package I want to test StockModule features

import { NestFactory } from '@nestjs/core';
import { StockModule } from 'stock'; // stock is defined in package.json 
import { Module } from '@nestjs/common';

@Module({
  imports: [
    StockModule,
  ],
})
class TestModule { }

describe('Stock Module ', () => {
  beforeAll(async () => {
    const app = await NestFactory.createApplicationContext(TestModule);
  });
 });

Test are running with jest

When I try to launch the test nest throw me this error:

[Nest] 7278  - 12/02/2022, 11:00:56 AM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the GraphQLModule (?, GqlModuleOptions, AbstractGraphQLDriver, GraphQLTypesLoader). Please make sure that the argument HttpAdapterHost at index [0] is available in the GraphQLModule context.

Potential solutions:
- If HttpAdapterHost is a provider, is it part of the current GraphQLModule?
- If HttpAdapterHost is exported from a separate @Module, is that module imported within GraphQLModule?
  @Module({
    imports: [ /* the Module containing HttpAdapterHost */ ]
  })

The version of @nestjs/* are the same, I even tried to copy the node_modules/@nestjs from stock package to test package and I still have the same issues,

0

There are 0 best solutions below