Open EXPEylazzari opened 1 year ago
Hi, I was about to open a similar issue :) My use case is to analyze the query plan and forbid some queries depending on it because subgraphs are located in different regions. It would be ideal if the QueryPlan root node and the PlanNode enum were public or had getters
I would also like to see this happen. My use case is to produce some instrumentation around query behaviors, such as looking at the depth and total number of calls a query expands to.
As a workaround, I think I can "serialize" the plan into something like serde_json::Value
, then re-hydrate it back into something useful. A simple getter for the root node (&PlanNode
) would be far nicer, both for efficiency and correctness.
This should allow a lot of custom behavior without allowing the user to accidentally mess up the query plan, as which appears to be the reasoning for #1558.
Is your feature request related to a problem? No. It's really more of an improvement, but I filed it as a feature request given this requires code changes. Not sure if this was the right thing to do.
For local development, when designing a schema, and even after in production, it is useful to be able to quickly see the execution plan of a query that is being made against the router.
At this time, the
QueryPlan
struct derives theDebug
trait (see here), so from a custom plugin, we can do something like:which generates something like this (using the sample supergraph schema from the Apollo Router doc):
or the equivalent log in JSON format:
As you can see, it's quite chatty.
The
formatted_query_plan
field of theQueryPlan
is logged in the above, but it would be nice to be able to only log that one field. Unfortunately, it is declaredpub(crate)
, like all the other fields of the struct (see here). So there's simply no way for custom plugin code to access it.Describe the solution you'd like It would be nice to simply add getter for the individual fields of the
QueryPlan
struct, such that plugin code can use them and log them as they see fit. That is, return them in such a way that we can't use the getter to then mutate the internal state of theQueryPlan
. It is strictly for read purposes.Describe alternatives you've considered None, given the fields are private, we can't access them from plugin code.
Additional context None