(book) Update the graphql_scalar! example to be generic

This is now basically a requirement due to GraphQLObject derive
being generic.
This commit is contained in:
Christoph Herzog 2019-05-17 19:10:00 +02:00 committed by theduke
parent 43fcc63c23
commit 74522b015e

View file

@ -17,7 +17,7 @@ use juniper::Value;
struct UserID(String);
juniper::graphql_scalar!(UserID {
juniper::graphql_scalar!(UserID where Scalar = <S> {
description: "An opaque identifier, represented as a string"
resolve(&self) -> Value {
@ -30,11 +30,17 @@ juniper::graphql_scalar!(UserID {
v.as_scalar_value::<String>().map(|s| UserID(s.to_owned()))
}
from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, juniper::DefaultScalarValue> {
<String as juniper::ParseScalarValue>::from_str(value)
from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, S> {
<String as juniper::ParseScalarValue<S>>::from_str(value)
}
});
#[derive(juniper::GraphQLObject)]
struct User {
id: UserID,
username: String,
}
# fn main() {}
```