use std::sync::Arc;
use nest_rs_graphql::GraphqlContextSeed;
use nest_rs_graphql::async_graphql::{Context, Error, ErrorExtensions, Result};
use crate::Ability;
nest_rs_graphql::inventory::submit! {
GraphqlContextSeed {
owner_type_id: || None,
seed: |req, _container, gql| match req.extensions().get::<Arc<Ability>>() {
Some(ability) => gql.data(ability.clone()),
None => gql,
},
}
}
pub fn ability(ctx: &Context<'_>) -> Result<Arc<Ability>> {
ctx.data_opt::<Arc<Ability>>().cloned().ok_or_else(|| {
Error::new("missing request `Ability` — is the GraphQL auth bridge installed on /graphql?")
})
}
pub(crate) fn forbidden() -> Error {
Error::new("forbidden").extend_with(|_, e| e.set("code", "FORBIDDEN"))
}