From 475754d9d95e0c2f50801027f846499f1e8df32b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Sun, 10 May 2020 21:39:43 -0700 Subject: [PATCH] Update the books --- docs/en/src/define_interface.md | 13 ++++++++----- docs/en/src/define_union.md | 9 ++++++--- docs/zh-CN/src/define_interface.md | 7 +++++-- docs/zh-CN/src/define_union.md | 7 +++++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/docs/en/src/define_interface.md b/docs/en/src/define_interface.md index 95d428ce..9642de98 100644 --- a/docs/en/src/define_interface.md +++ b/docs/en/src/define_interface.md @@ -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); -``` \ No newline at end of file +enum Shape { + Circle(Circle), + Square(Square), +} +``` diff --git a/docs/en/src/define_union.md b/docs/en/src/define_union.md index 136ff959..7b58423a 100644 --- a/docs/en/src/define_union.md +++ b/docs/en/src/define_union.md @@ -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); -``` \ No newline at end of file +enum Shape { + Circle(Circle), + Square(Square), +} +``` diff --git a/docs/zh-CN/src/define_interface.md b/docs/zh-CN/src/define_interface.md index e98c0383..2aa82852 100644 --- a/docs/zh-CN/src/define_interface.md +++ b/docs/zh-CN/src/define_interface.md @@ -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); -``` \ No newline at end of file +enum Shape { + Circle(Circle), + Square(Square), +} +``` diff --git a/docs/zh-CN/src/define_union.md b/docs/zh-CN/src/define_union.md index 42b382f2..6fc35965 100644 --- a/docs/zh-CN/src/define_union.md +++ b/docs/zh-CN/src/define_union.md @@ -38,5 +38,8 @@ impl Square { } #[Union] -struct Shape(Circle, Square); -``` \ No newline at end of file +enum Shape { + Circle(Circle), + Square(Square), +} +```