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

Mic*_*elB 6 graphql nestjs apollo-federation graphql-federation nestjs-graphql

在 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)

我创建了一个基于 nx 的单一存储库,通过在本地主机上的不同端口上同时以监视模式启动所有 3 个服务器,您可以轻松地重现此问题。

一切都按其应有的方式映射。链接: https: //github.com/sebastiangug/nestjs-federation.git

自述文件包含运行它所需的两个命令以及同一组指令以及每个服务可用的运行状况检查查询。

使用的版本:

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

你知道我在这里做错了什么或者需要什么进一步的配置才能实现这一点吗?

谢谢