async-graphql/docs/en/src/context.md

21 lines
511 B
Markdown
Raw Normal View History

2020-04-15 03:15:30 +00:00
# Context
2020-05-13 04:49:43 +00:00
The main goal of `Context` is to acquire global data attached to Schema. **Note that if the return value of resolver function is borrowed from `Context`, you need to explictly state the lifetime of the argument.**
The following example shows how to borrow data in `Context`.
```rust
use async_graphql::*;
struct Query;
#[Object]
impl Query {
async fn borrow_from_context_data<'ctx'>(
&self,
ctx: &'ctx Context<'_>
) -> &'ctx String {
ctx.data::<String>
}
}
```