Trait Plugin

Source
pub trait Plugin:
    Send
    + Sync
    + 'static {
    type Config: JsonSchema + DeserializeOwned + Send;

    // Required method
    fn new<'async_trait>(
        init: PluginInit<Self::Config>,
    ) -> Pin<Box<dyn Future<Output = Result<Self, BoxError>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait;

    // Provided methods
    fn router_service(&self, service: BoxService) -> BoxService { ... }
    fn supergraph_service(&self, service: BoxService) -> BoxService { ... }
    fn execution_service(&self, service: BoxService) -> BoxService { ... }
    fn subgraph_service(
        &self,
        _subgraph_name: &str,
        service: BoxService,
    ) -> BoxService { ... }
    fn name(&self) -> &'static str
       where Self: Sized { ... }
    fn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint> { ... }
}
Expand description

All router plugins must implement the Plugin trait.

This trait defines lifecycle hooks that enable hooking into Apollo Router services. The trait also provides a default implementations for each hook, which returns the associated service unmodified. For more information about the plugin lifecycle please check this documentation https://www.apollographql.com/docs/router/customizations/native/#plugin-lifecycle

Required Associated Types§

Source

type Config: JsonSchema + DeserializeOwned + Send

The configuration for this plugin. Typically a struct with #[derive(serde::Deserialize)].

If a plugin is [registered][register_plugin()!], it can be enabled through the plugins section of Router YAML configuration by having a sub-section named after the plugin. The contents of this section are deserialized into this Config type and passed to Plugin::new as part of PluginInit.

Required Methods§

Source

fn new<'async_trait>( init: PluginInit<Self::Config>, ) -> Pin<Box<dyn Future<Output = Result<Self, BoxError>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

This is invoked once after the router starts and compiled-in plugins are registered.

Provided Methods§

Source

fn router_service(&self, service: BoxService) -> BoxService

This function is EXPERIMENTAL and its signature is subject to change.

This service runs at the very beginning and very end of the request lifecycle. It’s the entrypoint of every requests and also the last hook before sending the response. Define supergraph_service if your customization needs to interact at the earliest or latest point possible. For example, this is a good opportunity to perform JWT verification before allowing a request to proceed further.

Source

fn supergraph_service(&self, service: BoxService) -> BoxService

This service runs after the HTTP request payload has been deserialized into a GraphQL request, and before the GraphQL response payload is serialized into a raw HTTP response. Define supergraph_service if your customization needs to interact at the earliest or latest point possible, yet operates on GraphQL payloads.

Source

fn execution_service(&self, service: BoxService) -> BoxService

This service handles initiating the execution of a query plan after it’s been generated. Define execution_service if your customization includes logic to govern execution (for example, if you want to block a particular query based on a policy decision).

Source

fn subgraph_service( &self, _subgraph_name: &str, service: BoxService, ) -> BoxService

This service handles communication between the Apollo Router and your subgraphs. Define subgraph_service to configure this communication (for example, to dynamically add headers to pass to a subgraph). The _subgraph_name parameter is useful if you need to apply a customization only specific subgraphs.

Source

fn name(&self) -> &'static str
where Self: Sized,

Return the name of the plugin.

Source

fn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint>

Return one or several Endpoints and ListenAddr and the router will serve your custom web Endpoint(s).

This method is experimental and subject to change post 1.0

Implementors§