Add fileCount GraphQL query for match counts without paging — Closes #77#79
Draft
conradbzura wants to merge 3 commits into
Draft
Add fileCount GraphQL query for match counts without paging — Closes #77#79conradbzura wants to merge 3 commits into
conradbzura wants to merge 3 commits into
Conversation
Obtaining the number of files matching a filter meant issuing the files query, which also fetches and hydrates a page of file documents the caller then discards. Clients that only need the size of a result set -- sizing pagination controls, "N files match" labels, faceting UIs that count many filter permutations -- paid for a page they never use. fileCount accepts the same FileMetadataInput filter shape as files and distinctValues and returns a scalar Int, running only count_documents against the filter. It reuses the shared to_query/to_dict filter path and the cutover wait, so an absent filter counts every file. Claude-Session: https://claude.ai/code/session_01Y5eYL9rN5xCDbwTQZrjwky
Note fileCount in the GraphQL Queries section with an example showing it takes the same FileMetadataInput filter as files and returns a count without fetching any documents. Claude-Session: https://claude.ai/code/session_01Y5eYL9rN5xCDbwTQZrjwky
Add TestFileCountQuery: the unfiltered total, a filtered subset, no-match and empty-database zeros, the empty-input-list count-all edge, OR across multiple values in one field, OR across multiple input entries, AND across multiple fields, agreement with the files result length for the same filter, and a property-based invariant that the count equals the number of documents matching a generated filter. Claude-Session: https://claude.ai/code/session_01Y5eYL9rN5xCDbwTQZrjwky
Collaborator
Author
|
FYI @john-conroy - the PR body has usage examples for this. Decided to make it a separate endpoint since it's not a breaking change. |
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
Add a
fileCountGraphQL query that returns the number of files matching a filter without fetching any file documents. Obtaining a match count previously meant issuing thefilesquery, which also fetches and hydrates a page of documents the caller then discards — wasteful for clients that only need the size of a result set (pagination controls, "N files match" labels, faceting UIs that count many filter permutations).The new resolver mirrors the existing
distinctValuesquery in form: it accepts the same[FileMetadataInput]filter shape asfiles/distinctValues, reuses the sharedto_query(to_dict(input))filter-building path and thewait_for_cutoverguard, and returns a scalarInt!by running onlycount_documentsagainst the filter. An absent (or empty) filter counts every file.This branch is standalone on
master, wherefilesstill returns a bare list; there is nototalCountenvelope to reconcile (that work lives on a separate branch/PR).Closes #77
Example
Count files from a specific DCC:
Count every file (no filter):
Response:
{ "data": { "fileCount": 1234 } }Over HTTP:
Proposed changes
Add the
fileCountresolverAdd
Query.file_countinsrc/cfdb/api/gql/schema.py, exposed in the schema asfileCount(input: [FileMetadataInput!] = null): Int!. It awaitslocks.wait_for_cutover(), builds the Mongo filter withto_query(to_dict(input)) if input else {}(identical tofiles/distinct_values), and returnsawait api.db.files.count_documents(query). Regenerate the committedschema.graphqlSDL snapshot to add the field.Document the query
Note
fileCountin the README GraphQL Queries section with an example, showing it takes the sameFileMetadataInputfilter asfilesand returns a count without fetching documents.Cover the query with tests
Add
TestFileCountQuerytotests/test_schema.pyexercising the resolver end-to-end throughschema.execute, including OR/AND filter construction, cross-query agreement withfiles, and a property-based invariant.Test cases
TestFileCountQueryfileCountruns with no inputTestFileCountQueryfileCountruns with a DCC filter for HuBMAPTestFileCountQueryfileCountruns with a filter for an absent DCCTestFileCountQueryfileCountruns with no inputTestFileCountQueryfileCountruns with an empty input listTestFileCountQueryfileCountruns with one field listing two abbreviationsTestFileCountQueryfileCountruns with two separate input entriesTestFileCountQueryfileCountruns with a DCC and a data-access-level filterTestFileCountQueryfileCountandfilesrun with the same filterfileCountequals thefilesresult lengthTestFileCountQueryfileCountruns with that filter