[][src]Struct artemis_normalized_cache::NormalizedCacheExtension

pub struct NormalizedCacheExtension { /* fields omitted */ }

A query extension that lets you pass additional logic into the cache.

Methods

impl NormalizedCacheExtension[src]

pub fn new() -> Self[src]

Create a new query extension with default options.

pub fn update<Q: GraphQLQuery, F>(self, update: F) -> Self where
    F: Fn(&Option<Q::ResponseData>, QueryStore, &mut Vec<String>) + Send + Sync + 'static, 
[src]

A custom updater function to run against related queries, such as lists of the same entity The function has 3 parameters:

  • current_data - The returned data of the query you're running. This may also be an optimistic result.
  • store - A QueryStore object used to run custom update logic against other queries.
  • dependencies - This must be passed through to the QueryStore without modification.

Example


let extension = NormalizedCacheExtension::new()
    .update::<GetConference, _>(|current_data, store, dependencies| {
        let conference = current_data.as_ref().unwrap().conference.as_ref().unwrap();
        store.update_query(GetConferences, Variables, move |mut data| {
            if let Some(ResponseData { conferences: Some(ref mut conferences) }) = data {
                conferences.push(get_conferences::GetConferencesConferences {
                    id: conference.id.clone(),
                    name: conference.name.clone()
                });
            }
            data
        }, dependencies)
    });

pub fn optimistic_result<Q: GraphQLQuery, F: Fn() -> Option<Q::ResponseData> + 'static + Send + Sync>(
    self,
    optimistic_result: F
) -> Self
[src]

A function returning an optimistic result. This result will be written to a temporary cache layer and will be pushed to subscribers immediately. If subscribers aren't used the optimistic result is ignored.

This closure must return an optional ResponseData - None is interpreted as skip optimistic result.

Trait Implementations

impl Clone for NormalizedCacheExtension[src]

impl Default for NormalizedCacheExtension[src]

impl Extension for NormalizedCacheExtension[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.