如何使用 graphql-tools 从两个源位置加载 GraphQL 模式?

How to load a GraphQL schema from two source locations with graphql-tools?

我想从不同位置(本地应用程序和公共模块)加载 graphql 模式。我愿意:

export function GraphqlServer(
    resolvers: Record<string, IResolvers>,
    config?: Config
) {
    const localScheme = '**/*.graphql';
    const commonSchema = join(
        __dirname,
        './packages/common/src/graphql/api/**/*.graphql'
    );
    const schema = loadSchemaSync([localScheme, commonSchema], {
        loaders: [new GraphQLFileLoader()]
    });

    const schemaWithResolvers = addResolversToSchema({
        schema,
        resolvers: {
            ...resolvers,
            Date,
            DateTime,
            JSON
        }
    });

但是好像只加载了第一个位置的架构。我收到一个错误

Error: Unknown type "GetExternalConfluencePage".

在第二个位置的 .graphql 文件中定义。如果我将此文件从第二个位置移动到第一个位置,它就会工作。

.graphql文件内容为:

input GetExternalConfluencePage {
    confluencePageId: String!
}

type ExternalConfluencePage {
    title: String!
    body: String!
}

第一个位置的 .graphql 文件包含:

type Query {
    macro(input: GetMacroInput!): Macro!
    externalConfluencePage(
        input: GetExternalConfluencePage!
    ): ExternalConfluencePage
}

任何提示可能是什么问题?

它工作得很好。

例如

index.ts

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

const localScheme = join(__dirname, './local.graphql');
const commonSchema = join(__dirname, './common/*.graphql');
const schema = loadSchemaSync([localScheme, commonSchema], {
  loaders: [new GraphQLFileLoader()],
});

console.log(printSchema(schema));

common/common.graphql:

input GetExternalConfluencePage {
  confluencePageId: String!
}

type ExternalConfluencePage {
  title: String!
  body: String!
}

local.graphql:

type Query {
  externalConfluencePage(input: GetExternalConfluencePage!): ExternalConfluencePage
}

将加载的 GraphQL 模式打印到控制台:

input GetExternalConfluencePage {
  confluencePageId: String!
}

type ExternalConfluencePage {
  title: String!
  body: String!
}

type Query {
  externalConfluencePage(input: GetExternalConfluencePage!): ExternalConfluencePage
}

包版本:

"graphql": "^15.4.0",
"graphql-tools": "^6.2.3",