use std::{borrow::Cow, marker::PhantomData};
use crate::{
connection::{DefaultEdgeName, EmptyFields},
types::connection::{CursorType, EdgeNameType},
ComplexObject, ObjectType, OutputType, SimpleObject, TypeName,
};
#[derive(SimpleObject)]
#[graphql(internal, name_type, shareable, complex)]
pub struct Edge<Cursor, Node, EdgeFields, Name = DefaultEdgeName>
where
Cursor: CursorType + Send + Sync,
Node: OutputType,
EdgeFields: ObjectType,
Name: EdgeNameType,
{
#[graphql(skip)]
_mark: PhantomData<Name>,
#[graphql(skip)]
pub cursor: Cursor,
pub node: Node,
#[graphql(flatten)]
pub(crate) additional_fields: EdgeFields,
}
#[ComplexObject(internal)]
impl<Cursor, Node, EdgeFields, Name> Edge<Cursor, Node, EdgeFields, Name>
where
Cursor: CursorType + Send + Sync,
Node: OutputType,
EdgeFields: ObjectType,
Name: EdgeNameType,
{
async fn cursor(&self) -> String {
self.cursor.encode_cursor()
}
}
impl<Cursor, Node, EdgeFields, Name> TypeName for Edge<Cursor, Node, EdgeFields, Name>
where
Cursor: CursorType + Send + Sync,
Node: OutputType,
EdgeFields: ObjectType,
Name: EdgeNameType,
{
#[inline]
fn type_name() -> Cow<'static, str> {
Name::type_name::<Node>().into()
}
}
impl<Cursor, Node, EdgeFields, Name> Edge<Cursor, Node, EdgeFields, Name>
where
Name: EdgeNameType,
Cursor: CursorType + Send + Sync,
Node: OutputType,
EdgeFields: ObjectType,
{
#[inline]
pub fn with_additional_fields(
cursor: Cursor,
node: Node,
additional_fields: EdgeFields,
) -> Self {
Self {
_mark: PhantomData,
cursor,
node,
additional_fields,
}
}
}
impl<Cursor, Node, Name> Edge<Cursor, Node, EmptyFields, Name>
where
Cursor: CursorType + Send + Sync,
Node: OutputType,
Name: EdgeNameType,
{
#[inline]
pub fn new(cursor: Cursor, node: Node) -> Self {
Self {
_mark: PhantomData,
cursor,
node,
additional_fields: EmptyFields,
}
}
}