1

我正在尝试用一个网关和 3 个实现微服务来组成一个联合阿波罗服务。

MS1:

type Movie @key(fields: "id name") {
    id: String!
    name: String
}

MS2:

type Location @key(fields: "id") {
    id: String!
    longitude: Float!
    latitude: Float!
} 

type Movie @key(fields: "id") @extends {
    id: String! @external
    location: Location
}

MS3:

type Award @key(fields: "name"){
    name: String!
    count: Int
} 

type Movie @key(fields: "name") @extends {
    name: String! @external
    award: Award
}

MS1 提供nameidname应发送到 MS3 用于解析过程,id应由 MS2 用于解析过程。

这种方法适用于旧版本的 apollo-gateway / apollo-server,但在最新版本中我收到以下错误消息。

{"stack":"Error: A valid schema couldn't be composed. The following composition errors were found:\n\t[ms2] Movie -> extends from ms1 but specifies an invalid @key directive. Valid @key directives are specified by the originating type. Available @key directives for this type are:\n\t@key(fields: \"id name\")\n   ...}

提供这样的密钥的方法也不起作用:

type Movie @key(fields: "id") @key(fields: "name") {

模式必须是什么样子才能提供所描述的用例?

4

0 回答 0