use std::{any::Any, marker::PhantomPinned};
use derive_more::with_trait::Debug;
use juniper::GraphQLError;
use serde::{Serialize, Serializer};
#[derive(Debug)]
#[debug("{error:?}")]
pub struct ErrorPayload {
_execution_params: Option<Box<dyn Any + Send>>,
error: GraphQLError,
_pinned: PhantomPinned,
}
impl ErrorPayload {
pub(crate) fn new(execution_params: Box<dyn Any + Send>, error: GraphQLError) -> Self {
Self {
_execution_params: Some(execution_params),
error,
_pinned: PhantomPinned,
}
}
pub fn graphql_error(&self) -> &GraphQLError {
&self.error
}
}
impl PartialEq for ErrorPayload {
fn eq(&self, other: &Self) -> bool {
self.error.eq(&other.error)
}
}
impl Serialize for ErrorPayload {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.error.serialize(serializer)
}
}
impl From<GraphQLError> for ErrorPayload {
fn from(error: GraphQLError) -> Self {
Self {
_execution_params: None,
error,
_pinned: PhantomPinned,
}
}
}