如何在Nest.js微服务中使用GraphQL Playground或Appolo Sandbox



我有一个微服务:

import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
transport: Transport.KAFKA,
options: {
client: {
brokers: ['localhost:9092'],
},
consumer: {
groupId: 'auth-consumer',
},
},
},
);
app.listen();
}
bootstrap();

我想使用GQL Playground,但文档只提到默认工厂(NestFactory.create()而不是NestFactory.createMicroservice()(。他们执行app.listen(XXXX),只需要导航到localhost:XXXX/graphql

我的微服务使用Kafka,并且不是我的API网关的一部分,我如何在GQL Playground上测试我的GQL端点?

也许这会对您有所帮助!

import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.connectMicroservice<MicroserviceOptions>({
transport: Transport.KAFKA,
options: {
client: {
clientId: 'classroom',
brokers: [process.env.KAFKA_BROKERS as string],
},
consumer: {
groupId: 'purchases',
},
},
});
app.startAllMicroservices().then(() => {
console.log('[MICROSERVICE] is running!');
});
app.listen(process.env.APP_PORT || 3000).then(() => {
console.log('[HTTP/GRAPHQL] is running!');
});
}
bootstrap();

相关内容

  • 没有找到相关文章

最新更新