[federation] support new `@interfaceObject` directive
dariuszkuc opened this issue · comments
Apollo Federation v2.3 introduced new @interfaceObject
directive that allows users to extend entity functionality through inheritance, i.e. given subgraph A
interface Product {
id: ID!
title: String
}
# Book entity with key
type Book implements Product @key(fields: "id") {
id: ID!
title: String
pages: Int
}
# Movie entity with key
type Movie implements Product @key(fields: "id") {
id: ID!
title: String
duration: Int
}
We can generically extend the Product interface in other subgraphs by treating it as local object type with @interfaceObject
directive. This new directive informs composition logic that it is actually an entity interface. This allows us to add new functionality in subgraph B without knowing any existing implementation details (i.e. without knowing anything about Book and Movie types).
type Product @key(fields: "id") @interfaceObject {
id: ID!
reviews: [Review!]!
}
type Review {
author: String
text: String
rating: Int
}
Additional resources:
New directive functionality can be tested using Apollo Federation Subgraph Compatibility NPX script (and Github Action). Example integration project is already provided in the subgraph compatibility testing repository.
I'll take this one
For convenience -> link to the Federation v2.3 subgraph spec definitions