juniper icon indicating copy to clipboard operation
juniper copied to clipboard

Implement HashSet support the same way as Vec

Open rimutaka opened this issue 2 years ago • 0 comments

This PR implements support for converting HashSet<T> into GraphQL exactly the same way as Vec<T>. Only output-related traits were implemented:

  • IsOutputType
  • GraphQLType
  • BaseType
  • WrapType
  • GraphQLValueAsync

Use case

Consider this struct

#[derive(Debug, Serialize, Deserialize, Eq, Clone, GraphQLObject)]
#[graphql(scalar = RustScalarValue)]
pub struct KeywordCounter {
    pub full_list: Vec<String>,        // <---- a list, works fine as-is
    pub unique_list: HashSet<String>,  // <---- the same as full_list from GQL perspective, but fails because of no HashSet impl      
    pub c: u64,                        // <---- a custom scalar, works fine
}

rimutaka avatar May 31 '22 03:05 rimutaka