【发布时间】: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