Skip to content

GraphQLObject field attribute like serde's serialize_with #780

Description

@DusterTheFirst

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 GraphQLType
pub struct UserId(pub u64);

#[derive(GraphQLObject)] 
struct GraphQLObj {
    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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementImprovement of existing features or bugfix

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions