(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:
parent
43fcc63c23
commit
74522b015e
1 changed files with 9 additions and 3 deletions
|
@ -17,7 +17,7 @@ use juniper::Value;
|
||||||
|
|
||||||
struct UserID(String);
|
struct UserID(String);
|
||||||
|
|
||||||
juniper::graphql_scalar!(UserID {
|
juniper::graphql_scalar!(UserID where Scalar = <S> {
|
||||||
description: "An opaque identifier, represented as a string"
|
description: "An opaque identifier, represented as a string"
|
||||||
|
|
||||||
resolve(&self) -> Value {
|
resolve(&self) -> Value {
|
||||||
|
@ -30,11 +30,17 @@ juniper::graphql_scalar!(UserID {
|
||||||
v.as_scalar_value::<String>().map(|s| UserID(s.to_owned()))
|
v.as_scalar_value::<String>().map(|s| UserID(s.to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, juniper::DefaultScalarValue> {
|
from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, S> {
|
||||||
<String as juniper::ParseScalarValue>::from_str(value)
|
<String as juniper::ParseScalarValue<S>>::from_str(value)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[derive(juniper::GraphQLObject)]
|
||||||
|
struct User {
|
||||||
|
id: UserID,
|
||||||
|
username: String,
|
||||||
|
}
|
||||||
|
|
||||||
# fn main() {}
|
# fn main() {}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue