You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GraphQLObject field attribute like serde's serialize_with #780
When creating graphql objects using the GraphQLObject custom derive which have types that do not implement GraphQLType you end up being forced to use the #[juniper::object] proc macro and redefine methods to expose each and every field manually. It would be useful to have a #[graphql(transform = "fn_name")] field attribute that would allow users to transform the type into another ie. u64 (snowflake) to string.
example:
/// User id struct from library, so it is impossible to derive GraphQLTypepubstructUserId(pubu64);#[derive(GraphQLObject)]structGraphQLObj{normal_string:String,#[graphql(transform = "ToString::to_string")]custom_type:UserId}
This improvement would probably be a better solution to #553.
could be a possible duplicate of #652
@DusterTheFirst we need a concrete Rust type to be named for building up a GraphQL schema by introspecting the Rust code given to macros.
Unfortunately, having UserId type and ToString::to_string ident of the function, it's impossible to name the transformation result type of applying this function to UserId in the current stable Rust. If we had sort of real typeof in Rust, it would be possible. But we have no ability to name a type out of an ident.
However, if we force users to name the result type, it will work:
Activity
DusterTheFirst commentedon Oct 8, 2020
Another solution could be to enable a way to make a type that implements
Displayto be usable as a GraphQLTypetyranron commentedon Jun 1, 2022
@DusterTheFirst we need a concrete Rust type to be named for building up a GraphQL schema by introspecting the Rust code given to macros.
Unfortunately, having
UserIdtype andToString::to_stringident of the function, it's impossible to name the transformation result type of applying this function toUserIdin the current stable Rust. If we had sort of realtypeofin Rust, it would be possible. But we have no ability to name a type out of an ident.However, if we force users to name the result type, it will work: