如何在生成GQL模式时进行转换?[NestJS]



我想把前缀应用到GQL模式生成的所有类型、突变等。这是我的配置工厂:

useFactory: (configService: ConfigService) => ({
autoSchemaFile: 'schema.graphql',
sortSchema: true,
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
transformSchema: schema => wrapSchema({
schema,
transforms: [
new RenameTypes(name => `New${name}`),
new RenameObjectFields((_, fieldName) => `new_${fieldName}`),
new RenameInterfaceFields((_, fieldName) => `new_${fieldName}`),
new RenameInputObjectFields((_, fieldName) => `new_${fieldName}`),
],
}),
playground: configService.get<string>('NODE_ENV') === 'development',
context: ({ req, res }): { req: Request; res: Response } => ({
req,
res,
}),
tracing: configService.get<string>('NODE_ENV') === 'development',
}),

wrapSchema工作得很好,但结果我仍然在变老的模式…看起来transformSchema根本不起作用。如何解决这个问题?

因此,在探索@nestjs/graphql的源代码后,我发现为了使transformSchema选项工作,我必须设置transformAutoSchemaFile: true,因为我使用autoSchemaFile

最新更新