我想咨询有关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
}
它的结果是这样的: 类型名称 { 名字: 字符串! 姓氏: 字符串! }
type Address {
street: String!
number: Int!
}
type User {
name: Name!
address: Address!
}
type Query {
user(userId: String!): User
}
在最终模式中只显示一个用户类型。 我尝试使用
mergeSchemas
中的onTypeConflict
API来扩展类型,但是没有取得任何结果。是否有一种方法可以通过扩展冲突的类型来合并模式?