diff --git a/master/print.html b/master/print.html index 4b96eab0..8c0e5f52 100644 --- a/master/print.html +++ b/master/print.html @@ -1452,7 +1452,7 @@ trait Character { # fn main() {}

Custom context

-

If a context is required in a trait method to resolve a GraphQL interface field, specify it as an argument.

+

If a Context is required in a trait method to resolve a GraphQL interface field, specify it as an argument.

# extern crate juniper;
 # use std::collections::HashMap;
 use juniper::{graphql_interface, GraphQLObject};
@@ -1500,19 +1500,18 @@ impl Character for Human {
 # fn main() {}
 

Using executor and explicit generic scalar

-

If an executor is required in a trait method to resolve a GraphQL interface field, specify it as an argument.

+

If an Executor is required in a trait method to resolve a GraphQL interface field, specify it as an argument.

This requires to explicitly parametrize over ScalarValue, as Executor does so.

# extern crate juniper;
 use juniper::{graphql_interface, Executor, GraphQLObject, LookAheadMethods as _, ScalarValue};
 
-#[graphql_interface(for = Human, Scalar = S)] // notice specifying scalar as existing type parameter
+#[graphql_interface(for = Human, Scalar = S)] // notice specifying `ScalarValue` as existing type parameter
 trait Character<S: ScalarValue> {             
     // If a field argument is named `executor`, it's automatically assumed
     // as an executor argument.
     async fn id<'a>(&self, executor: &'a Executor<'_, '_, (), S>) -> &'a str
     where
         S: Send + Sync; // required by `#[async_trait]` transformation ¯\_(ツ)_/¯
-    
 
     // Otherwise, you may mark it explicitly as an executor argument.
     async fn name<'b>(
@@ -1549,7 +1548,7 @@ impl<S: ScalarValue> Character<S> for Human {
 # fn main() {}
 

Downcasting

-

By default, the GraphQL interface value is downcast to one of its implementer types via matching the enum variant or downcasting the trait object (if dyn is used).

+

By default, the GraphQL interface value is downcast to one of its implementer types via matching the enum variant or downcasting the trait object (if dyn macro argument is used).

However, if some custom logic is needed to downcast a GraphQL interface implementer, you may specify either an external function or a trait method to do so.

# extern crate juniper;
 # use std::collections::HashMap;
@@ -1608,6 +1607,7 @@ fn get_droid<'db>(ch: &CharacterValue, db: &'db Database) -> Op
 #
 # fn main() {}
 
+

The attribute syntax #[graphql_interface(on ImplementerType = resolver_fn)] follows the GraphQL syntax for downcasting interface implementer.

ScalarValue considerations

By default, #[graphql_interface] macro generates code, which is generic over a ScalarValue type. This may introduce a problem when at least one of GraphQL interface implementers is restricted to a concrete ScalarValue type in its implementation. To resolve such problem, a concrete ScalarValue type should be specified.

# extern crate juniper;
@@ -1620,7 +1620,7 @@ trait Character {
 }
 
 #[derive(GraphQLObject)]
-#[graphql(Scalar = DefaultScalarValue)]
+#[graphql(impl = CharacterValue, Scalar = DefaultScalarValue)]
 struct Human {
     id: String,
     home_planet: String,
@@ -1633,6 +1633,7 @@ impl Character for Human {
 }
 
 #[derive(GraphQLObject)]
+#[graphql(impl = CharacterValue, Scalar = DefaultScalarValue)]
 struct Droid {
     id: String,
     primary_function: String,
@@ -1822,8 +1823,8 @@ where
 # fn main() {}
 

Unions

-

From the server's point of view, GraphQL unions are similar to interfaces - the only exception is that they don't contain fields on their own.

-

For implementing GraphQL unions Juniper provides:

+

From the server's point of view, GraphQL unions are somewhat similar to interfaces - the main difference is that they don't contain fields on their own.

+

The most obvious and straightforward way to represent a GraphQL union in Rust is enum. However, we also can do so either with trait or a regular struct. That's why, for implementing GraphQL unions Juniper provides: