Skip to main content

hive_router_plan_executor/plugins/hooks/
on_supergraph_load.rs

1use std::sync::Arc;
2
3use graphql_tools::static_graphql::schema::Document;
4use hive_router_internal::authorization::metadata::AuthorizationMetadata;
5use hive_router_query_planner::planner::Planner;
6
7use crate::{
8    introspection::schema::SchemaMetadata,
9    plugin_trait::{EndHookPayload, FromGraphQLErrorToResponse, StartHookPayload},
10    response::graphql_error::GraphQLError,
11    SubgraphExecutorMap,
12};
13
14pub struct SupergraphData {
15    /// The metadata of the supergraph schema,
16    /// which includes the list of subgraphs, their relationships, and other relevant information about the supergraph.
17    pub metadata: SchemaMetadata,
18    /// The query planner instance that will be used to generate the query plan for the incoming GraphQL requests based on the supergraph schema.
19    pub planner: Planner,
20    /// The authorization metadata that will be used to authorize the incoming GraphQL requests based on the supergraph schema and the authorization rules defined in the router.
21    pub authorization: AuthorizationMetadata,
22    /// The map of subgraph executors that will be used to execute the query plan for the incoming GraphQL requests based on the supergraph schema.
23    pub subgraph_executor_map: SubgraphExecutorMap,
24    /// The AST of the supergraph schema document that was loaded and parsed by the router.
25    pub supergraph_schema: Arc<Document>,
26}
27
28pub type OnSupergraphLoadResult = Result<SupergraphData, GraphQLError>;
29
30pub struct OnSupergraphLoadStartHookPayload {
31    /// The current supergraph data that is currently used by the router before loading the new supergraph schema.
32    pub current_supergraph_data: Arc<Option<SupergraphData>>,
33    /// The raw SDL string of the new supergraph schema that is being loaded by the router.
34    /// Plugins can modify the SDL string before it is parsed and loaded by the router,
35    /// and the modified SDL string will be used in the loading process instead of the original one.
36    pub new_ast: Document,
37}
38
39impl StartHookPayload<OnSupergraphLoadEndHookPayload, OnSupergraphLoadResult>
40    for OnSupergraphLoadStartHookPayload
41{
42}
43
44pub type OnSupergraphLoadStartHookResult<'exec> = crate::plugin_trait::StartHookResult<
45    'exec,
46    OnSupergraphLoadStartHookPayload,
47    OnSupergraphLoadEndHookPayload,
48    OnSupergraphLoadResult,
49>;
50
51pub struct OnSupergraphLoadEndHookPayload {
52    /// The new supergraph data that is generated from loading the new supergraph schema.
53    pub new_supergraph_data: SupergraphData,
54}
55
56impl EndHookPayload<OnSupergraphLoadResult> for OnSupergraphLoadEndHookPayload {}
57
58pub type OnSupergraphLoadEndHookResult =
59    crate::plugin_trait::EndHookResult<OnSupergraphLoadEndHookPayload, OnSupergraphLoadResult>;
60
61impl FromGraphQLErrorToResponse for OnSupergraphLoadResult {
62    fn from_graphql_error_to_response(error: GraphQLError, _status_code: http::StatusCode) -> Self {
63        Err(error)
64    }
65}