我有一个GraphQL模式,该模式使用缝合将远程模式与本地定义的模式一起包括在内。
我的拼接逻辑如下:
const link = new HttpLink({
uri: config.cms.endpoint,
fetch,
});
const remoteSchema = await introspectSchema(link);
const remoteExecutableSchema = makeRemoteExecutableSchema({
schema: remoteSchema,
link,
});
const localExecutableSchema = makeExecutableSchema({
typeDefs,
resolvers,
});
const mergedSchema = mergeSchemas({
schemas: [
localExecutableSchema,
remoteExecutableSchema,
],
});
const apolloServer = new ApolloServer({
schema: mergedSchema,
...
导入的typeDefs
变量包含以下定义:
input OrderItem {
alphaId: ProductAlphaId!
addOns: [ProductAlphaId]!
}
remoteSchema
包含ProductAlphaId
的定义。但是,由于它是在“远程”模式(而不是本地模式)中定义的,因此在启动服务器时出现错误:
Could not start server: Unknown type "ProductAlphaId".
我应该如何使用另一个模式的类型?我知道这可能会产生循环依赖关系,但就我而言,我只想在“第二个”中使用“第一个”模式中的类型。
答案 0 :(得分:0)
这可能是问题所在,您需要在合并时检查架构的顺序。
...
const mergedSchema = mergeSchemas({
schemas: [
remoteExecutableSchema,
localExecutableSchema
],
});
...