1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Extension trait for accessing acton-service request data from inside
//! `async_graphql` resolvers.
use Context;
use crateClaims;
/// Convenience accessors for data the framework injects into every GraphQL
/// request.
///
/// The framework's `GraphQL` service copies the following from the Axum
/// request `Extensions` map into the GraphQL `Request::data` map:
///
/// * [`Claims`] — present whenever the PASETO or JWT middleware (or any other
/// token validator) has authenticated the request.
/// * [`CedarAuthz`](crate::middleware::cedar::CedarAuthz) — present when the
/// `graphql-cedar` feature is enabled and Cedar is configured on the
/// service builder.
///
/// Other framework or user data (database pools, key managers, etc.) should
/// be attached to the schema at build time with
/// `SchemaBuilder::data(...)`.
///
/// # Example
///
/// ```rust,ignore
/// use async_graphql::{Context, Object};
/// use acton_service::graphql::GraphQLContextExt;
///
/// struct Query;
///
/// #[Object]
/// impl Query {
/// async fn whoami(&self, ctx: &Context<'_>) -> String {
/// ctx.claims()
/// .map(|c| c.sub.clone())
/// .unwrap_or_else(|| "anonymous".into())
/// }
/// }
/// ```