Merge pull request #135 from nm-infy/nm-infy-patch-3

Correct spellings and grammar in define_complex_object.md
This commit is contained in:
Sunli 2020-06-01 19:15:18 +08:00 committed by GitHub
commit fd2c39292a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,11 +4,11 @@ Different from `SimpleObject`, `Object` must have Resolve defined for each field
**A resolver function has to be asynchronous. The first argument has to be `&self`, second being optional `Context` and followed by field arguments.**
Resolve is used to get the value of the field. You can query a database and return the result. **The return type of the function is the type of the field.** You can also return a `async_graphql::FieldResult` so to return an error if it occrs and error message will be send to query result.
Resolve is used to get the value of the field. You can query a database and return the result. **The return type of the function is the type of the field.** You can also return a `async_graphql::FieldResult` so to return an error if it occurs an error message will be sent to query result.
When querying a database, you may need a global data base connection pool.
When creating `Schema`, you can use `SchemaBuilder::data` to setup `Schema` data, and `Context::data` to setup `Context`data.
The following `value_from_db` function showed how to retrive a database connection from `Context`.
The following `value_from_db` function showed how to retrieve a database connection from `Context`.
```rust
use async_graphql::*;
@ -32,4 +32,4 @@ impl MyObject {
Ok(conn.query_something(id)?.name)
}
}
```
```