Repository: graphql-rust/juniper (language: rust)

Issue:
How to use elements defined with `graphql_scalar!`?
The Juniper book has a lovely example of a scalar, named `UserID`, but does not show how to use it. I copied and pasted the `UserID` example, renamed it to `Digest`, and tried to use it in an object definition. It did not work out as hoped:

```
error[E0277]: the trait bound `schema::Digest: juniper::types::base::GraphQLType<__S>` is not satisfied
  --> src/schema.rs:53:10
   |
53 | #[derive(GraphQLObject)]
   |          ^^^^^^^^^^^^^ the trait `juniper::types::base::GraphQLType<__S>` is not implemented for `schema::Digest`
   |
   = help: consider adding a `where schema::Digest: juniper::types::base::GraphQLType<__S>` bound
   = note: required because of the requirements on the impl of `juniper::types::base::GraphQLType<__S>` for `std::option::Option<schema::Digest>`
   = note: required because of the requirements on the impl of `juniper::executor::IntoResolvable<'_, __S, std::option::Option<schema::Digest>, ()>` for `std::option::Option<schema::Digest>`
```

I can't find any examples to help me know where I'm going wrong. Any guidance would be appreciated, thanks.

Speaking of examples, it seems that `Value::string()` and its friend `as_string_value()` have been deprecated, but I can't for the life of me figure out how to use the suggested alternatives, so updated examples would be super.

Admittedly, I am not a Rust expert, so these could just be "you're an idiot" issues. My apologies. Keep up the great work, I hope eventually I can make use of it.


Discussion / hints:
This is due to scalar generics. The object macros by default use a generic scalar, but the `graphql_scalar!` macro uses the `juniper::DefaultScalarValue`, so they are not compatible.

You can fix this by using `juniper::graphql_scalar!(UserID where Scalar = <S> { ... }` instead.t

```rust
use juniper::Value;

struct UserID(String);

juniper::graphql_scalar!(UserID where Scalar = <S> {
    description: "An opaque identifier, represented as a string"

    resolve(&self) -> Value {
        Value::scalar(self.0.clone())
    }

    from_input_value(v: &InputValue) -> Option<UserID> {
        // If there's a parse error here, simply return None. Juniper will
        // present an error to the client.
        v.as_scalar_value::<String>().map(|s| UserID(s.to_owned()))
    }

    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,
}
```

Alternatively, you could also scope your object to `DefaultScalarValue` by using `#[derive(juniper::GraphQLObject(Scalar = juniper::DefaultScalarValue)]`.

This is of course a docs issue, but considering the issues with generics, I'm not sure if we should make the derive use DefaultScalarValue by default rather than being generic...

Fix patch:
diff --git a/docs/book/content/types/scalars.md b/docs/book/content/types/scalars.md
index e4f116a52..35d07bf7c 100644
--- a/docs/book/content/types/scalars.md
+++ b/docs/book/content/types/scalars.md
@@ -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() {}
 ```
 


Test patch: