Apollo Federation (Gateway): how to send different "keys" to different implementing microservices?

593 views Asked by At

I am trying to compose a federated apollo service with a gateway and 3 implementing microservices.

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 provides a name and an id. name shall be send to MS3 for the resolving process and id shall be used by MS2 for the resolving process.

This approach worked with an older version of apollo-gateway / apollo-server, but with the latest versions I receive the following error messages.

{"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   ...}

An approach to provide the keys like this didn't work either:

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

What does the schema have to look like to provide the described use case?

0

There are 0 answers