如何联合提供相同类型的两个apollo服务



我是apollo的新手,我有两个apollo服务,我想通过使用apollo联合来联合:

产品服务:

extend type Query {
job(id: String!): Job
}
type Seo {
title: String! 
description: String! 
keywords: String! 
}
type Product @key(fields: "id")  {
id: ID!
title: String!
seo: Seo!
}

员工服务:

extend type Query {
staffMember(id: String!): StaffMember
}
type Seo {
title: String! 
description: String! 
keywords: String! 
}
type StaffMember @key(fields: "id")  {
id: ID!
title: String!
seo: Seo!
}

如何在两个对象的响应对象中使用Seo类型?创建接口Seo并实现StaffMemberSeo和ProductSeo的正确过程是正确的吗?还是有一个注释允许我在两个服务中定义完全相同的类型?

一个服务必须拥有该类型。在该服务中使用@key指令。在引用服务中,使用@extend,并包含该服务使用的带有字段的类型的存根。

将其视为SQL数据库中的外键。

最新更新