标签: apollo-testing

NestJS如何从graphql模块获取apolloClient以使用“apollo-server-testing”进行测试?

虽然标题类似于Access to Apollo server for NestJS GraphQL test,但问题本身很旧,并且该问题中的答案都解决了 Nestjs 中似乎不再存在的行为。

我遵循了这里的 PR https://github.com/nestjs/graphql/pull/1104以及其他几个线程,试图从测试模块获取 apolloClient 来对其运行测试查询,但没有成功。

Typescript 编译器支持的普遍错误是它根本不存在于 GraphQlModule 上。它在哪里?为什么它被删除了?我如何访问这个关键功能?

TypeError: Cannot read properties of undefined (reading 'executeOperation')

      71 | export function createTestClient(testingModule: TestingModule): apolloServerTesting.ApolloServerTestClient {
      72 |     const apolloServer = getApolloServer(testingModule);
    > 73 |     return apolloServerTesting.createTestClient(apolloServer as any);
         |                                ^
      74 | }
Run Code Online (Sandbox Code Playgroud)

基于PR创建的功能:

export function getApolloServer(app: INestApplicationContext): ApolloServerBase {
    try {
        const graphqlModule = app.get(GraphQLModule);
        return (graphqlModule as any).apolloServer;
    } catch (error) {}
    throw new Error( …
Run Code Online (Sandbox Code Playgroud)

graphql apollo-server nestjs nestjs-testing apollo-testing

5
推荐指数
0
解决办法
1137
查看次数