Add ToGraphQLCursor and ToGraphQLID traits. #54
This commit is contained in:
parent
6d7d64866b
commit
4a68ac3786
|
@ -122,7 +122,7 @@ pub use error::{
|
|||
pub use parser::{Pos, Positioned, Value};
|
||||
pub use query::{IntoQueryBuilder, IntoQueryBuilderOpts, QueryBuilder, QueryResponse};
|
||||
pub use registry::CacheControl;
|
||||
pub use scalars::{Any, Json, ID};
|
||||
pub use scalars::{Any, Json, ToGraphQLID, ID};
|
||||
pub use schema::Schema;
|
||||
pub use subscription::{
|
||||
SimpleBroker, SubscriptionStream, SubscriptionStreams, SubscriptionTransport,
|
||||
|
@ -130,7 +130,7 @@ pub use subscription::{
|
|||
};
|
||||
pub use types::{
|
||||
Connection, Cursor, DataSource, EmptyEdgeFields, EmptyMutation, EmptySubscription, PageInfo,
|
||||
QueryOperation, Upload,
|
||||
QueryOperation, ToGraphQLCursor, Upload,
|
||||
};
|
||||
pub use validation::ValidationMode;
|
||||
|
||||
|
|
|
@ -98,6 +98,21 @@ impl PartialEq<&str> for ID {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert any type that implements Display to the ID type
|
||||
pub trait ToGraphQLID {
|
||||
#[allow(missing_docs)]
|
||||
fn to_graphql_id(&self) -> ID;
|
||||
}
|
||||
|
||||
impl<T> ToGraphQLID for T
|
||||
where
|
||||
T: std::fmt::Display,
|
||||
{
|
||||
fn to_graphql_id(&self) -> ID {
|
||||
ID(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[Scalar(internal)]
|
||||
impl ScalarType for ID {
|
||||
fn type_name() -> &'static str {
|
||||
|
|
|
@ -15,7 +15,7 @@ mod bson;
|
|||
mod uuid;
|
||||
|
||||
pub use any::Any;
|
||||
pub use id::ID;
|
||||
pub use id::{ToGraphQLID, ID};
|
||||
pub use json::Json;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -47,6 +47,21 @@ impl From<usize> for Cursor {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
T: std::fmt::Display,
|
||||
{
|
||||
fn to_graphql_cursor(&self) -> Cursor {
|
||||
Cursor(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[Scalar(internal)]
|
||||
impl ScalarType for Cursor {
|
||||
fn type_name() -> &'static str {
|
||||
|
|
|
@ -7,7 +7,7 @@ mod slice;
|
|||
use crate::{Context, FieldResult, ObjectType};
|
||||
|
||||
pub use connection_type::Connection;
|
||||
pub use cursor::Cursor;
|
||||
pub use cursor::{Cursor, ToGraphQLCursor};
|
||||
pub use page_info::PageInfo;
|
||||
|
||||
/// Connection query operation
|
||||
|
|
|
@ -7,7 +7,9 @@ mod optional;
|
|||
mod query_root;
|
||||
mod upload;
|
||||
|
||||
pub use connection::{Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation};
|
||||
pub use connection::{
|
||||
Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation, ToGraphQLCursor,
|
||||
};
|
||||
pub use empty_mutation::EmptyMutation;
|
||||
pub use empty_subscription::EmptySubscription;
|
||||
pub use query_root::QueryRoot;
|
||||
|
|
Loading…
Reference in New Issue
Block a user