Add the prepared-query API skeleton (Step 2 of #490) - #491
Open
zipdoki wants to merge 1 commit into
Open
Conversation
5 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Step 2 of #490. This adds the API surface for prepared queries — endpoints, payloads, and a service declaration — with no implementation behind it. Every service method is
TODO("Not yet implemented"), so what I'm asking for is a review of the shape.Part of #490.
Design notes
Three decisions I'd like checked:
"limit": "{limit}"is text where anIntbelongs — the declared type is what makes it a number on the way in./graph/v3, not under a database. A multi-hop query names its own database per step and may name several.Changes
PreparedQueryServicewithregister/amend/get/list/delete, the alias pair, andquery— allTODOPreparedQueryControllerfor/graph/v3/prepared-queriesand/graph/v3/prepared-queries/aliasesargumentsonPOST /graph/v3/query/{id}ReadOnlyRequestFilter;POST /graph/v3/query/{id}reads, and its path ends in a variable so no suffix matchesHow to Test
The endpoint-exhaustiveness check in
ReadOnlyRequestFilterTestcovers the ten new mappings. Nothing else can be tested until the service has a body, so the requests below are the shape under review rather than a transcript.Register a query, then give it a name:
Run it, by the name or by the id:
{ "items": [ {"name": "result", "data": [{"itemId": "item1", "metric": 2}], "rows": 1, "stats": [], "offset": null, "hasNext": false} ] }Declared arguments are all required, and a value of the wrong JSON type is read as the declared one, so
"limit": "100"binds the same way100does.Reads, moving a name, and editing a query in place
{id}takes either form. A name has to satisfy the metadata naming policy and a generated id can't, so the two can never collide and the shape of the path variable says which was meant. Listings answer with a bare array and take?status=ACTIVE|INACTIVE|ALL, as the table and alias listings do.A registered query reads back as it was written, placeholders and all — what's stored is a template, not a query with values in it:
{ "tenant": "local", "id": "3f2c8a91-7d4e-4b12-9c33-0a51e6b8d204", "arguments": [ {"name": "entity", "type": "string", "comment": "the user asked about", "nullable": false}, {"name": "limit", "type": "int", "comment": "how many ranked rows", "nullable": false} ], "fetch": [{"type": "TOPK", "name": "ranked", "database": "shop", "table": "purchases_table", "topk": "top_purchased", "entity": {"type": "VALUE", "value": ["{entity}"]}, "limit": "{limit}", "...": "..."}], "transform": [{"type": "SQL", "name": "result", "sql": "SELECT target AS itemId, metric FROM ranked WHERE metric >= {minMetric} ORDER BY metric DESC"}], "stats": [], "active": true, "comment": "top purchased items for one user, in one category" }The response also carries the
revision/createdAt/createdBy/updatedAt/updatedByfields every other v3 descriptor does, at their defaults.Moving a name is one call, and sending the old id back is the rollback:
Editing a query leaves the parts that weren't sent as they were:
Not touched
Storage, and the two decisions recorded in #490 — where these rows live, and how fast a moved name propagates.
POST /graph/v3/queryalso still takes a query with noarguments: that needs binding which doesn't exist yet, and declaring the field before it works would be a lie.AI Assistance