-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Router should support resolving interface implementations across subgraph #2193
Comments
The list of subgraphs against which the router should resolve abstract field could be constrained by the fragments used in the query to apply on the abstract field results. For instance, continuing with the example above, if the query looks like: query BookSupergraph {
sub_books {
... on Sub_Textbook {
title
author
courses
}
}
} the router could resolve field |
Likely a duplicate of #336 |
I added a technote to our docs covering this topic: https://www.apollographql.com/docs/technotes/TN0018-aggregating-across-subgraphs/ |
For what it's worth, I created #2277 as a dedicated issue for the proposal I laid out in my comment on #336. It is true that the first iteration of that proposal will not tackle the question of distributing the implementations of an interface over multiple subgraphs, but I do discuss that question in some details in the last sub-section of the description on #2227 (the one named "Potential future followups" ). That said, the tl;dr is that doing this in general means that, as you yourself mention above ("Router (...) can query these subgraphs separately and merge(flatten) the contents"), the router may have to query all the subgraphs having implementations of the interface. And while I get both that 1) this may be fine when you known that you have only 2 subgraphs involved and 2) very specific queries could be done more efficiently than that, it is also something that feels hard to use right and doesn't scale very well. In fact, I could even argue that this goes against some of the the main goals of federation, because:
Anyway, don't mean to completely shut the door on some support for this ever, but I want to be upfront that the current thinking is that it's a better approach to use a specific subgraph to do any kind of non-trivial dispatch (what @lennyburdette describes in his technote in the previous comment). |
I came across this while trying to figure out an approach to simplify a number of our subgraphs and wanted to suggest that maybe a limited scope of this could be supported, possibly with distinct directives that allowed a narrow composition definition. Our specific use case involves a non uniform distribution of subgraphs handling different markets for similar types. A simplified example would be something along the lines of:
Subgraph 2
Subgraph 3
In this case, as a matter of governance, we wouldn’t necessarily have any subgraph use the interface as a response type, but as a method to simplify extensions for subgraphs that cross market boundaries. Are there any considerations here I may be missing? Maybe this just isn't in the spirit of what interfaces are intended to solve? |
GraphQL abstract types (Union, Interface) could be extended or implemented by various concrete types so a field declared to return a single instance or an array of abstract types can return any of those concrete types.
This works well when all implementation or component types reside within the same subgraph.
In the federated case any subgraph could extend union type defined in the other subgraphs or implement an interface defined in the other subgraph. Unfortunately, the router does not resolve all of the components/concrete types across multiple subgraphs, it only resolves the abstract types against the declaring subgraph.
Hence we are requesting to make the router to resolve abstract types against all subgraphs that register extensions or implementations of those.
Here is an example, let's say the interface
Book
has two implementationsTextBook
andColoringBook
.Single Graph
If these interfaces were implemented in the same (sub)graph, a query on
books
would get results from both implementations.Single Graph Schema
Single Graph Query
Single Graph Query Response
Interface Implementations across subgraphs
Schema
TextBook Schema
ColoringBook Schema
Query
Response
Asks
Sub_Book
A working example is available here: https://stackblitz.com/edit/basic-federation-2-hsrxlr?file=two.js,three.js,one.js (Use Chrome)

The text was updated successfully, but these errors were encountered: