1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
/// Arguments used for cursor-based pagination.
#[derive(Deserialize, Debug, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct PaginationArgs {
/// Returns the first `n` items from the list.
pub first: Option<i64>,
/// A cursor pointing to the position after which items should be returned.
pub after: Option<String>,
/// Returns the last `n` items from the list.
pub last: Option<i64>,
/// A cursor pointing to the position before which items should be returned.
pub before: Option<String>,
}
/// Metadata describing the current page of results.
#[derive(Serialize, Debug, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct PageInfo {
/// Indicates whether there are more items when paginating forward.
pub has_next_page: bool,
/// Indicates whether there are more items when paginating backward.
pub has_previous_page: bool,
/// The cursor corresponding to the first item in the current page.
pub start_cursor: Option<String>,
/// The cursor corresponding to the last item in the current page.
pub end_cursor: Option<String>,
}
/// A paginated connection containing edges and pagination metadata.
#[derive(Serialize, Debug, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Connection<T> {
/// A list of edges, each containing a node and its cursor.
pub edges: Vec<Edge<T>>,
/// Information about pagination for this connection.
pub page_info: PageInfo,
}
/// An edge in a connection, representing a node and its cursor.
#[derive(Serialize, Debug, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Edge<T> {
/// The item/node contained in this edge.
pub node: T,
/// A cursor for this node, used in pagination.
pub cursor: String,
}
|