我目前正在将使用graphql-js定义的模式迁移到使用typedefs和解析器的executableSchema。我想迭代地迁移我的代码库,并将它们缝合在一起。因此,让一些部分仍然使用graphql-js,而另一些部分使用gql typedefs,直到我开始研究整个模式。
当我试图在我的typedefs中重用现有类型时,我遇到了一个问题。
例如,我的typedef可能是:
type Query {
customers: [User]
}但是在我的graphql-js模式中存在User类型的定义。因此,即使在模式被缝合之后,它也会显示为Error: Type "User" not found in document。
这是可能的吗?或者我必须一次迁移所有相关的内容吗?
示例:
// The original schema is created using graphql-js
const oldSchema = new GraphQLSchema({query: ..., mutation: ...});
// The parts I'm slowly migrating to use graphql-tools
const newSchema = makeExecutableSchema({ typeDefs: ..., resolvers: ...});
// Then putting them together
const mergedSchema = mergeSchemas({schemas: [oldSchema, newSchema]})发布于 2019-02-01 22:47:39
我不确定这是否适用于你的“旧模式”,但在我的项目中,我用以下方式合并了它们……
import requireGraphQLFile from 'require-graphql-file';
import {makeExecutableSchema } from 'apollo-server';
const schema1= requireGraphQLFile('./schema/schema1');
const schema2= requireGraphQLFile('./schema/schema2');
const schema3= requireGraphQLFile('./schema/schema3');
const schema = makeExecutableSchema({
typeDefs: [schema1,schema2, schema3],
resolvers
});https://stackoverflow.com/questions/54412079
复制相似问题