import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; import { AppModule } from '../src/app.module'; import { GraphQLModule } from '@nestjs/graphql'; import { ApolloServerTestClient, createTestClient, } from 'apollo-server-testing'; import { gql } from 'apollo-server-express'; describe('AppController (e2e)', () => { let app: INestApplication; let apolloClient: ApolloServerTestClient; beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); await app.init(); const module: GraphQLModule = moduleFixture.get( GraphQLModule, ); // apolloServer is protected, we need to cast module to any to get it apolloClient = createTestClient((module as any).apolloServer); }); afterAll(async () => { await app?.close(); }); });