Graphql Apollo服务器模式缝合使用合并模式,如何使用单独模式中的类型?
我目前正在将一个模式从使用Graphql Apollo服务器模式缝合使用合并模式,如何使用单独模式中的类型?,graphql,apollo,graphql-js,apollo-server,Graphql,Apollo,Graphql Js,Apollo Server,我目前正在将一个模式从使用graphql js定义迁移到使用typedefs和解析器的可执行模式。我想迭代地迁移代码库并将它们缝合在一起。所以有些部分仍然使用graphqljs,有些部分使用gqltypedefs,直到我开始做整个模式 当我尝试在typedefs中重用现有类型时,遇到了一个问题 例如,我的typedef可能是: type Query { customers: [User] } 但是User类型的定义存在于我的graphqljs模式中。所以它会说Error:Type“User
graphql js
定义迁移到使用typedefs和解析器的可执行模式。我想迭代地迁移代码库并将它们缝合在一起。所以有些部分仍然使用graphqljs
,有些部分使用gql
typedefs,直到我开始做整个模式
当我尝试在typedefs中重用现有类型时,遇到了一个问题
例如,我的typedef可能是:
type Query {
customers: [User]
}
但是User
类型的定义存在于我的graphqljs
模式中。所以它会说Error:Type“User”在文档中找不到,即使在缝合模式之后也是如此
这是可能的还是我必须一次迁移所有相关的东西
例如:
// 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]})
我不确定这是否适用于您的“旧模式”,但在我的项目中,我以以下方式合并了它们
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
});
有趣的问题,您可以添加运行mergeSchemas
的方式吗?不清楚您为什么要谈论executableSchema
,而不是makeRemoteExecutableSchema
@yevheniherasymchuk谢谢您的评论。原始模式是使用graphqljs
创建的,因此其创建使用:constoldschema=newgraphqlschema({query:…,mutation:…})代码>我正在慢慢迁移到使用graphql工具的部分,比如:const newSchema=makeExecutableSchema({typeDefs:…,resolvers:…})代码>然后把它放在一起:const mergedSchema=mergeSchemas({schemas:[oldSchema,newSchema]})
哦,我明白了,你的示例代码帮助很大。谢谢