|
6 | 6 | from cursor_pagination import CursorPage, CursorPaginator |
7 | 7 | from django.db.models import QuerySet |
8 | 8 |
|
| 9 | +from codecov.commands.exceptions import ValidationError |
9 | 10 | from codecov.db import sync_to_async |
10 | 11 | from graphql_api.types.enums import OrderingDirection |
11 | 12 |
|
@@ -85,13 +86,19 @@ def __init__( |
85 | 86 | self.end_index = len(data) |
86 | 87 |
|
87 | 88 | if first and last: |
88 | | - raise ValueError("Cannot provide both 'first' and 'last'") |
| 89 | + raise ValidationError("Cannot provide both 'first' and 'last'") |
89 | 90 |
|
90 | 91 | if after is not None: |
91 | | - self.start_index = int(after) + 1 |
| 92 | + try: |
| 93 | + self.start_index = int(after) + 1 |
| 94 | + except ValueError: |
| 95 | + raise ValidationError("'after' cursor must be an integer") |
92 | 96 |
|
93 | 97 | if before is not None: |
94 | | - self.end_index = min(self.end_index, int(before)) |
| 98 | + try: |
| 99 | + self.end_index = min(self.end_index, int(before)) |
| 100 | + except ValueError: |
| 101 | + raise ValidationError("'before' cursor must be an integer") |
95 | 102 |
|
96 | 103 | # Ensure valid bounds after 'after' and 'before' |
97 | 104 | self.start_index = max(self.start_index, 0) |
@@ -132,10 +139,10 @@ def has_previous(self) -> bool: |
132 | 139 | class ArrayConnection: |
133 | 140 | """Connection wrapper for array pagination.""" |
134 | 141 |
|
135 | | - def __init__(self, data: List[Any], paginator: ArrayPaginator, page: List[Any]): |
136 | | - self.data = data |
| 142 | + def __init__(self, paginator: ArrayPaginator): |
| 143 | + self.data = paginator.data |
137 | 144 | self.paginator = paginator |
138 | | - self.page = page |
| 145 | + self.page = paginator.page |
139 | 146 |
|
140 | 147 | @property |
141 | 148 | def edges(self) -> List[Dict[str, Any]]: |
@@ -237,7 +244,7 @@ def queryset_to_connection_sync( |
237 | 244 | array_paginator = ArrayPaginator( |
238 | 245 | data, first=first, last=last, after=after, before=before |
239 | 246 | ) |
240 | | - return ArrayConnection(data, array_paginator, array_paginator.page) |
| 247 | + return ArrayConnection(array_paginator) |
241 | 248 |
|
242 | 249 | else: |
243 | 250 | ordering = tuple(field_order(field, ordering_direction) for field in ordering) |
|
0 commit comments