Return the total match count alongside files query results — Closes #76#78
Draft
conradbzura wants to merge 2 commits into
Draft
Return the total match count alongside files query results — Closes #76#78conradbzura wants to merge 2 commits into
conradbzura wants to merge 2 commits into
Conversation
The files GraphQL query returned a bare list, so a client had no way to
learn how many documents matched its filter and could not size
pagination controls; a short page was the only end-of-results signal,
which is wrong whenever the total is an exact multiple of pageSize.
files now returns a FileList envelope: items carries the requested page
and totalCount reports the full match count for the input filter, before
page and pageSize are applied. The count is issued concurrently with the
page fetch via asyncio.gather, reusing the filter already built for the
query, so latency is the max of the two round trips rather than the sum.
Tests migrate the existing files-query cases to the envelope shape and
add example and property-based coverage for totalCount, including that it
stays invariant across pagination windows and empty results.
BREAKING CHANGE: files returns FileList { totalCount, items } instead of
a list of files. Callers must move their field selection under items.
Claude-Session: https://claude.ai/code/session_01654cZBZnxJUcvPwahVGmeb
Update the GraphQL query examples to the new FileList envelope, selecting totalCount alongside items. Also fix two pre-existing inaccuracies in the same section: the API exposes three queries, not two (distinctValues was added later), and the pageSize default is 25, not 100. Claude-Session: https://claude.ai/code/session_01654cZBZnxJUcvPwahVGmeb
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
Change the
filesGraphQL query to return aFileListenvelope —{ totalCount, items }— instead of a bare list.itemscarries the requested page andtotalCountreports the full number of documents matching theinputfilter, beforepage/pageSizeare applied, so clients can size pagination controls instead of guessing from a short final page.totalCountis served bycount_documentsreusing the same filter already built for the page query, issued concurrently with the page fetch viaasyncio.gatherso latency is the max of the two round trips rather than their sum. This was chosen over a single$facetaggregation because the in-memory test double implementscount_documentsbut notaggregate, and over a separate siblingfileCountquery because the count should travel with the results in one round trip.This is a deliberate breaking change to the GraphQL contract: every caller of
filesmust move its field selection underitems. The blast radius is contained —tests/test_schema.pyis the only in-repo consumer; the CLI, REST routers, sync service, and Rust materializer all read MongoDB directly.Closes #76
Proposed changes
src/cfdb/api/gql/types.py— Add aFileListStrawberry type withtotal_count: intanditems: List[FileMetadataType], exposed in the schema astotalCount/items.src/cfdb/api/gql/schema.py— Change thefilesresolver to returnFileList, fetching the count and the page concurrently. Thewait_for_cutovergate and filter translation are unchanged;fileanddistinctValuesare untouched.schema.graphql— Regenerate the committed schema snapshot:filesnow returnsFileList!, plus the newtype FileListblock.README.md— Update the GraphQL examples to the envelope shape, and correct two pre-existing inaccuracies in the same section: the API exposes three queries (not two), and thepageSizedefault is 25 (not 100).tests/test_schema.py— Migrate the existingfiles-query tests to the envelope shape and add example plus property-based coverage fortotalCount.Test cases
TestFilesQuerypageSizeof 2filesquery runsTestFilesQuerypageSizeof 2filesquery runstotalCountis 3 whileitemsholds 2totalCountindependent of page sizeTestFilesQuerytotalCountis 3 on both pagestotalCountstable across pagesTestFilesQueryfilesquery runstotalCountis 3 with emptyitemsTestFilesQueryfilesquery filters on an absent filenametotalCount0 and emptyitems, not nullTestFilesQueryfilesquery filters on 4DNtotalCountis 2, not the collection totaltotalCountreflects the filterTestFilesQuerypage/pageSizefilesquery runs across generated pagination windowstotalCountis always 12 anditemsmatches the page sliceTestFilesQueryfilesquery selects those nested fieldshttps://claude.ai/code/session_01654cZBZnxJUcvPwahVGmeb