pub trait Resolver: Extension {
// Required methods
fn resolve_field(
&mut self,
headers: Headers,
subgraph_name: &str,
directive: FieldDefinitionDirective<'_>,
inputs: FieldInputs,
) -> Result<FieldOutput, Error>;
fn resolve_subscription(
&mut self,
headers: Headers,
subgraph_name: &str,
directive: FieldDefinitionDirective<'_>,
) -> Result<Box<dyn Subscription>, Error>;
// Provided method
fn subscription_key(
&mut self,
headers: &Headers,
subgraph_name: &str,
directive: FieldDefinitionDirective<'_>,
) -> Option<Vec<u8>> { ... }
}Expand description
A trait that extends Extension and provides functionality for resolving fields.
Implementors of this trait are expected to provide a method to resolve field values based on the given context, directive, and inputs. This is typically used in scenarios where field resolution logic needs to be encapsulated within a resolver object, allowing for modular and reusable code design.
Required Methods§
Sourcefn resolve_field(
&mut self,
headers: Headers,
subgraph_name: &str,
directive: FieldDefinitionDirective<'_>,
inputs: FieldInputs,
) -> Result<FieldOutput, Error>
fn resolve_field( &mut self, headers: Headers, subgraph_name: &str, directive: FieldDefinitionDirective<'_>, inputs: FieldInputs, ) -> Result<FieldOutput, Error>
Resolves a field value based on the given context, directive, definition, and inputs.
§Arguments
headers- The subgraph headers associated with this field resolutionsubgraph_name- The name of the subgraph associated with this field resolutiondirective- The directive associated with this field resolutiondefinition- The field definition containing metadatainputs- The input values provided for this field
§Returns
Returns a Result containing either the resolved FieldOutput value or an Error
Sourcefn resolve_subscription(
&mut self,
headers: Headers,
subgraph_name: &str,
directive: FieldDefinitionDirective<'_>,
) -> Result<Box<dyn Subscription>, Error>
fn resolve_subscription( &mut self, headers: Headers, subgraph_name: &str, directive: FieldDefinitionDirective<'_>, ) -> Result<Box<dyn Subscription>, Error>
Resolves a subscription field by setting up a subscription handler.
§Arguments
headers- The subgraph headers associated with this field resolutiondirective- The directive associated with this subscription fielddefinition- The field definition containing metadata about the subscription
§Returns
Returns a Result containing either a boxed Subscriber implementation or an Error
Provided Methods§
Sourcefn subscription_key(
&mut self,
headers: &Headers,
subgraph_name: &str,
directive: FieldDefinitionDirective<'_>,
) -> Option<Vec<u8>>
fn subscription_key( &mut self, headers: &Headers, subgraph_name: &str, directive: FieldDefinitionDirective<'_>, ) -> Option<Vec<u8>>
Returns a key for a subscription field.
This method is used to identify unique subscription channels or connections when managing multiple active subscriptions. The returned key can be used to track, manage, or deduplicate subscriptions.
§Arguments
headers- The subgraph headers associated with this subscriptionsubgraph_name- The name of the subgraph associated with this subscriptiondirective- The directive associated with this subscription field
§Returns
Returns an Option<Vec<u8>> containing either a unique key for this
subscription or None if no deduplication is desired.