Trait Resolver

Source
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§

Source

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 resolution
  • subgraph_name - The name of the subgraph associated with this field resolution
  • directive - The directive associated with this field resolution
  • definition - The field definition containing metadata
  • inputs - The input values provided for this field
§Returns

Returns a Result containing either the resolved FieldOutput value or an Error

Source

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 resolution
  • directive - The directive associated with this subscription field
  • definition - The field definition containing metadata about the subscription
§Returns

Returns a Result containing either a boxed Subscriber implementation or an Error

Provided Methods§

Source

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 subscription
  • subgraph_name - The name of the subgraph associated with this subscription
  • directive - 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.

Implementors§