Struct apollo_router::Context
source ยท pub struct Context { /* private fields */ }
Expand description
A map of arbitrary JSON values, for use by plugins.
Context makes use of DashMap
under the hood which tries to handle concurrency
by allowing concurrency across threads without requiring locking. This is great
for usability but could lead to surprises when updates are highly contested.
Within the router, contention is likely to be highest within plugins which
provide crate::services::SubgraphRequest
or
crate::services::SubgraphResponse
processing. At such times,
plugins should restrict themselves to the Context::get
and Context::upsert
functions to minimise the possibility of mis-sequenced updates.
Implementationsยง
sourceยงimpl Context
impl Context
sourcepub fn contains_key<K>(&self, key: K) -> boolwhere
K: Into<String>,
pub fn contains_key<K>(&self, key: K) -> boolwhere
K: Into<String>,
Returns true if the context contains a value for the specified key.
sourcepub fn get<K, V>(&self, key: K) -> Result<Option<V>, BoxError>where
K: Into<String>,
V: for<'de> Deserialize<'de>,
pub fn get<K, V>(&self, key: K) -> Result<Option<V>, BoxError>where
K: Into<String>,
V: for<'de> Deserialize<'de>,
Get a value from the context using the provided key.
Semantics:
- If the operation fails, then the key is not present.
- If the operation succeeds, the value is an
Option
.
sourcepub fn insert<K, V>(&self, key: K, value: V) -> Result<Option<V>, BoxError>where
K: Into<String>,
V: for<'de> Deserialize<'de> + Serialize,
pub fn insert<K, V>(&self, key: K, value: V) -> Result<Option<V>, BoxError>where
K: Into<String>,
V: for<'de> Deserialize<'de> + Serialize,
Insert a value int the context using the provided key and value.
Semantics:
- If the operation fails, then the pair has not been inserted.
- If the operation succeeds, the result is the old value as an
Option
.
sourcepub fn insert_json_value<K>(&self, key: K, value: Value) -> Option<Value>where
K: Into<String>,
pub fn insert_json_value<K>(&self, key: K, value: Value) -> Option<Value>where
K: Into<String>,
Insert a value in the context using the provided key and value.
Semantics: the result is the old value as an Option
.
sourcepub fn get_json_value<K>(&self, key: K) -> Option<Value>where
K: Into<String>,
pub fn get_json_value<K>(&self, key: K) -> Option<Value>where
K: Into<String>,
Get a json value from the context using the provided key.
sourcepub fn upsert<K, V>(
&self,
key: K,
upsert: impl Fn(V) -> V
) -> Result<(), BoxError>where
K: Into<String>,
V: for<'de> Deserialize<'de> + Serialize + Default,
pub fn upsert<K, V>(
&self,
key: K,
upsert: impl Fn(V) -> V
) -> Result<(), BoxError>where
K: Into<String>,
V: for<'de> Deserialize<'de> + Serialize + Default,
Upsert a value in the context using the provided key and resolving function.
The resolving function must yield a value to be used in the context. It is provided with the current value to use in evaluating which value to yield.
Semantics:
- If the operation fails, then the pair has not been inserted (or a current value updated).
- If the operation succeeds, the pair have either updated an existing value or been inserted.
Trait Implementationsยง
sourceยงimpl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementationsยง
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementationsยง
ยงimpl<T> FutureExt for T
impl<T> FutureExt for T
ยงfn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
ยงfn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceยงimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourceยงfn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
ยงimpl<D> OwoColorize for D
impl<D> OwoColorize for D
ยงfn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
ยงfn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
ยงfn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
ยงfn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
ยงfn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
ยงfn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
ยงfn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
ยงfn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
ยงfn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
ยงfn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
ยงfn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
ยงfn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
ยงfn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
ยงfn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
ยงfn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
ยงfn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
ยงfn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
ยงfn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
ยงfn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
ยงfn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
ยงfn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
ยงfn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
ยงfn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
ยงfn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
ยงfn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
ยงfn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
ยงfn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
ยงfn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
ยงfn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreยงfn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read moreยงfn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
ยงfn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
ยงfn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
ยงfn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
sourceยงimpl<T> Serialize for Twhere
T: Serialize + ?Sized,
impl<T> Serialize for Twhere
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
sourceยงimpl<T> Variant for Twhere
T: Any + Clone + SendSync,
impl<T> Variant for Twhere
T: Any + Clone + SendSync,
sourceยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Variant
trait object to &mut dyn Any
.sourceยงfn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Variant
trait object to Box<dyn Any>
.