#[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 · 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> StructuralEq for DynamicallyResolvedValue<'a>
impl<'a> StructuralPartialEq for DynamicallyResolvedValue<'a>
Auto Trait Implementations§
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> 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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.