pub struct NormalizedCacheExtension { /* private fields */ }Expand description
A query extension that lets you pass additional logic into the cache.
Implementations§
Source§impl NormalizedCacheExtension
impl NormalizedCacheExtension
Sourcepub fn update<Q: GraphQLQuery, F>(self, update: F) -> Self
pub fn update<Q: GraphQLQuery, F>(self, update: F) -> Self
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- AQueryStoreobject used to run custom update logic against other queries.dependencies- This must be passed through to theQueryStorewithout 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(),
city: None,
talks: None
});
}
data
}, dependencies)
});Sourcepub fn optimistic_result<Q: GraphQLQuery, F: Fn() -> Option<Q::ResponseData> + 'static + Send + Sync>(
self,
optimistic_result: F,
) -> Self
pub fn optimistic_result<Q: GraphQLQuery, F: Fn() -> Option<Q::ResponseData> + 'static + Send + Sync>( self, optimistic_result: F, ) -> Self
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§
Source§impl Clone for NormalizedCacheExtension
impl Clone for NormalizedCacheExtension
Source§fn clone(&self) -> NormalizedCacheExtension
fn clone(&self) -> NormalizedCacheExtension
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for NormalizedCacheExtension
impl Default for NormalizedCacheExtension
Source§fn default() -> NormalizedCacheExtension
fn default() -> NormalizedCacheExtension
Returns the “default value” for a type. Read more
impl Extension for NormalizedCacheExtension
Auto Trait Implementations§
impl Freeze for NormalizedCacheExtension
impl !RefUnwindSafe for NormalizedCacheExtension
impl Send for NormalizedCacheExtension
impl Sync for NormalizedCacheExtension
impl Unpin for NormalizedCacheExtension
impl !UnwindSafe for NormalizedCacheExtension
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more