-
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
Allow hoisted+parallelized execution of a subgraph's contributed entity fields #3141
Comments
In general the proposed solution is, I think, somewhat problematic. For this to be a valid operation, we must have guarantees on the behaviour of the
Other approachesThe federation spec actually allows both subgraphs to declare the
This results in a query plan like:
I think in general it would be better to optimise the general case, as I suggest here, which should solve for your use case too: #2653 (comment) Stopgap solutionIf you don't want to duplicate the definition of type Query {
user(id: ID): User
}
type User @key(fields: "id") {
id: ID!
} And the rest of your schema omitting type Query {
someOtherField: Boolean!
}
type User @key(fields: "id") {
id: ID!
name: String!
} This will force the federation plan to always hop services after the call to I have created a branch on my federation defer POC repository to show it is effective for your use case, and also to show that Apollo Router can utilise a |
Thanks for the response @meiamsome! I really like the stopgap solution, nice and sneaky :) As for the class of concerns raised with likely any API here, there would indeed have to be some element of "trust me 😎" - this is unavoidable given the distributed nature. Prior art: the "trust me" approach is already the case for
I agree with your concerns, and I don't think there's any magic way around it - it would be part of the tradeoff when implementing this. |
👋 Consider this query:
And our query plan looks like this:
Query.user
andUser.name
lives in our legacy monolithUser.profilePhoto
lives in a new subgraphPretty standard stuff.
But upon migrating out the
profilePhoto
resolver to the new subgraph, teams notice "hey i have an extra waterfall", and they can't start hitting the database to fetch the profile photo untillegacy_monolith
finishes resolving - but there's no real dependency there.With larger types, more fields and more subgraphs, we become more sensitive and exposed to this issue.
Very related discussion here https://gist.github.com/magicmark/cbda3eedf1255334caee357fde7680de
Problem statement
Child subgraphs are blocked from resolving entity fields until the parent subgraph yields.
Proposal
In the above example, we have a very simplified example of
Query.user(id: ID): User
. In the initial request to the router, we already have the argument (id
) that would be required to call__resolveReference
infancy_new_photos_subgraph
.This won't always be the case - e.g.
Query.searchUser(name: String): User
- this would require thesearchUser
to finish yielding before we can get an ID.But many of our use cases, our
@key(fields: ...)
information is already available from the request object.It would be cool to declare schema like this:
If all fields in the child subgraph query's selection set are being referenced via
id
with a matchinghoistable
argument, then the subgraph could call its__resolveReference
in parallel with the query to the monolith.The text was updated successfully, but these errors were encountered: