Skip to content

Commit fc1eae8

Browse files
davidroecaCkk3
andauthored
Pagination args (#255)
* Add initial first/after implementation for pagination args * Add last/before * Add tests for before/last * Working initial implementation for async * Fix/update tests; working async * Patch for sync sqlalchemy not the long term fix * Minor bind refactor * Reformat * Reformat * Add release.md file * Reduce number of for loops in mapper; fix some logic errors * Refactor tests * Resolve remaining test errors * Add cases to check for invalid pagination args * Small fixes + more coverage * Remove unnecessary list comp * Fix misplaced setattr * Reformat * Address PR feedback from sourcery * Refactor based on sourcery feedback * remove unused parent_loader * run pre-commit --------- Co-authored-by: Ckk3 <[email protected]>
1 parent 1a2db70 commit fc1eae8

File tree

9 files changed

+1113
-78
lines changed

9 files changed

+1113
-78
lines changed

RELEASE.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Release type: minor
2+
3+
Implement Relay-style cursor pagination for SQLAlchemy relationships by extending the connection resolver and DataLoader to accept pagination arguments, computing pageInfo metadata, and introducing cursor utilities. Add PaginatedLoader to scope DataLoader instances per pagination parameters and update tests to verify pagination behavior.
4+
5+
**New Features**:
6+
- Support cursor-based pagination (first, after, last, before) on GraphQL relationship fields
7+
- Introduce PaginatedLoader to manage DataLoader instances per pagination configuration
8+
9+
**Enhancements**:
10+
- Extend connection resolvers to compute pageInfo fields (hasNextPage, hasPreviousPage, totalCount) and handle forward and backward pagination
11+
- Add utilities for cursor encoding/decoding and relationship key extraction
12+
13+
**Tests**:
14+
- Add comprehensive tests for forward and backward pagination scenarios in both synchronous and asynchronous execution contexts
15+
16+
**Examples**:
17+
18+
Get the first three books for a specific author:
19+
20+
```gql
21+
query {
22+
author(id: 1) {
23+
id
24+
name
25+
books(first: 3) {
26+
edges {
27+
node {
28+
id
29+
title
30+
}
31+
}
32+
pageInfo {
33+
hasNextPage
34+
hasPreviousPage
35+
startCursor
36+
endCursor
37+
}
38+
}
39+
}
40+
}
41+
```
42+
43+
Get all books after a specific book's cursor:
44+
45+
```gql
46+
query($afterBook: String) {
47+
author(id: 1) {
48+
id
49+
name
50+
books(after: $afterBook) {
51+
edges {
52+
node {
53+
id
54+
title
55+
}
56+
}
57+
pageInfo {
58+
hasNextPage
59+
hasPreviousPage
60+
startCursor
61+
endCursor
62+
}
63+
}
64+
}
65+
}
66+
```
67+
68+
Get the first three books for a specific author after a specific book's cursor:
69+
70+
```gql
71+
query($afterBook: String) {
72+
author(id: 1) {
73+
id
74+
name
75+
books(first: 3, after: $afterBook) {
76+
edges {
77+
node {
78+
id
79+
title
80+
}
81+
}
82+
pageInfo {
83+
hasNextPage
84+
hasPreviousPage
85+
startCursor
86+
endCursor
87+
}
88+
}
89+
}
90+
}
91+
```
92+
93+
94+
Get the last three books for a specific author:
95+
96+
```gql
97+
query {
98+
author(id: 1) {
99+
id
100+
name
101+
books(last: 3) {
102+
edges {
103+
node {
104+
id
105+
title
106+
}
107+
}
108+
pageInfo {
109+
hasNextPage
110+
hasPreviousPage
111+
startCursor
112+
endCursor
113+
}
114+
}
115+
}
116+
}
117+
```
118+
119+
Get all books before a specific book's cursor:
120+
121+
```gql
122+
query($beforeBook: String) {
123+
author(id: 1) {
124+
id
125+
name
126+
books(before: $beforeBook) {
127+
edges {
128+
node {
129+
id
130+
title
131+
}
132+
}
133+
pageInfo {
134+
hasNextPage
135+
hasPreviousPage
136+
startCursor
137+
endCursor
138+
}
139+
}
140+
}
141+
}
142+
```
143+
144+
Get the last three books for a specific author before a specific book's cursor:
145+
146+
```gql
147+
query($beforeBook: String) {
148+
author(id: 1) {
149+
id
150+
name
151+
books(last: 3, before: $beforeBook) {
152+
edges {
153+
node {
154+
id
155+
title
156+
}
157+
}
158+
pageInfo {
159+
hasNextPage
160+
hasPreviousPage
161+
startCursor
162+
endCursor
163+
}
164+
}
165+
}
166+
}
167+
```

0 commit comments

Comments
 (0)