2020-05-05 05:21:45 +00:00
|
|
|
use crate::types::connection::cursor::Cursor;
|
2020-03-19 09:20:12 +00:00
|
|
|
use async_graphql_derive::Object;
|
|
|
|
|
|
|
|
pub struct PageInfo {
|
|
|
|
pub has_previous_page: bool,
|
|
|
|
pub has_next_page: bool,
|
2020-05-05 05:21:45 +00:00
|
|
|
pub start_cursor: Option<Cursor>,
|
|
|
|
pub end_cursor: Option<Cursor>,
|
2020-03-19 09:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Object(internal)]
|
|
|
|
impl PageInfo {
|
|
|
|
#[field(desc = "When paginating backwards, are there more items?")]
|
|
|
|
async fn has_previous_page(&self) -> bool {
|
|
|
|
self.has_previous_page
|
|
|
|
}
|
|
|
|
|
|
|
|
#[field(desc = "When paginating forwards, are there more items?")]
|
|
|
|
async fn has_next_page(&self) -> bool {
|
|
|
|
self.has_next_page
|
|
|
|
}
|
|
|
|
|
|
|
|
#[field(desc = "When paginating backwards, the cursor to continue.")]
|
2020-05-05 05:21:45 +00:00
|
|
|
async fn start_cursor(&self) -> &Option<Cursor> {
|
2020-03-19 09:20:12 +00:00
|
|
|
&self.start_cursor
|
|
|
|
}
|
|
|
|
|
|
|
|
#[field(desc = "When paginating forwards, the cursor to continue.")]
|
2020-05-05 05:21:45 +00:00
|
|
|
async fn end_cursor(&self) -> &Option<Cursor> {
|
2020-03-19 09:20:12 +00:00
|
|
|
&self.end_cursor
|
|
|
|
}
|
|
|
|
}
|