Simplify cursor conversion
This commit is contained in:
parent
08cf3c5969
commit
d3015e9814
|
@ -130,7 +130,7 @@ pub use subscription::{
|
||||||
};
|
};
|
||||||
pub use types::{
|
pub use types::{
|
||||||
Connection, Cursor, DataSource, EmptyEdgeFields, EmptyMutation, EmptySubscription, PageInfo,
|
Connection, Cursor, DataSource, EmptyEdgeFields, EmptyMutation, EmptySubscription, PageInfo,
|
||||||
QueryOperation, ToGraphQLCursor, Upload,
|
QueryOperation, Upload,
|
||||||
};
|
};
|
||||||
pub use validation::ValidationMode;
|
pub use validation::ValidationMode;
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,6 @@ use std::ops::{Deref, DerefMut};
|
||||||
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
|
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
|
||||||
pub struct Cursor(String);
|
pub struct Cursor(String);
|
||||||
|
|
||||||
impl std::fmt::Display for Cursor {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Cursor {
|
impl Deref for Cursor {
|
||||||
type Target = String;
|
type Target = String;
|
||||||
|
|
||||||
|
@ -29,36 +23,12 @@ impl DerefMut for Cursor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Cursor {
|
impl<T> From<T> for Cursor
|
||||||
fn from(value: String) -> Self {
|
|
||||||
Cursor(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a str> for Cursor {
|
|
||||||
fn from(value: &'a str) -> Self {
|
|
||||||
Cursor(value.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<usize> for Cursor {
|
|
||||||
fn from(value: usize) -> Self {
|
|
||||||
Cursor(value.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert any type that implements Display to the Cursor type
|
|
||||||
pub trait ToGraphQLCursor {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
fn to_graphql_cursor(&self) -> Cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> ToGraphQLCursor for T
|
|
||||||
where
|
where
|
||||||
T: std::fmt::Display,
|
T: std::fmt::Display
|
||||||
{
|
{
|
||||||
fn to_graphql_cursor(&self) -> Cursor {
|
fn from(value: T) -> Self {
|
||||||
Cursor(self.to_string())
|
Cursor(value.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ mod slice;
|
||||||
use crate::{Context, FieldResult, ObjectType};
|
use crate::{Context, FieldResult, ObjectType};
|
||||||
|
|
||||||
pub use connection_type::Connection;
|
pub use connection_type::Connection;
|
||||||
pub use cursor::{Cursor, ToGraphQLCursor};
|
pub use cursor::{Cursor};
|
||||||
pub use page_info::PageInfo;
|
pub use page_info::PageInfo;
|
||||||
|
|
||||||
/// Connection query operation
|
/// Connection query operation
|
||||||
|
|
|
@ -8,7 +8,7 @@ mod query_root;
|
||||||
mod upload;
|
mod upload;
|
||||||
|
|
||||||
pub use connection::{
|
pub use connection::{
|
||||||
Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation, ToGraphQLCursor,
|
Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation,
|
||||||
};
|
};
|
||||||
pub use empty_mutation::EmptyMutation;
|
pub use empty_mutation::EmptyMutation;
|
||||||
pub use empty_subscription::EmptySubscription;
|
pub use empty_subscription::EmptySubscription;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user