Fix sample code on Quickstart (#177)

Fix sample code on Quickstart #177
This commit is contained in:
Atsuhiro Takahashi 2020-06-15 22:07:38 +09:00 committed by GitHub
parent 064c136284
commit 3fd22ae3a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -26,7 +26,7 @@ struct Query;
#[Object]
impl Query {
#[field(desc = "Returns the sum of a and b")]
async fn add(a: i32, b: i32) -> i32 {
async fn add(&self, a: i32, b: i32) -> i32 {
a + b
}
}
@ -38,7 +38,7 @@ impl Query {
In our example, there is only Query without Mutation and Subscription, so we create the Schema with `EmptyMutation` and `EmptySubscription`, and then call `Schema::execute` to execute the Query.
```rust
let schema = Schema::new(MySchema, EmptyMutation, EmptySubscription);
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let res = schema.execute("{ add(a: 10, b: 20) }");
```
@ -47,7 +47,7 @@ let res = schema.execute("{ add(a: 10, b: 20) }");
Query returns `async_graphql::Result` with `async_graphql::http::GQLResponse ` wrapped, can be directly converted to JSON.
```rust
let json = serde_json::to_vec(async_graphql::http::GQLResponse(res));
let json = serde_json::to_string(&async_graphql::http::GQLResponse(res));
```
## Web server integration

View File

@ -26,7 +26,7 @@ struct Query;
#[Object]
impl Query {
#[field(desc = "Returns the sum of a and b")]
async fn add(a: i32, b: i32) -> i32 {
async fn add(&self, a: i32, b: i32) -> i32 {
a + b
}
}
@ -38,7 +38,7 @@ impl Query {
在我们这个例子里面只有Query没有Mutation和Subscription所以我们用`EmptyMutation`和`EmptySubscription`来创建Schema然后调用`Schema::execute`来执行查询。
```rust
let schema = Schema::new(MySchema, EmptyMutation, EmptySubscription);
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let res = schema.execute("{ add(a: 10, b: 20) }");
```
@ -47,7 +47,7 @@ let res = schema.execute("{ add(a: 10, b: 20) }");
查询返回的`async_graphql::Result`用`async_graphql::http::GQLResponse`包装起来就能直接转换为JSON。
```rust
let json = serde_json::to_vec(async_graphql::http::GQLResponse(res));
let json = serde_json::to_string(&async_graphql::http::GQLResponse(res));
```
## 和Web Server的集成