Update connection type

This commit is contained in:
Sunli 2022-05-02 16:20:45 +08:00
parent 028d674c29
commit 21916e1281
4 changed files with 37 additions and 34 deletions

@ -1 +1 @@
Subproject commit 22bc2e58689a2d5d76fbea687f008d134d45e660 Subproject commit d359d0ea3116326daf753f08233219530b8ec10b

View File

@ -1,7 +1,10 @@
use std::{borrow::Cow, marker::PhantomData}; use std::{borrow::Cow, marker::PhantomData};
use crate::{ use crate::{
connection::{edge::Edge, ConnectionNameType, EdgeNameType, PageInfo}, connection::{
edge::Edge, ConnectionNameType, DefaultConnectionName, DefaultEdgeName, EdgeNameType,
PageInfo,
},
types::connection::{CursorType, EmptyFields}, types::connection::{CursorType, EmptyFields},
Object, ObjectType, OutputType, TypeName, Object, ObjectType, OutputType, TypeName,
}; };
@ -10,24 +13,24 @@ use crate::{
/// ///
/// Connection is the result of a query for `connection::query`. /// Connection is the result of a query for `connection::query`.
pub struct Connection< pub struct Connection<
Name,
EdgeName,
Cursor, Cursor,
Node, Node,
ConnectionFields = EmptyFields, ConnectionFields = EmptyFields,
EdgeFields = EmptyFields, EdgeFields = EmptyFields,
Name = DefaultConnectionName,
EdgeName = DefaultEdgeName,
> where > where
Name: ConnectionNameType,
EdgeName: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
ConnectionFields: ObjectType, ConnectionFields: ObjectType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: ConnectionNameType,
EdgeName: EdgeNameType,
{ {
_mark1: PhantomData<Name>, _mark1: PhantomData<Name>,
_mark2: PhantomData<EdgeName>, _mark2: PhantomData<EdgeName>,
/// All edges of the current page. /// All edges of the current page.
pub edges: Vec<Edge<EdgeName, Cursor, Node, EdgeFields>>, pub edges: Vec<Edge<Cursor, Node, EdgeFields, EdgeName>>,
/// Additional fields for connection object. /// Additional fields for connection object.
pub additional_fields: ConnectionFields, pub additional_fields: ConnectionFields,
/// If `true` means has previous page. /// If `true` means has previous page.
@ -36,14 +39,14 @@ pub struct Connection<
pub has_next_page: bool, pub has_next_page: bool,
} }
impl<Name, EdgeName, Cursor, Node, EdgeFields> impl<Cursor, Node, EdgeFields, Name, EdgeName>
Connection<Name, EdgeName, Cursor, Node, EmptyFields, EdgeFields> Connection<Cursor, Node, EmptyFields, EdgeFields, Name, EdgeName>
where where
Name: ConnectionNameType,
EdgeName: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: ConnectionNameType,
EdgeName: EdgeNameType,
{ {
/// Create a new connection. /// Create a new connection.
#[inline] #[inline]
@ -59,15 +62,15 @@ where
} }
} }
impl<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields> impl<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>
Connection<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields> Connection<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>
where where
Name: ConnectionNameType,
EdgeName: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
ConnectionFields: ObjectType, ConnectionFields: ObjectType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: ConnectionNameType,
EdgeName: EdgeNameType,
{ {
/// Create a new connection, it can have some additional fields. /// Create a new connection, it can have some additional fields.
#[inline] #[inline]
@ -88,15 +91,15 @@ where
} }
#[Object(internal, name_type)] #[Object(internal, name_type)]
impl<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields> impl<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>
Connection<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields> Connection<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>
where where
Name: ConnectionNameType,
EdgeName: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
ConnectionFields: ObjectType, ConnectionFields: ObjectType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: ConnectionNameType,
EdgeName: EdgeNameType,
{ {
/// Information to aid in pagination. /// Information to aid in pagination.
async fn page_info(&self) -> PageInfo { async fn page_info(&self) -> PageInfo {
@ -110,7 +113,7 @@ where
/// A list of edges. /// A list of edges.
#[inline] #[inline]
async fn edges(&self) -> &[Edge<EdgeName, Cursor, Node, EdgeFields>] { async fn edges(&self) -> &[Edge<Cursor, Node, EdgeFields, EdgeName>] {
&self.edges &self.edges
} }
@ -121,15 +124,15 @@ where
} }
} }
impl<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields> TypeName impl<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName> TypeName
for Connection<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields> for Connection<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>
where where
Name: ConnectionNameType,
EdgeName: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
ConnectionFields: ObjectType, ConnectionFields: ObjectType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: ConnectionNameType,
EdgeName: EdgeNameType,
{ {
#[inline] #[inline]
fn type_name() -> Cow<'static, str> { fn type_name() -> Cow<'static, str> {

View File

@ -1,7 +1,7 @@
use std::{borrow::Cow, marker::PhantomData}; use std::{borrow::Cow, marker::PhantomData};
use crate::{ use crate::{
connection::EmptyFields, connection::{DefaultEdgeName, EmptyFields},
types::connection::{CursorType, EdgeNameType}, types::connection::{CursorType, EdgeNameType},
InputValueError, InputValueResult, ObjectType, OutputType, Scalar, ScalarType, SimpleObject, InputValueError, InputValueResult, ObjectType, OutputType, Scalar, ScalarType, SimpleObject,
TypeName, Value, TypeName, Value,
@ -32,12 +32,12 @@ impl<T: CursorType + Send + Sync> ScalarType for CursorScalar<T> {
/// An edge in a connection. /// An edge in a connection.
#[derive(SimpleObject)] #[derive(SimpleObject)]
#[graphql(internal, name_type)] #[graphql(internal, name_type)]
pub struct Edge<Name, Cursor, Node, EdgeFields> pub struct Edge<Cursor, Node, EdgeFields, Name = DefaultEdgeName>
where where
Name: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: EdgeNameType,
{ {
#[graphql(skip)] #[graphql(skip)]
_mark: PhantomData<Name>, _mark: PhantomData<Name>,
@ -49,12 +49,12 @@ where
pub(crate) additional_fields: EdgeFields, pub(crate) additional_fields: EdgeFields,
} }
impl<Name, Cursor, Node, EdgeFields> TypeName for Edge<Name, Cursor, Node, EdgeFields> impl<Cursor, Node, EdgeFields, Name> TypeName for Edge<Cursor, Node, EdgeFields, Name>
where where
Name: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
EdgeFields: ObjectType, EdgeFields: ObjectType,
Name: EdgeNameType,
{ {
#[inline] #[inline]
fn type_name() -> Cow<'static, str> { fn type_name() -> Cow<'static, str> {
@ -62,7 +62,7 @@ where
} }
} }
impl<Name, Cursor, Node, EdgeFields> Edge<Name, Cursor, Node, EdgeFields> impl<Cursor, Node, EdgeFields, Name> Edge<Cursor, Node, EdgeFields, Name>
where where
Name: EdgeNameType, Name: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
@ -85,11 +85,11 @@ where
} }
} }
impl<Name, Cursor, Node> Edge<Name, Cursor, Node, EmptyFields> impl<Cursor, Node, Name> Edge<Cursor, Node, EmptyFields, Name>
where where
Name: EdgeNameType,
Cursor: CursorType + Send + Sync, Cursor: CursorType + Send + Sync,
Node: OutputType, Node: OutputType,
Name: EdgeNameType,
{ {
/// Create a new edge. /// Create a new edge.
#[inline] #[inline]

View File

@ -194,7 +194,7 @@ pub async fn query<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields, F
first: Option<i32>, first: Option<i32>,
last: Option<i32>, last: Option<i32>,
f: F, f: F,
) -> Result<Connection<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields>> ) -> Result<Connection<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>>
where where
Name: ConnectionNameType, Name: ConnectionNameType,
EdgeName: EdgeNameType, EdgeName: EdgeNameType,
@ -205,7 +205,7 @@ where
EdgeFields: ObjectType, EdgeFields: ObjectType,
F: FnOnce(Option<Cursor>, Option<Cursor>, Option<usize>, Option<usize>) -> R, F: FnOnce(Option<Cursor>, Option<Cursor>, Option<usize>, Option<usize>) -> R,
R: Future< R: Future<
Output = Result<Connection<Name, EdgeName, Cursor, Node, ConnectionFields, EdgeFields>, E>, Output = Result<Connection<Cursor, Node, ConnectionFields, EdgeFields, Name, EdgeName>, E>,
>, >,
E: Into<Error>, E: Into<Error>,
{ {