1

我正在使用graphql-codegen插件typescript-mongodb从 qraphql 模式生成数据库模型文件。因此,我的架构包含来自typescript-mongodblike@entity@column. codegen 工作正常,但是当我使用该graphql-tools loadSchemaSync函数加载架构时,我得到一个架构验证错误,它抱怨未知指令。

可能最简单的解决方案是将 mongo 插件指令定义添加到模式中(我也无法开始工作)。但是在 graphql-codegen 生成配置文件之后,实际上没有任何理由在模式中包含这些指令。

所以我想知道在将模式文件加载到可执行模式之前,是否有一些标准方法可以从模式中删除与 mongo 相关的指令作为中间步骤?

或者有没有办法告诉 loadSchemaSync 函数忽略“未知指令”错误?

这是我当前加载架构文件的代码:

import { join } from "path";
import {loadSchemaSync, GraphQLFileLoader} from "graphql-tools"

const schema = loadSchemaSync(join(__dirname, '../src/graphql/schemas/**/*.graphql'), {
  loaders: [
    new GraphQLFileLoader()
  ]
})
4

1 回答 1

0

听起来您还没有将 mongo codegen 指令导入到您的架构中。

您应该知道graphql-tools已被弃用并且不会再收到更新。您应该使用适当的范围包,例如: https ://www.npmjs.com/package/@graphql-codegen/typescript-mongodb

查看文档中的使用示例。

https://www.graphql-code-generator.com/docs/plugins/typescript-mongodb#usage-example

import { makeExecutableSchema } from '@graphql-tools/schema';
import { DIRECTIVES } from '@graphql-codegen/typescript-mongodb';

const schema = makeExecutableSchema({
  typeDefs: [
    DIRECTIVES,
    // the rest of your GraphQL types
  ],
  resolvers,
});
于 2021-10-07T23:41:06.123 回答