【问题标题】:GraphQLFederationModule healthcheckGraphQLFederationModule 健康检查
【发布时间】:2021-09-13 08:38:31
【问题描述】:

我正在学习nest.js,但有一个我可能不完全理解的问题。

在我们公司,我们有 dev-gateway,它检查 MY_URL/.well-known/apollo/server-health 端点以确保服务在创建之前启动,然后从 MY_URL 下载架构。 MY_URL 是我们传递给配置的变量。

所以我需要 GET http://MY_URL/.well-known/apollo/server-health 来返回 { status: pass } 和 POST http://MY_URL/ 来返回 schema/be graphql 端点。

如果 GraphQLFederationModule 配置中的 path 等于 / 它可以工作,但如果我将路径定义为 /graphql 然后:

  • GET http://MY_URL/.well-known/apollo/server-health 返回 { status: pass } 我认为这是个问题,我想要 /graphql 路径下的 graphql 服务
  • GET http://MY_URL/graphql/.well-known/apollo/server-health 是 graphql 端点,它返回错误(缺少查询),我认为它应该返回 { status: pass }
  • GET http://MY_URL/graphql 返回 graphql enpoint 就可以了

我准备了一些最小的工作版本,我正在使用: "@apollo/federation": "^0.25.1", "@nestjs/common": "^7.6.15", "@nestjs/core": "^7.6.15", "@nestjs/graphql": "^7.10.3", “阿波罗服务器快递”:“^2.22.2”, "graphql": "^15.5.0", "graphql-tools": "^7.0.4",

import { NestFactory } from '@nestjs/core';
import { Module } from '@nestjs/common';
import {
  GraphQLFederationModule,
  Query,
  Resolver,
  ResolveReference,
  Directive, Field, ID, ObjectType 
} from '@nestjs/graphql';

import { Controller, Get } from '@nestjs/common';

@Controller('')
export class AppController {
  @Get()
  healthCheck() {
    return 'Hello World!';
  }
}

@ObjectType()
@Directive('@key(fields: "_id")')
export class AdSpot {
  @Field((type) => ID)
  _id: string;

  @Field((type) => String)
  name: string
}

@Resolver((of) => AdSpot)
export class CatResolver {
  @Query((returns) => [AdSpot], { name: 'adSpots' })
  async getAdSpots() {
    return [];
  }
}

@Module({
  providers: [CatResolver],
})
export class CatsModule {}

@Module({
  imports: [
    CatsModule,
    GraphQLFederationModule.forRoot({
      include: [CatsModule],
      path: '/graphql',
      autoSchemaFile: true,
      sortSchema: true,
      playground: true,
      disableHealthCheck: false,
    }),
  ],
  controllers: [AppController],
})
export class AppModule {}

async function bootstrap() {
  try {
    const app = await NestFactory.create(AppModule);
    await app.listen(3010);
  } catch (err) {
    console.log('-------------------------------------');
    console.log(err);
  }
}

bootstrap();

我做错了什么?我错过了一些配置还是一个错误?

【问题讨论】:

    标签: javascript node.js graphql nestjs


    【解决方案1】:

    使用相对路径,即

    typePaths: ['**/*.graphql'],
    
    

    你的情况

    @Module({
      imports: [
        CatsModule,
        GraphQLFederationModule.forRoot({
          include: [CatsModule],
          typePaths: ['**/*.graphql'],
          autoSchemaFile: true,
          sortSchema: true,
          playground: true,
          disableHealthCheck: false,
        }),
      ],
      controllers: [AppController],
    })
    

    【讨论】:

    • 嗨,比尔,我很抱歉提出愚蠢的问题,但我对 typePaths 没有问题,但对 path 没有问题,我不确定如何在 graphql 中使用 *路径。
    • 试试这个:路径:'**/ *.graphql',
    • Bill,我不会尝试更改任何文件路径(并且 '*/graphql' 是文件路径),因为我将首先使用代码。这怎么可能?
    猜你喜欢
    • 2014-10-02
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 2017-07-16
    • 1970-01-01
    • 2019-05-19
    • 2019-11-20
    相关资源
    最近更新 更多