Skip to content

Commit

Permalink
measure the number of generated query plans
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Aug 23, 2024
1 parent 28947fc commit 2883d18
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 19 deletions.
3 changes: 3 additions & 0 deletions router-bridge/js-src/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ExecutionResultWithUsageReporting<T>
export interface QueryPlanResult {
formattedQueryPlan: string;
queryPlan: QueryPlan;
evaluatedPlanCount: number;
}

export interface PlanOptions {
Expand Down Expand Up @@ -122,11 +123,13 @@ export class BridgeQueryPlanner {
formattedQueryPlan = null;
}

let statistics = this.planner.lastGeneratedPlanStatistics();
return {
usageReporting,
data: {
queryPlan,
formattedQueryPlan,
evaluatedPlanCount: statistics.evaluatedPlanCount,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: router-bridge/src/planner.rs
expression: "serde_json::to_string_pretty(&dbg!(planner.plan(\"query { currentUser { activeOrganization { id suborga { id ...@defer { nonNullId } } } } }\".to_string(),\n None).await.unwrap()).data.unwrap()).unwrap()"
expression: "serde_json::to_string_pretty(&planner.plan(\"query { currentUser { activeOrganization { id suborga { id ...@defer { nonNullId } } } } }\".to_string(),\n None,\n PlanOptions::default()).await.unwrap().data.unwrap()).unwrap()"
---
{
"queryPlan": {
Expand Down Expand Up @@ -102,5 +102,6 @@ expression: "serde_json::to_string_pretty(&dbg!(planner.plan(\"query { currentUs
]
}
},
"formattedQueryPlan": "QueryPlan {\n Defer {\n Primary {\n {\n currentUser {\n activeOrganization {\n id\n suborga {\n id\n }\n }\n }\n }:\n Sequence {\n Fetch(service: \"user\") {\n {\n currentUser {\n activeOrganization {\n __typename\n id\n }\n }\n }\n },\n Flatten(path: \"currentUser.activeOrganization\") {\n Fetch(service: \"orga\", id: 0) {\n {\n ... on Organization {\n __typename\n id\n }\n } =>\n {\n ... on Organization {\n suborga {\n __typename\n id\n }\n }\n }\n },\n },\n }\n }, [\n Deferred(depends: [0], path: \"currentUser/activeOrganization/suborga\") {\n {\n nonNullId\n }:\n Flatten(path: \"currentUser.activeOrganization.suborga.@\") {\n Fetch(service: \"orga\") {\n {\n ... on Organization {\n __typename\n id\n }\n } =>\n {\n ... on Organization {\n nonNullId\n }\n }\n },\n }\n },\n ]\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Defer {\n Primary {\n {\n currentUser {\n activeOrganization {\n id\n suborga {\n id\n }\n }\n }\n }:\n Sequence {\n Fetch(service: \"user\") {\n {\n currentUser {\n activeOrganization {\n __typename\n id\n }\n }\n }\n },\n Flatten(path: \"currentUser.activeOrganization\") {\n Fetch(service: \"orga\", id: 0) {\n {\n ... on Organization {\n __typename\n id\n }\n } =>\n {\n ... on Organization {\n suborga {\n __typename\n id\n }\n }\n }\n },\n },\n }\n }, [\n Deferred(depends: [0], path: \"currentUser/activeOrganization/suborga\") {\n {\n nonNullId\n }:\n Flatten(path: \"currentUser.activeOrganization.suborga.@\") {\n Fetch(service: \"orga\") {\n {\n ... on Organization {\n __typename\n id\n }\n } =>\n {\n ... on Organization {\n nonNullId\n }\n }\n },\n }\n },\n ]\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: router-bridge/src/planner.rs
assertion_line: 1908
expression: "serde_json::to_string_pretty(&plan_response).unwrap()"
---
{
Expand Down Expand Up @@ -29,5 +28,6 @@ expression: "serde_json::to_string_pretty(&plan_response).unwrap()"
]
}
},
"formattedQueryPlan": "QueryPlan {\n Defer {\n Primary {\n {\n computer(id: \"Computer1\") {\n id\n }\n }:\n Fetch(service: \"computers\") {\n {\n computer(id: \"Computer1\") {\n id\n errorField\n }\n }\n }\n }, [\n Deferred(depends: [], path: \"computer\") {\n {\n ... on Computer {\n errorField\n }\n }:\n },\n ]\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Defer {\n Primary {\n {\n computer(id: \"Computer1\") {\n id\n }\n }:\n Fetch(service: \"computers\") {\n {\n computer(id: \"Computer1\") {\n id\n errorField\n }\n }\n }\n }, [\n Deferred(depends: [], path: \"computer\") {\n {\n ... on Computer {\n errorField\n }\n }:\n },\n ]\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ expression: "serde_json::to_string_pretty(&planner.plan(\"query Search($moviePar
]
}
},
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"searchSubgraph\") {\n {\n search {\n __typename\n ... on MovieResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n ... on ArticleResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n }\n }\n },\n Flatten(path: \"[email protected].@\") {\n Fetch(service: \"artworkSubgraph\") {\n {\n ... on EntityCollectionSection {\n __typename\n id\n }\n } =>\n {\n ... on EntityCollectionSection {\n artwork(params: $movieParams)\n title\n }\n }\n },\n },\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"searchSubgraph\") {\n {\n search {\n __typename\n ... on MovieResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n ... on ArticleResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n }\n }\n },\n Flatten(path: \"[email protected].@\") {\n Fetch(service: \"artworkSubgraph\") {\n {\n ... on EntityCollectionSection {\n __typename\n id\n }\n } =>\n {\n ... on EntityCollectionSection {\n artwork(params: $movieParams)\n title\n }\n }\n },\n },\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ expression: "serde_json::to_string_pretty(&planner.plan(\"query Search($moviePar
]
}
},
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"searchSubgraph\") {\n {\n search {\n __typename\n ... on MovieResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n ... on ArticleResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n }\n }\n },\n Parallel {\n Flatten(path: \".search.@|[MovieResult].sections.@\") {\n Fetch(service: \"artworkSubgraph\") {\n {\n ... on EntityCollectionSection {\n __typename\n id\n }\n } =>\n {\n ... on EntityCollectionSection {\n artwork(params: $movieParams)\n }\n }\n },\n },\n Flatten(path: \".search.@|[ArticleResult].sections.@\") {\n Fetch(service: \"artworkSubgraph\") {\n {\n ... on EntityCollectionSection {\n __typename\n id\n }\n } =>\n {\n ... on EntityCollectionSection {\n artwork(params: $articleParams)\n title\n }\n }\n },\n },\n },\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"searchSubgraph\") {\n {\n search {\n __typename\n ... on MovieResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n ... on ArticleResult {\n id\n sections {\n __typename\n ... on EntityCollectionSection {\n __typename\n id\n }\n }\n }\n }\n }\n },\n Parallel {\n Flatten(path: \".search.@|[MovieResult].sections.@\") {\n Fetch(service: \"artworkSubgraph\") {\n {\n ... on EntityCollectionSection {\n __typename\n id\n }\n } =>\n {\n ... on EntityCollectionSection {\n artwork(params: $movieParams)\n }\n }\n },\n },\n Flatten(path: \".search.@|[ArticleResult].sections.@\") {\n Fetch(service: \"artworkSubgraph\") {\n {\n ... on EntityCollectionSection {\n __typename\n id\n }\n } =>\n {\n ... on EntityCollectionSection {\n artwork(params: $articleParams)\n title\n }\n }\n },\n },\n },\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationKind": "query"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n last\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n last\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationKind": "query"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ... on A {\n x\n y\n t {\n __typename\n ... on A {\n x\n y\n }\n ... on B {\n z\n }\n }\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ... on A {\n x\n y\n t {\n __typename\n ... on A {\n x\n y\n }\n ... on B {\n z\n }\n }\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationKind": "query"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ... on A {\n x\n y\n t {\n __typename\n ... on A {\n x\n y\n }\n ... on B {\n z\n }\n }\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ... on A {\n x\n y\n t {\n __typename\n ... on A {\n x\n y\n }\n ... on B {\n z\n }\n }\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationKind": "query"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ..._generated_onA3_0\n }\n }\n \n fragment _generated_onA2_0 on A {\n x\n y\n }\n \n fragment _generated_onA3_0 on A {\n x\n y\n t {\n __typename\n ..._generated_onA2_0\n ... on B {\n z\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n ..._generated_onA3_0\n }\n }\n \n fragment _generated_onA2_0 on A {\n x\n y\n }\n \n fragment _generated_onA3_0 on A {\n x\n y\n t {\n __typename\n ..._generated_onA2_0\n ... on B {\n z\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationName": "MyFirstAndLastName__accounts__0"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n last\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n last\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationName": "MyFirstName__accounts__0"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationName": "MyFirstAndLastName__accounts__0"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n last\n }\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"accounts\") {\n {\n me {\n name {\n first\n last\n }\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ expression: "serde_json::to_string_pretty(&query_plan2.data).unwrap()"
]
}
},
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"accounts\") {\n {\n me {\n __typename\n id\n name {\n first\n }\n }\n }\n },\n Flatten(path: \"me\") {\n Fetch(service: \"reviews\") {\n {\n ... on User {\n __typename\n id\n }\n } =>\n {\n ... on User {\n reviews {\n id\n author {\n __typename\n id\n }\n body\n }\n }\n }\n },\n },\n Flatten(path: \"[email protected]\") {\n Fetch(service: \"accounts\") {\n {\n ... on User {\n __typename\n id\n }\n } =>\n {\n ... on User {\n name {\n first\n }\n }\n }\n },\n },\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"accounts\") {\n {\n me {\n __typename\n id\n name {\n first\n }\n }\n }\n },\n Flatten(path: \"me\") {\n Fetch(service: \"reviews\") {\n {\n ... on User {\n __typename\n id\n }\n } =>\n {\n ... on User {\n reviews {\n id\n author {\n __typename\n id\n }\n body\n }\n }\n }\n },\n },\n Flatten(path: \"[email protected]\") {\n Fetch(service: \"accounts\") {\n {\n ... on User {\n __typename\n id\n }\n } =>\n {\n ... on User {\n name {\n first\n }\n }\n }\n },\n },\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ expression: "serde_json::to_string_pretty(&payload2.data).unwrap()"
]
}
},
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n k\n }\n }\n },\n Flatten(path: \"t\") {\n Fetch(service: \"Subgraph2\") {\n {\n ... on T {\n __typename\n k\n }\n } =>\n {\n ... on T {\n a\n }\n }\n },\n },\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Sequence {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n __typename\n k\n }\n }\n },\n Flatten(path: \"t\") {\n Fetch(service: \"Subgraph2\") {\n {\n ... on T {\n __typename\n k\n }\n } =>\n {\n ... on T {\n a\n }\n }\n },\n },\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ expression: "serde_json::to_string_pretty(&payload1.data).unwrap()"
"operationKind": "query"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n a\n }\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n a\n }\n }\n },\n}",
"evaluatedPlanCount": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ expression: "serde_json::to_string_pretty(&payload.data).unwrap()"
"operationKind": "query"
}
},
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n a1 {\n ...Selection\n }\n a2 {\n ...Selection\n }\n }\n }\n \n fragment Selection on A {\n x\n y\n }\n },\n}"
"formattedQueryPlan": "QueryPlan {\n Fetch(service: \"Subgraph1\") {\n {\n t {\n a1 {\n ...Selection\n }\n a2 {\n ...Selection\n }\n }\n }\n \n fragment Selection on A {\n x\n y\n }\n },\n}",
"evaluatedPlanCount": 1
}
Loading

0 comments on commit 2883d18

Please sign in to comment.