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§
Sourcetype Config: JsonSchema + DeserializeOwned + Send
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§
Provided Methods§
Sourcefn router_service(&self, service: BoxService) -> BoxService
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.
Sourcefn supergraph_service(&self, service: BoxService) -> BoxService
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.
Sourcefn execution_service(&self, service: BoxService) -> BoxService
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).
Sourcefn subgraph_service(
&self,
_subgraph_name: &str,
service: BoxService,
) -> BoxService
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.
Sourcefn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint>
fn web_endpoints(&self) -> MultiMap<ListenAddr, Endpoint>
Return one or several Endpoint
s and ListenAddr
and the router will serve your custom web Endpoint(s).
This method is experimental and subject to change post 1.0