标签: graphql-federation

在 jest 中运行 e2e 测试时无法 POST /graphql (404) 错误(GraphQL Federation)

我正在尝试在 Nest.js 应用程序中使用 supertest + jest 端到端测试我的 graphql 服务,但不断收到此错误:

错误:无法 POST /graphql (404)

我尝试了很多方法,但由于该错误而无法使测试完全运行。

下面是我的测试文件:

import request from 'supertest';
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { GatewayAppModule } from '../../../app-gateway.module';
import { AppModule } from '../../../app.module';
import { CreateAccountArgs } from '../dto/create-account.args';

jest.mock('graphql-moment', () => ({
  GraphQLDate: jest.fn(),
}));

describe('Auth resolver: Authentication module e2e test', () => {
  let mainApp: INestApplication;
  let gatewayApp: INestApplication;

  beforeAll(async () => {
    const mainAppModuleRef: TestingModule = …
Run Code Online (Sandbox Code Playgroud)

supertest jestjs graphql nestjs graphql-federation

7
推荐指数
0
解决办法
694
查看次数

Nestjs + apollo graphql 联合网关由于“错误请求”而无法内省服务,可复制的 git 存储库可用

在 NX monorepo 中,我正在构建 3 个 Nestjs 应用程序,首先是一个auth-service+user-service和一个。gateway它们均由 apollo graphql 提供支持并遵循官方 Nestjs 文档。

我遇到的问题是,在user-service作为auth-service单独服务器成功处理请求的同时,网关抛出

 Couldn't load service definitions for "auth" at http://localhost:3100/apis/auth-service/graphql: 400: Bad Request
Run Code Online (Sandbox Code Playgroud)

这些服务本身是标准的 graphql 应用程序,没有什么基础的。

网关的定义如下:

{
server: {
          debug: true,
          playground: true,
          autoSchemaFile: './apps/gateway/schema.gql',
          sortSchema: true,
          introspection: true,
          cors: ['*'],
          path: '/apis/gateway/graphql';
        },
gateway: {
            supergraphSdl: new IntrospectAndCompose({
              subgraphHealthCheck: true,
              subgraphs: [
                {
                  name: 'user',
                  url: resolveSubgraphUrl('user'),
                },
                {
                  name: 'auth',
                  url: resolveSubgraphUrl('auth'),
                },
              ],
            }), …
Run Code Online (Sandbox Code Playgroud)

graphql nestjs apollo-federation graphql-federation nestjs-graphql

6
推荐指数
0
解决办法
489
查看次数