Struct ExtensionContext

Source
pub struct ExtensionContext<'a> {
    pub schema_env: &'a SchemaEnv,
    pub session_data: &'a Data,
    pub query_data: Option<&'a Data>,
}
Expand description

Context for extension

Fields§

§schema_env: &'a SchemaEnv

Schema-scope context data, [Registry], and custom directives.

§session_data: &'a Data

Extension-scoped context data shared across all extensions.

Can be accessed only from hooks that implement the Extension trait.

It is created with each new Request and is empty by default.

For subscriptions, the session ends when the subscription is closed.

§query_data: Option<&'a Data>

Request-scoped context data shared across all resolvers.

This is a reference to Request::data field. If the request has not initialized yet, the value is seen as None inside the Extension::request, Extension::subscribe, and Extension::prepare_request hooks.

Implementations§

Source§

impl<'a> ExtensionContext<'a>

Source

pub fn stringify_execute_doc( &self, doc: &ExecutableDocument, variables: &Variables, ) -> String

Convert the specified ExecutableDocument into a query string.

Usually used for log extension, it can hide secret arguments.

Source

pub fn sdl(&self) -> String

Returns SDL(Schema Definition Language) of this schema.

Source

pub fn sdl_with_options(&self, options: SDLExportOptions) -> String

Returns SDL(Schema Definition Language) of this schema with options.

Source

pub fn data<D: Any + Send + Sync>(&self) -> Result<&'a D>

Gets the global data defined in the Context or Schema.

If both Schema and Query have the same data type, the data in the Query is obtained.

§Errors

Returns a Error if the specified type data does not exist.

Source

pub fn data_unchecked<D: Any + Send + Sync>(&self) -> &'a D

Gets the global data defined in the Context or Schema.

§Panics

It will panic if the specified data type does not exist.

Source

pub fn data_opt<D: Any + Send + Sync>(&self) -> Option<&'a D>

Gets the global data defined in the Context or Schema or None if the specified type data does not exist.

Trait Implementations§

Source§

impl<'a> DataContext<'a> for ExtensionContext<'a>

Source§

fn data<D: Any + Send + Sync>(&self) -> Result<&'a D>

Gets the global data defined in the Context or Schema. Read more
Source§

fn data_unchecked<D: Any + Send + Sync>(&self) -> &'a D

Gets the global data defined in the Context or Schema. Read more
Source§

fn data_opt<D: Any + Send + Sync>(&self) -> Option<&'a D>

Gets the global data defined in the Context or Schema or None if the specified type data does not exist.

Auto Trait Implementations§

§

impl<'a> Freeze for ExtensionContext<'a>

§

impl<'a> !RefUnwindSafe for ExtensionContext<'a>

§

impl<'a> Send for ExtensionContext<'a>

§

impl<'a> Sync for ExtensionContext<'a>

§

impl<'a> Unpin for ExtensionContext<'a>

§

impl<'a> !UnwindSafe for ExtensionContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.