我有关于GraphQL Schema拼接的问题 . 我有两个Graphql架构:
type Name {
firstname: String!
lastname: String!
}
type Address {
street: String!
number: Int!
}
type User {
name: Name!
address: Address!
}
type Query {
user(userId: String!): User
}
和
type User {
age: String!
}
type Query {
user(userId: String!): User
}
我现在尝试使用graphql-tools的 mergeSchemas
函数合并模式:
const schema = mergeSchemas({
schemas: [schema1, schema2]
});
但不是我想要实现的(扩展的用户类型):
type Name {
firstname: String!
lastname: String!
}
type Address {
street: String!
number: Int!
}
type User {
name: Name!
address: Address!
age: String!
}
type Query {
user(userId: String!): User
}
它导致了这个:类型名称{firstname:String!姓氏:字符串! }
type Address {
street: String!
number: Int!
}
type User {
name: Name!
address: Address!
}
type Query {
user(userId: String!): User
}
最终架构中只显示一个UserTypes . 我尝试使用 mergeSchemas
中的 onTypeConflict
API扩展Type但我没有取得任何结果 .
有没有办法通过扩展冲突类型来合并Schemas?
2 回答
这是合并对象类型的可能解决方案 . 也许有必要在
onTypeConflict
中按类型名称进行过滤,而不是合并每种类型 .致谢:mergeObjectTypes功能由Jared Wolinsky编写 .
这应该有所帮助