diff --git a/juniper/src/macros/reflect.rs b/juniper/src/macros/reflect.rs index 563b28dfe..4af166b72 100644 --- a/juniper/src/macros/reflect.rs +++ b/juniper/src/macros/reflect.rs @@ -1,6 +1,6 @@ //! Compile-time reflection of Rust types into GraphQL types. -use std::{rc::Rc, sync::Arc}; +use std::{collections::HashSet, rc::Rc, sync::Arc}; use futures::future::BoxFuture; @@ -72,6 +72,10 @@ impl> BaseType for Vec { const NAME: Type = T::NAME; } +impl> BaseType for HashSet { + const NAME: Type = T::NAME; +} + impl> BaseType for [T] { const NAME: Type = T::NAME; } @@ -133,6 +137,10 @@ impl> BaseSubTypes for Vec { const NAMES: Types = T::NAMES; } +impl> BaseSubTypes for HashSet { + const NAMES: Types = T::NAMES; +} + impl> BaseSubTypes for [T] { const NAMES: Types = T::NAMES; } @@ -229,6 +237,10 @@ impl> WrappedType for Vec { const VALUE: u128 = T::VALUE * 10 + 3; } +impl> WrappedType for HashSet { + const VALUE: u128 = T::VALUE * 10 + 3; +} + impl> WrappedType for [T] { const VALUE: u128 = T::VALUE * 10 + 3; } diff --git a/juniper/src/types/containers.rs b/juniper/src/types/containers.rs index 108f0e021..2c4000883 100644 --- a/juniper/src/types/containers.rs +++ b/juniper/src/types/containers.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashSet, mem::{self, MaybeUninit}, ptr, }; @@ -220,6 +221,63 @@ where } } +impl GraphQLType for HashSet +where + T: GraphQLType, + S: ScalarValue, +{ + fn name(_: &Self::TypeInfo) -> Option<&'static str> { + None + } + + fn meta<'r>(info: &Self::TypeInfo, registry: &mut Registry<'r, S>) -> MetaType<'r, S> + where + S: 'r, + { + registry.build_list_type::(info, None).into_meta() + } +} + +impl GraphQLValue for HashSet +where + T: GraphQLValue, + S: ScalarValue, +{ + type Context = T::Context; + type TypeInfo = T::TypeInfo; + + fn type_name(&self, _: &Self::TypeInfo) -> Option<&'static str> { + None + } + + fn resolve( + &self, + info: &Self::TypeInfo, + _: Option<&[Selection]>, + executor: &Executor, + ) -> ExecutionResult { + resolve_into_list(executor, info, self.iter()) + } +} + +impl GraphQLValueAsync for HashSet +where + T: GraphQLValueAsync, + T::TypeInfo: Sync, + T::Context: Sync, + S: ScalarValue + Send + Sync, +{ + fn resolve_async<'a>( + &'a self, + info: &'a Self::TypeInfo, + _: Option<&'a [Selection]>, + executor: &'a Executor, + ) -> crate::BoxFuture<'a, ExecutionResult> { + let f = resolve_into_list_async(executor, info, self.iter()); + Box::pin(f) + } +} + impl GraphQLType for [T] where S: ScalarValue, diff --git a/juniper/src/types/marker.rs b/juniper/src/types/marker.rs index c4cc18f55..dc9661476 100644 --- a/juniper/src/types/marker.rs +++ b/juniper/src/types/marker.rs @@ -249,6 +249,17 @@ where } } +impl IsOutputType for std::collections::HashSet +where + T: IsOutputType, + S: ScalarValue, +{ + #[inline] + fn mark() { + T::mark() + } +} + impl IsOutputType for [T] where T: IsOutputType,