Make PageInfo available from outside (#52)

This commit is contained in:
sunli 2020-05-06 06:52:04 +08:00
parent 35531b65f8
commit 64aee618fc
5 changed files with 20 additions and 26 deletions

View File

@ -125,7 +125,7 @@ pub use subscription::{
WebSocketTransport,
};
pub use types::{
Connection, Cursor, DataSource, EmptyEdgeFields, EmptyMutation, EmptySubscription,
Connection, Cursor, DataSource, EmptyEdgeFields, EmptyMutation, EmptySubscription, PageInfo,
QueryOperation, Upload,
};
pub use validation::ValidationMode;

View File

@ -17,9 +17,14 @@ use std::collections::HashMap;
/// otherwise you can use the `Connection::map` function to convert to a type that implements `OutputValueType`.
/// `E` is an extension object type that extends the edge fields.
pub struct Connection<T, E: ObjectType + Sync + Send = EmptyEdgeFields> {
total_count: Option<usize>,
page_info: PageInfo,
nodes: Vec<(Cursor, E, T)>,
/// The total number of records.
pub total_count: Option<usize>,
/// Information about pagination in a connection.
pub page_info: PageInfo,
/// All records of the current page.
pub nodes: Vec<(Cursor, E, T)>,
}
impl<T, E: ObjectType + Sync + Send> Connection<T, E> {

View File

@ -8,6 +8,7 @@ use crate::{Context, FieldResult, ObjectType};
pub use connection_type::Connection;
pub use cursor::Cursor;
pub use page_info::PageInfo;
/// Connection query operation
pub enum QueryOperation {

View File

@ -1,32 +1,20 @@
#![allow(missing_docs)]
use crate::types::connection::cursor::Cursor;
use async_graphql_derive::Object;
use async_graphql_derive::SimpleObject;
/// Information about pagination in a connection
#[SimpleObject(internal, desc = "Information about pagination in a connection.")]
pub struct PageInfo {
pub has_previous_page: bool,
pub has_next_page: bool,
pub start_cursor: Option<Cursor>,
pub end_cursor: Option<Cursor>,
}
#[Object(internal)]
impl PageInfo {
#[field(desc = "When paginating backwards, are there more items?")]
async fn has_previous_page(&self) -> bool {
self.has_previous_page
}
pub has_previous_page: bool,
#[field(desc = "When paginating forwards, are there more items?")]
async fn has_next_page(&self) -> bool {
self.has_next_page
}
pub has_next_page: bool,
#[field(desc = "When paginating backwards, the cursor to continue.")]
async fn start_cursor(&self) -> &Option<Cursor> {
&self.start_cursor
}
pub start_cursor: Option<Cursor>,
#[field(desc = "When paginating forwards, the cursor to continue.")]
async fn end_cursor(&self) -> &Option<Cursor> {
&self.end_cursor
}
pub end_cursor: Option<Cursor>,
}

View File

@ -7,7 +7,7 @@ mod optional;
mod query_root;
mod upload;
pub use connection::{Connection, Cursor, DataSource, EmptyEdgeFields, QueryOperation};
pub use connection::{Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation};
pub use empty_mutation::EmptyMutation;
pub use empty_subscription::EmptySubscription;
pub use query_root::QueryRoot;