Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ The `cloudformation/backend.yml` `ImageURI` and `cloudformation/workers.yml` `Wo

### Queries

The API exposes two queries: `files` (paginated list) and `file` (single lookup by MongoDB ObjectId).
The API exposes queries including `files` (paginated list), `file` (single lookup by MongoDB ObjectId), and `fileCount` (match count for a filter).

```graphql
query {
Expand Down Expand Up @@ -180,6 +180,8 @@ curl -X POST http://localhost:8000/metadata \

Single file lookup: `{ file(id: "507f1f77bcf86cd799439011") { filename accessUrl } }`

File count for a filter: `{ fileCount(input: [{ dcc: [{ dccAbbreviation: ["4DN"] }] }]) }` — returns the number of matching files without fetching any documents. It accepts the same `FileMetadataInput` filter shape as `files`; with no `input` it counts every file.

### Query Mechanics

The GraphQL API uses an implicit OR/AND clause system for building MongoDB queries:
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ type Query {
files(input: [FileMetadataInput!] = null, page: Int! = 0, pageSize: Int! = 25): [FileMetadataType!]!
file(id: ObjectIdScalar!): FileMetadataType
distinctValues(fields: [String!]!, input: [FileMetadataInput!] = null): [DistinctFieldType!]!
fileCount(input: [FileMetadataInput!] = null): Int!
}

input SubjectInput {
Expand Down
14 changes: 14 additions & 0 deletions src/cfdb/api/gql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,19 @@ async def distinct_values(
for field, values in zip(fields, all_values)
]

@strawberry.field
async def file_count(
self,
_: strawberry.Info,
input: list[FileMetadataInput] | None = None,
) -> int:
# Wait for any database cutover to complete
await locks.wait_for_cutover()

assert api.db is not None
query = to_query(to_dict(input)) if input else {}

return await api.db.files.count_documents(query)


schema = strawberry.Schema(query=Query)
Loading
Loading