use super::*;
#[derive(Debug, Clone, PartialEq)]
pub struct SetFilter<T, VF = <<T as DefaultMarker>::Marker as ToGraphqlFilter>::Filter> {
pub(crate) eq: Option<Box<[T]>>,
pub(crate) ne: Option<Box<[T]>>,
pub(crate) encloses: Option<Box<[T]>>,
pub(crate) enclosed_by: Option<Box<[T]>>,
pub(crate) overlaps: Option<Box<[T]>>,
pub(crate) has_element: Option<T>,
pub(crate) any: Option<VF>,
pub(crate) count: Option<ScalarFilter<usize>>,
}
impl<T, VF> SetFilter<T, VF> {
#[inline]
pub const fn new() -> Self {
Self {
eq: None,
ne: None,
encloses: None,
enclosed_by: None,
overlaps: None,
has_element: None,
any: None,
count: None,
}
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.eq.is_none()
&& self.ne.is_none()
&& self.encloses.is_none()
&& self.enclosed_by.is_none()
&& self.overlaps.is_none()
&& self.has_element.is_none()
&& self.any.is_none()
&& match &self.count {
Some(count) => count.is_empty(),
None => true,
}
}
opt_accessor!(eq: [T] => with_eq, set_eq, maybe_eq, update_eq);
opt_accessor!(ne: [T] => with_ne, set_ne, maybe_ne, update_ne);
opt_accessor!(encloses: [T] => with_encloses, set_encloses, maybe_encloses, update_encloses);
opt_accessor!(
enclosed_by: [T] => with_enclosed_by, set_enclosed_by, maybe_enclosed_by, update_enclosed_by
);
opt_accessor!(overlaps: [T] => with_overlaps, set_overlaps, maybe_overlaps, update_overlaps);
opt_accessor!(
has_element: T => with_has_element, set_has_element, maybe_has_element, update_has_element
);
opt_accessor!(any: VF => with_any, set_any, maybe_any, update_any);
opt_accessor!(
count: ScalarFilter<usize> => with_count, set_count, maybe_count, update_count
);
pub fn try_map<U, E, F>(self, mut f: F) -> Result<SetFilter<U, VF>, E>
where
F: FnMut(T) -> Result<U, E>,
{
Ok(SetFilter {
eq: map_operands(self.eq, &mut f)?,
ne: map_operands(self.ne, &mut f)?,
encloses: map_operands(self.encloses, &mut f)?,
enclosed_by: map_operands(self.enclosed_by, &mut f)?,
overlaps: map_operands(self.overlaps, &mut f)?,
has_element: map_operand(self.has_element, &mut f)?,
any: self.any,
count: self.count,
})
}
}
impl<T, VF> Default for SetFilter<T, VF> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<T, VF> GraphqlFilter for SetFilter<T, VF> {
#[inline]
fn is_empty(&self) -> bool {
Self::is_empty(self)
}
}
#[cfg(feature = "async-graphql")]
impl<T, VF> async_graphql::InputType for SetFilter<T, VF>
where
T: crate::ToGraphqlInput + Send + Sync,
<T as crate::ToGraphqlInput>::Input: async_graphql::InputType,
VF: async_graphql::InputType,
{
type RawValueType = Self;
fn type_name() -> ::std::borrow::Cow<'static, str> {
let element = VF::type_name();
::std::borrow::Cow::Owned(::std::format!("{}SetFilter", super::operand_of(&element)))
}
fn create_type_info(registry: &mut async_graphql::registry::Registry) -> ::std::string::String {
registry.create_input_type::<Self, _>(
async_graphql::registry::MetaTypeId::InputObject,
|registry| async_graphql::registry::MetaType::InputObject {
name: ::std::borrow::Cow::into_owned(Self::type_name()),
description: ::std::option::Option::None,
input_fields: <Self as crate::NullableFace>::bare_fields(registry),
visible: ::std::option::Option::None,
inaccessible: false,
tags: ::std::vec::Vec::new(),
rust_typename: ::std::option::Option::Some(::std::any::type_name::<Self>()),
oneof: false,
directive_invocations: ::std::vec::Vec::new(),
},
)
}
fn parse(
value: ::std::option::Option<async_graphql::Value>,
) -> async_graphql::InputValueResult<Self> {
if let ::std::option::Option::Some(async_graphql::Value::Object(object)) = value {
::std::result::Result::Ok(Self {
eq: super::via::cross_list::<T, Self>(&object, "eq")?,
ne: super::via::cross_list::<T, Self>(&object, "ne")?,
encloses: super::via::cross_list::<T, Self>(&object, "encloses")?,
enclosed_by: super::via::cross_list::<T, Self>(&object, "enclosedBy")?,
overlaps: super::via::cross_list::<T, Self>(&object, "overlaps")?,
has_element: super::via::cross::<T, Self>(&object, "hasElement")?,
any: super::parse_slot::<_, Self>(&object, "any")?,
count: super::parse_slot::<_, Self>(&object, "count")?,
})
} else {
::std::result::Result::Err(async_graphql::InputValueError::expected_type(
value.unwrap_or_default(),
))
}
}
fn to_value(&self) -> async_graphql::Value {
async_graphql::Value::Object(<Self as crate::NullableFace>::bare_values(self))
}
#[inline]
fn as_raw_value(&self) -> ::std::option::Option<&Self::RawValueType> {
::std::option::Option::Some(self)
}
}
#[cfg(feature = "async-graphql")]
impl<T, VF> async_graphql::InputObjectType for SetFilter<T, VF>
where
T: crate::ToGraphqlInput + Send + Sync,
<T as crate::ToGraphqlInput>::Input: async_graphql::InputType,
VF: async_graphql::InputType,
{
}
#[cfg(feature = "async-graphql")]
fn set_values<T, VF>(
filter: &SetFilter<T, VF>,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value>
where
T: crate::ToGraphqlInput,
<T as crate::ToGraphqlInput>::Input: async_graphql::InputType,
VF: async_graphql::InputType,
{
let mut map = async_graphql::indexmap::IndexMap::new();
map.insert(
async_graphql::Name::new("eq"),
super::via::carry_list(&filter.eq),
);
map.insert(
async_graphql::Name::new("ne"),
super::via::carry_list(&filter.ne),
);
map.insert(
async_graphql::Name::new("encloses"),
super::via::carry_list(&filter.encloses),
);
map.insert(
async_graphql::Name::new("enclosedBy"),
super::via::carry_list(&filter.enclosed_by),
);
map.insert(
async_graphql::Name::new("overlaps"),
super::via::carry_list(&filter.overlaps),
);
map.insert(
async_graphql::Name::new("hasElement"),
super::via::carry(&filter.has_element),
);
map.insert(
async_graphql::Name::new("any"),
async_graphql::InputType::to_value(&filter.any),
);
map.insert(
async_graphql::Name::new("count"),
async_graphql::InputType::to_value(&filter.count),
);
map
}
#[cfg(feature = "async-graphql")]
impl<T, VF> crate::NullableFace for SetFilter<T, VF>
where
T: crate::ToGraphqlInput + Send + Sync,
<T as crate::ToGraphqlInput>::Input: async_graphql::InputType,
VF: async_graphql::InputType,
{
fn bare_fields(
registry: &mut async_graphql::registry::Registry,
) -> async_graphql::indexmap::IndexMap<
::std::string::String,
async_graphql::registry::MetaInputValue,
> {
__ingraph_filter_input_fields!(
registry,
"eq" : ::core::option::Option<::std::boxed::Box<[<T as crate::ToGraphqlInput>::Input]>>,
"ne" : ::core::option::Option<::std::boxed::Box<[<T as crate::ToGraphqlInput>::Input]>>,
"encloses" : ::core::option::Option<::std::boxed::Box<[<T as crate::ToGraphqlInput>::Input]>>,
"enclosedBy" : ::core::option::Option<::std::boxed::Box<[<T as crate::ToGraphqlInput>::Input]>>,
"overlaps" : ::core::option::Option<::std::boxed::Box<[<T as crate::ToGraphqlInput>::Input]>>,
"hasElement" : ::core::option::Option<<T as crate::ToGraphqlInput>::Input>,
"any" : ::core::option::Option<VF>,
"count" : ::core::option::Option<ScalarFilter<usize>>,
)
}
fn bare_values(
&self,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value> {
set_values(self)
}
}