【发布时间】:2021-09-05 16:24:42
【问题描述】:
我在节点 v14x 上使用带有 graphql 的 NestJS 7 这是我的 graphql 模块配置
import { Module, NestModule, RequestMethod, MiddlewareConsumer } from '@nestjs/common';
import { graphqlUploadExpress } from "graphql-upload"
import { GraphQLModule } from '@nestjs/graphql';
import { ConfigService } from '@nestjs/config';
import { ApolloServerDataLoaderPlugin } from '@webundsoehne/nestjs-graphql-typeorm-dataloader';
import { GraphqlConfig } from './@core/config/config.interface';
import { getConnection } from 'typeorm';
@Module({
imports: [
GraphQLModule.forRootAsync({
useFactory: async (configService: ConfigService) => {
const graphqlConfig = configService.get<GraphqlConfig>('graphql');
return {
buildSchemaOptions: {
numberScalarMode: 'integer',
plugins: [new ApolloServerDataLoaderPlugin({ typeormGetConnection: getConnection })]
},
sortSchema: graphqlConfig.sortSchema,
autoSchemaFile:
graphqlConfig.schemaDestination || './src/schema.graphql',
debug: graphqlConfig.debug,
path: graphqlConfig.endPoint,
uploads: false,
playground: graphqlConfig.playgroundEnabled,
context: ({ req, connection }) => {
if (connection) {
return { req: { headers: connection.context } }
}
return { req }
},
installSubscriptionHandlers: true,
dateScalarMode: "isoDate",
subscriptions: {
keepAlive: 5000
}
};
},
inject: [ConfigService],
}),
],
})
export class GQLModule implements NestModule {
constructor(private readonly configService: ConfigService) { }
configure(consumer: MiddlewareConsumer) {
const graphqlConfig = this.configService.get<GraphqlConfig>('graphql');
consumer.apply(graphqlUploadExpress()).forRoutes(graphqlConfig.endPoint)
}
}
在文件上传卡在节点 v14.x 上不起作用后,我找到了这个issue comment。我在解析器上从graphql-upload 导入所有内容,但仍然收到POST body missing. Did you forget use body-parser middleware? 之类的错误消息
有人可以帮我吗?
【问题讨论】:
标签: node.js graphql nestjs apollo-server