#[non_exhaustive]pub struct DynamicallyResolvedValue<'a> { /* private fields */ }Expand description
Indicates that a property’s value is dependent on another value in the query.
If VertexInfo::dynamically_required_property()
is able to determine a value for the specified property, it returns
a DynamicallyResolvedValue. The specified property’s value may be different
in different query results, but the way in which it varies can be determined programmatically
and can be resolved to a CandidateValue for each query result.
§Example
Consider the following query, which fetches emails where the sender also included their own address in the receipients:
{
Email {
contents @output
sender {
address @tag(name: "sender")
}
recipient {
address @filter(op: "=", value: ["%sender"])
}
}
}A naïve implementation of resolving the recipient edge would resolve all recipients
for each email and rely on Trustfall to filter out recipient addresses that don’t match
the sender’s address. This implementation is valid, but can be made faster.
To improve performance, the implementation could avoid loading all recipients and instead only load the recipient that matches the sender’s address (if any).
However, as the sender’s address varies from email to email, its value must be resolved
dynamically, i.e. separately for each possible query result. Resolving the recipient edge
might then look like this:
// Inside our adapter implementation:
// we use this method to resolve `recipient` edges.
fn resolve_recipient_edge<'a, V: AsVertex<Vertex> + 'a>(
&self,
contexts: ContextIterator<'a, V>,
resolve_info: &ResolveEdgeInfo,
) -> ContextOutcomeIterator<'a, V, VertexIterator<'a, Vertex>> {
if let Some(dynamic_value) = resolve_info.destination().dynamically_required_property("address") {
// The query is looking for a specific recipient's address,
// so let's look it up directly.
dynamic_value.resolve_with(self, contexts, |vertex, candidate| {
resolve_recipient_from_candidate_value(vertex, candidate)
})
} else {
// No specific recipient address, use the general-case edge resolver logic.
resolve_recipient_otherwise(contexts)
}
}Implementations§
Source§impl<'a> DynamicallyResolvedValue<'a>
impl<'a> DynamicallyResolvedValue<'a>
pub fn resolve<'vertex, AdapterT: Adapter<'vertex>, V: AsVertex<AdapterT::Vertex> + 'vertex>( self, adapter: &AdapterT, contexts: ContextIterator<'vertex, V>, ) -> ContextOutcomeIterator<'vertex, V, CandidateValue<FieldValue>>
pub fn resolve_with<'vertex, AdapterT: Adapter<'vertex>, V: AsVertex<AdapterT::Vertex> + 'vertex>( self, adapter: &AdapterT, contexts: ContextIterator<'vertex, V>, neighbor_resolver: impl FnMut(&AdapterT::Vertex, CandidateValue<FieldValue>) -> VertexIterator<'vertex, AdapterT::Vertex> + 'vertex, ) -> ContextOutcomeIterator<'vertex, V, VertexIterator<'vertex, AdapterT::Vertex>>
Trait Implementations§
Source§impl<'a> Clone for DynamicallyResolvedValue<'a>
impl<'a> Clone for DynamicallyResolvedValue<'a>
Source§fn clone(&self) -> DynamicallyResolvedValue<'a>
fn clone(&self) -> DynamicallyResolvedValue<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for DynamicallyResolvedValue<'a>
impl<'a> Debug for DynamicallyResolvedValue<'a>
Source§impl<'a> PartialEq for DynamicallyResolvedValue<'a>
impl<'a> PartialEq for DynamicallyResolvedValue<'a>
Source§fn eq(&self, other: &DynamicallyResolvedValue<'a>) -> bool
fn eq(&self, other: &DynamicallyResolvedValue<'a>) -> bool
self and other values to be equal, and is used by ==.impl<'a> Eq for DynamicallyResolvedValue<'a>
impl<'a> StructuralPartialEq for DynamicallyResolvedValue<'a>
Auto Trait Implementations§
impl<'a> Freeze for DynamicallyResolvedValue<'a>
impl<'a> RefUnwindSafe for DynamicallyResolvedValue<'a>
impl<'a> Send for DynamicallyResolvedValue<'a>
impl<'a> Sync for DynamicallyResolvedValue<'a>
impl<'a> Unpin for DynamicallyResolvedValue<'a>
impl<'a> UnsafeUnpin for DynamicallyResolvedValue<'a>
impl<'a> UnwindSafe for DynamicallyResolvedValue<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more