Update the books

This commit is contained in:
Blaine Bublitz 2020-05-10 21:39:43 -07:00
parent b7bc7fea12
commit 475754d9d9
4 changed files with 24 additions and 12 deletions

View File

@ -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),
}
```

View File

@ -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),
}
```

View File

@ -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),
}
```

View File

@ -38,5 +38,8 @@ impl Square {
}
#[Union]
struct Shape(Circle, Square);
```
enum Shape {
Circle(Circle),
Square(Square),
}
```