Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 30497a3

Browse files
committed
testing fake pagination
1 parent 3b84808 commit 30497a3

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

graphql_api/types/commit/commit.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,16 @@ def resolve_critical_files(commit: Commit, info, **kwargs) -> List[CriticalFile]
238238
@commit_bindable.field("pathContents")
239239
@convert_kwargs_to_snake_case
240240
@sync_to_async
241-
def resolve_path_contents(commit: Commit, info, path: str = None, filters=None):
241+
def resolve_path_contents(
242+
commit: Commit,
243+
info,
244+
path: str = None,
245+
filters=None,
246+
first: int = None,
247+
after: str = None,
248+
last: int = None,
249+
before: str = None,
250+
):
242251
"""
243252
The file directory tree is a list of all the files and directories
244253
extracted from the commit report of the latest, head commit.
@@ -314,7 +323,50 @@ def resolve_path_contents(commit: Commit, info, path: str = None, filters=None):
314323
items = report_paths.full_filelist()
315324
else:
316325
items = report_paths.single_directory()
317-
return {"results": sort_path_contents(items, filters)}
326+
327+
# Fake pagination logic
328+
sorted_items = sort_path_contents(items, filters)
329+
total_items = len(sorted_items)
330+
331+
# Pagination calculation (first, after, last, before)
332+
start = 0
333+
end = total_items
334+
335+
# If `after` is provided, adjust start index
336+
if after:
337+
start = (
338+
next((i for i, item in enumerate(sorted_items) if item["path"] == after), 0)
339+
+ 1
340+
)
341+
342+
# If `before` is provided, adjust end index
343+
if before:
344+
end = next(
345+
(i for i, item in enumerate(sorted_items) if item["path"] == before),
346+
total_items,
347+
)
348+
349+
# Apply `first` or `last` limits
350+
if first:
351+
end = min(start + first, end)
352+
elif last:
353+
start = max(end - last, start)
354+
355+
paginated_items = sorted_items[start:end]
356+
357+
# Prepare pagination info
358+
has_next_page = end < total_items
359+
has_previous_page = start > 0
360+
361+
return {
362+
"results": paginated_items,
363+
"pageInfo": {
364+
"hasNextPage": has_next_page,
365+
"hasPreviousPage": has_previous_page,
366+
"startCursor": paginated_items[0]["path"] if paginated_items else None,
367+
"endCursor": paginated_items[-1]["path"] if paginated_items else None,
368+
},
369+
}
318370

319371

320372
@commit_bindable.field("errors")

graphql_api/types/path_contents/path_content.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ type PathContentDir implements PathContent {
2929
percentCovered: Float!
3030
}
3131

32+
type PathContentsPageInfo {
33+
hasNextPage: Boolean!
34+
hasPreviousPage: Boolean!
35+
startCursor: String
36+
endCursor: String
37+
}
38+
3239
type PathContents {
3340
results: [PathContent!]!
41+
pageInfo: PathContentsPageInfo!
3442
}
3543

3644
union PathContentsResult =

0 commit comments

Comments
 (0)