532 B
532 B
Context
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 will need to explicitly state the lifetime of the argument.
The following example shows how to borrow data in Context
.
use async_graphql::*;
struct Query;
#[Object]
impl Query {
async fn borrow_from_context_data<'ctx>(
&self,
ctx: &'ctx Context<'_>
) -> FieldResult<&'ctx String> {
ctx.data::<String>()
}
}