Update the books
This commit is contained in:
parent
b7bc7fea12
commit
475754d9d9
|
@ -1,8 +1,8 @@
|
|||
# Interface
|
||||
|
||||
`Interface` is used to abstract `Object`s with common fields.
|
||||
`Async-graphql` implemented it as a wrapper.
|
||||
The wrapper will forward Resolve to the `Object` that implemented this `Interface`.
|
||||
`Interface` is used to abstract `Object`s with common fields.
|
||||
`Async-graphql` implemented it as a wrapper.
|
||||
The wrapper will forward Resolve to the `Object` that implemented this `Interface`.
|
||||
Therefore, the `Object`'s fields' type, arguments must match with the `Interface`'s.
|
||||
|
||||
`Async-graphql` implemented auto conversion from `Object` to `Interface`, you only need to call `Into::into`.
|
||||
|
@ -44,5 +44,8 @@ impl Square {
|
|||
field(name = "area", type = "f32"),
|
||||
field(name = "scale", type = "Shape", arg(name = "s", type = "f32"))
|
||||
)]
|
||||
struct Shape(Circle, Square);
|
||||
```
|
||||
enum Shape {
|
||||
Circle(Circle),
|
||||
Square(Square),
|
||||
}
|
||||
```
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Union
|
||||
|
||||
The definition of `Union` is similar to `Interface`'s, **but no field allowed.**.
|
||||
The implemention is quite similar for `Async-graphql`.
|
||||
The implemention is quite similar for `Async-graphql`.
|
||||
From `Async-graphql`'s perspective, `Union` is a subset of `Interface`.
|
||||
|
||||
The following example modified the definition of `Interface` a little bit and removed fields.
|
||||
|
@ -40,5 +40,8 @@ impl Square {
|
|||
}
|
||||
|
||||
#[Union]
|
||||
struct Shape(Circle, Square);
|
||||
```
|
||||
enum Shape {
|
||||
Circle(Circle),
|
||||
Square(Square),
|
||||
}
|
||||
```
|
||||
|
|
|
@ -41,5 +41,8 @@ impl Square {
|
|||
field(name = "area", type = "f32"),
|
||||
field(name = "scale", type = "Shape", arg(name = "s", type = "f32"))
|
||||
)]
|
||||
struct Shape(Circle, Square);
|
||||
```
|
||||
enum Shape {
|
||||
Circle(Circle),
|
||||
Square(Square),
|
||||
}
|
||||
```
|
||||
|
|
|
@ -38,5 +38,8 @@ impl Square {
|
|||
}
|
||||
|
||||
#[Union]
|
||||
struct Shape(Circle, Square);
|
||||
```
|
||||
enum Shape {
|
||||
Circle(Circle),
|
||||
Square(Square),
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue
Block a user