@@ -16,20 +16,23 @@ See the documentation for [`graphql_object!`][1] on the general item and type
16
16
syntax. `graphql_interface!` requires an additional `instance_resolvers` item,
17
17
and does _not_ support the `interfaces` item.
18
18
19
- `instance_resolvers` is a list/lambda hybrid used to resolve the concrete
19
+ `instance_resolvers` is a match like structure used to resolve the concrete
20
20
instance type of the interface. It starts with a context argument and continues
21
- with an array of expressions, each resolving into an `Option<T>` of the possible
22
- instances :
21
+ with a number of match arms; on the left side is the indicated type, and on the
22
+ right an expression that resolve into `Option<T>` of the type indicated :
23
23
24
24
```rust,ignore
25
25
instance_resolvers: |&context| {
26
- Human => context.get_human(self.id()), // returns Option<Human>
27
- Droid => context.get_droid(self.id()), // returns Option<Droid>
26
+ & Human => context.get_human(self.id()), // returns Option<& Human>
27
+ & Droid => context.get_droid(self.id()), // returns Option<& Droid>
28
28
},
29
29
```
30
30
31
- Each item in the array will be executed in order when the concrete type is
32
- required.
31
+ This is used for both the `__typename` field and when resolving a specialized
32
+ fragment, e.g. `...on Human`. For `__typename`, the resolvers will be executed
33
+ in order - the first one returning `Some` will be the determined type name. When
34
+ resolving fragment type conditions, only the corresponding match arm will be
35
+ executed.
33
36
34
37
## Example
35
38
@@ -71,8 +74,8 @@ graphql_interface!(<'a> &'a Character: Database as "Character" |&self| {
71
74
field id() -> &str { self.id() }
72
75
73
76
instance_resolvers: |&context| {
74
- Human => context.humans.get(self.id()),
75
- Droid => context.droids.get(self.id()),
77
+ & Human => context.humans.get(self.id()),
78
+ & Droid => context.droids.get(self.id()),
76
79
}
77
80
});
78
81
0 commit comments