mirumee / ariadne

Python library for implementing GraphQL servers using schema-first approach.
https://ariadnegraphql.org
BSD 3-Clause "New" or "Revised" License
2.2k stars 179 forks source link

[federation] support new `@interfaceObject` directive #1032

Closed dariuszkuc closed 1 year ago

dariuszkuc commented 1 year ago

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.

dariuszkuc commented 1 year ago

For convenience -> link to the Federation v2.3 subgraph spec definitions

dariuszkuc commented 1 year ago

Support added in https://github.com/mirumee/ariadne/pull/1060

rafalp commented 1 year ago

Hey @dariuszkuc, just wanted to say that I appreciate you taking time keep an eye on Federation support in Ariadne.

Thank you <3