Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion juniper/src/macros/reflect.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -72,6 +72,10 @@ impl<S, T: BaseType<S>> BaseType<S> for Vec<T> {
const NAME: Type = T::NAME;
}

impl<S, T: BaseType<S>> BaseType<S> for HashSet<T> {
const NAME: Type = T::NAME;
}

impl<S, T: BaseType<S>> BaseType<S> for [T] {
const NAME: Type = T::NAME;
}
Expand Down Expand Up @@ -133,6 +137,10 @@ impl<S, T: BaseSubTypes<S>> BaseSubTypes<S> for Vec<T> {
const NAMES: Types = T::NAMES;
}

impl<S, T: BaseSubTypes<S>> BaseSubTypes<S> for HashSet<T> {
const NAMES: Types = T::NAMES;
}

impl<S, T: BaseSubTypes<S>> BaseSubTypes<S> for [T] {
const NAMES: Types = T::NAMES;
}
Expand Down Expand Up @@ -229,6 +237,10 @@ impl<S, T: WrappedType<S>> WrappedType<S> for Vec<T> {
const VALUE: u128 = T::VALUE * 10 + 3;
}

impl<S, T: WrappedType<S>> WrappedType<S> for HashSet<T> {
const VALUE: u128 = T::VALUE * 10 + 3;
}

impl<S, T: WrappedType<S>> WrappedType<S> for [T] {
const VALUE: u128 = T::VALUE * 10 + 3;
}
Expand Down
58 changes: 58 additions & 0 deletions juniper/src/types/containers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::HashSet,
mem::{self, MaybeUninit},
ptr,
};
Expand Down Expand Up @@ -220,6 +221,63 @@ where
}
}

impl<S, T> GraphQLType<S> for HashSet<T>
where
T: GraphQLType<S>,
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::<T>(info, None).into_meta()
}
}

impl<S, T> GraphQLValue<S> for HashSet<T>
where
T: GraphQLValue<S>,
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<S>]>,
executor: &Executor<Self::Context, S>,
) -> ExecutionResult<S> {
resolve_into_list(executor, info, self.iter())
}
}

impl<S, T> GraphQLValueAsync<S> for HashSet<T>
where
T: GraphQLValueAsync<S>,
T::TypeInfo: Sync,
T::Context: Sync,
S: ScalarValue + Send + Sync,
{
fn resolve_async<'a>(
&'a self,
info: &'a Self::TypeInfo,
_: Option<&'a [Selection<S>]>,
executor: &'a Executor<Self::Context, S>,
) -> crate::BoxFuture<'a, ExecutionResult<S>> {
let f = resolve_into_list_async(executor, info, self.iter());
Box::pin(f)
}
}

impl<S, T> GraphQLType<S> for [T]
where
S: ScalarValue,
Expand Down
11 changes: 11 additions & 0 deletions juniper/src/types/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ where
}
}

impl<S, T> IsOutputType<S> for std::collections::HashSet<T>
where
T: IsOutputType<S>,
S: ScalarValue,
{
#[inline]
fn mark() {
T::mark()
}
}

impl<S, T> IsOutputType<S> for [T]
where
T: IsOutputType<S>,
Expand Down