2

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?

ashiaka
  • 3,994
  • 8
  • 32
  • 45
  • Have you found a solution for this? Thanks. – Le D. Thang Jun 30 '21 at 10:19
  • 2
    Not one I am very happy with, but I got it working like this: Keep MS 1 as it is. Then change on MS 2: type Location \@key(fields: "id") { id: String! longitude: Float! latitude: Float! } type Movie \@key(fields: "id name") @extends { id: String! \@external name: String! \@external location: Location } MS2 now gets name also, even if it doesn't need it for anything. MS3 can be changed accordingly. Also, remove backslashes in front of the \@ . Had to escape them for stackoverflow :( – ashiaka Jul 01 '21 at 11:12

0 Answers0