所以我有这两个模式
架构1
type Permission {
relation: Relation
}
enum Relation {
ONE
TWO
THREE
}
模式2
type Permission {
relation: Relation
}
enum Relation {
FOUR
FIVE
SIX
}
预期结果类似于:(但我对不同的想法持开放态度)合并后我想进行的查询是:
{
permissions{
relation
}
}
并得到类似的结果
"permissions": [
{
"relation": "ONE"
},
{
"relation": "SIX"
}
]
或者
"permissions": [
{
"relation": "schema1ONE"
},
{
"relation": "schema2SIX"
}
]
和突变如:
mutation{
createPermission(
relation: ONE
){
relation
}
}
mutation{
createPermission(
relation: SIX
){
relation
}
}
或者
mutation{
createPermission(
relation: schema1ONE
){
relation
}
}
mutation{
createPermission(
relation: schema2SIX
){
relation
}
}
我正在尝试transformSchema
在 graphql-tools 上使用该功能,但不能完全正确地弄清楚:
const Schema1 = await getRemoteSchema('schema1_url', 'schema1');
const Schema2 = await getRemoteSchema('schema2_url', 'schema2');
const schemas = [Schema1, Schema2]
const schema = mergeSchemas({
schemas: schemas,
resolvers: {}
});
getRemoteSchema 定义
export const getRemoteSchema = async (uri: string, schemaName: string): Promise<GraphQLSchema> => {
const httpLink = new HttpLink({ uri, fetch });
const schema = await introspectSchema(httpLink);
const executableSchema = makeRemoteExecutableSchema({
schema,
httpLink,
});
// transform schema by renaming root fields and types
const renamedSchema = transformSchema(
executableSchema,
[
new RenameTypes(name => {
if (name == 'Relation') {
return schemaName + name
} else {
return name
}
}),
// new RenameRootFields((operation, name) => `${schemaName}_${name}`)
]
);
return renamedSchema;
}
我做了这个故障https://glitch.com/edit/#!/schema-stitching-conflict 所以更容易看到问题。