Derive Macro juniper::GraphQLScalarValue
source · #[derive(GraphQLScalarValue)]
{
// Attributes available to this derive:
#[graphql]
}
Expand description
This custom derive macro implements the #[derive(GraphQLScalarValue)] derive.
This can be used for two purposes.
Transparent Newtype Wrapper
Sometimes, you want to create a custerm scalar type by wrapping an existing type. In Rust, this is often called the “newtype” pattern. Thanks to this custom derive, this becomes really easy:
// Deriving GraphQLScalar is all that is required.
#[derive(juniper::GraphQLScalarValue)]
struct UserId(String);
#[derive(juniper::GraphQLObject)]
struct User {
id: UserId,
}
The type can also be customized.
/// Doc comments are used for the GraphQL type description.
#[derive(juniper::GraphQLScalarValue)]
#[graphql(
transparent,
// Set a custom GraphQL name.
name= "MyUserId",
// A description can also specified in the attribute.
// This will the doc comment, if one exists.
description = "...",
)]
struct UserId(String);
Base ScalarValue Enum
TODO: write documentation.