You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// GraphQL spec, you can use them interchangeably.
111
+
// Same is applied for `Cow<'a, str>`.
112
+
// ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
113
+
fnhome_planet() ->&'staticstr {
114
+
"Tatooine"
115
+
}
116
+
}
117
+
#
118
+
# fnmain() {}
119
+
```
120
+
121
+
> __NOTE:__ Every interface has to specify all other interfaces/objects it implements or implemented for. Missing one of `for = ` or `impl = ` attributes is a compile-time error.
122
+
123
+
```compile_fail
124
+
# extern crate juniper;
125
+
use juniper::{graphql_interface, GraphQLObject};
126
+
127
+
#[derive(GraphQLObject)]
128
+
pub struct ObjA {
129
+
id: String,
130
+
}
131
+
132
+
#[graphql_interface(for = ObjA)]
133
+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at
134
+
// 'Failed to implement interface `Character` on `ObjA`: missing interface reference in implementer's `impl` attribute.'
135
+
struct Character {
136
+
id: String,
137
+
}
138
+
139
+
fn main() {}
140
+
```
141
+
142
+
143
+
### GraphQL subtyping and additional `null`able fields
144
+
145
+
GraphQL allows implementers (both objects and other interfaces) to return "subtypes" instead of an original value. Basically, this allows you to impose additional bounds on the implementation.
146
+
147
+
Valid "subtypes" are:
148
+
- interface implementer instead of an interface itself:
149
+
-`I implements T` in place of a `T`;
150
+
-`Vec<I implements T>` in place of a `Vec<T>`.
151
+
- non-null value in place of a nullable:
152
+
-`T` in place of a `Option<T>`;
153
+
-`Vec<T>` in place of a `Vec<Option<T>>`.
154
+
155
+
These rules are recursively applied, so `Vec<Vec<I implements T>>` is a valid "subtype" of a `Option<Vec<Option<Vec<Option<T>>>>>`.
156
+
157
+
Also, GraphQL allows implementers to add `null`able fields, which aren't present on an original interface.
0 commit comments