Skip to content

Commit 74522b0

Browse files
theduketheduke
authored and
theduke
committed
(book) Update the graphql_scalar! example to be generic
This is now basically a requirement due to GraphQLObject derive being generic.
1 parent 43fcc63 commit 74522b0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/book/content/types/scalars.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use juniper::Value;
1717

1818
struct UserID(String);
1919

20-
juniper::graphql_scalar!(UserID {
20+
juniper::graphql_scalar!(UserID where Scalar = <S> {
2121
description: "An opaque identifier, represented as a string"
2222

2323
resolve(&self) -> Value {
@@ -30,11 +30,17 @@ juniper::graphql_scalar!(UserID {
3030
v.as_scalar_value::<String>().map(|s| UserID(s.to_owned()))
3131
}
3232

33-
from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, juniper::DefaultScalarValue> {
34-
<String as juniper::ParseScalarValue>::from_str(value)
33+
from_str<'a>(value: ScalarToken<'a>) -> juniper::ParseScalarResult<'a, S> {
34+
<String as juniper::ParseScalarValue<S>>::from_str(value)
3535
}
3636
});
3737

38+
#[derive(juniper::GraphQLObject)]
39+
struct User {
40+
id: UserID,
41+
username: String,
42+
}
43+
3844
# fn main() {}
3945
```
4046

0 commit comments

Comments
 (0)