Skip to content

Commit

Permalink
Connector request service and mapping problem selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pubmodmatt committed Jan 23, 2025
1 parent 8c81327 commit 5b421dc
Show file tree
Hide file tree
Showing 48 changed files with 2,261 additions and 1,228 deletions.
16 changes: 16 additions & 0 deletions apollo-federation/src/sources/connect/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::error::Error;
use std::fmt::Display;
use std::fmt::Formatter;
use std::str::FromStr;
use std::sync::Arc;

use apollo_compiler::ast;
Expand Down Expand Up @@ -344,6 +345,21 @@ impl HTTPMethod {
}
}

impl FromStr for HTTPMethod {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_uppercase().as_str() {
"GET" => Ok(HTTPMethod::Get),
"POST" => Ok(HTTPMethod::Post),
"PATCH" => Ok(HTTPMethod::Patch),
"PUT" => Ok(HTTPMethod::Put),
"DELETE" => Ok(HTTPMethod::Delete),
_ => Err(format!("Invalid HTTP method: {s}")),
}
}
}

#[derive(Clone, Debug)]
pub enum HeaderSource {
From(HeaderName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,8 @@ expression: "&schema"
"type": "boolean"
},
"default": {
"connect": true,
"connect_request": true,
"execution": true,
"http_request": true,
"parse_query": true,
Expand All @@ -1554,7 +1556,7 @@ expression: "&schema"
"subgraph_request": true,
"supergraph": true
},
"description": "Which spans will be eligible for span stats to be collected for viewing in the APM view. Defaults to true for `request`, `router`, `query_parsing`, `supergraph`, `execution`, `query_planning`, `subgraph`, `subgraph_request` and `http_request`.",
"description": "Which spans will be eligible for span stats to be collected for viewing in the APM view. Defaults to true for `request`, `router`, `query_parsing`, `supergraph`, `execution`, `query_planning`, `subgraph`, `subgraph_request`, `connect`, `connect_request` and `http_request`.",
"type": "object"
}
},
Expand Down Expand Up @@ -1997,6 +1999,32 @@ expression: "&schema"
"error"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"connector_request_mapping_problems": {
"$ref": "#/definitions/MappingProblems",
"description": "#/definitions/MappingProblems"
}
},
"required": [
"connector_request_mapping_problems"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"connector_response_mapping_problems": {
"$ref": "#/definitions/MappingProblems",
"description": "#/definitions/MappingProblems"
}
},
"required": [
"connector_response_mapping_problems"
],
"type": "object"
}
]
},
Expand Down Expand Up @@ -3975,6 +4003,13 @@ expression: "&schema"
},
"type": "object"
},
"MappingProblems": {
"enum": [
"problems",
"count"
],
"type": "string"
},
"MetricAggregation": {
"oneOf": [
{
Expand Down
21 changes: 21 additions & 0 deletions apollo-router/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ pub(crate) trait PluginPrivate: Send + Sync + 'static {
service
}

/// This service handles individual requests to Apollo Connectors
fn connector_request_service(
&self,
service: crate::services::connector::request_service::BoxService,
) -> crate::services::connector::request_service::BoxService {
service
}

/// Return the name of the plugin.
fn name(&self) -> &'static str
where
Expand Down Expand Up @@ -735,6 +743,12 @@ pub(crate) trait DynPlugin: Send + Sync + 'static {
service: crate::services::http::BoxService,
) -> crate::services::http::BoxService;

/// This service handles individual requests to Apollo Connectors
fn connector_request_service(
&self,
service: crate::services::connector::request_service::BoxService,
) -> crate::services::connector::request_service::BoxService;

/// Return the name of the plugin.
fn name(&self) -> &'static str;

Expand Down Expand Up @@ -783,6 +797,13 @@ where
self.http_client_service(name, service)
}

fn connector_request_service(
&self,
service: crate::services::connector::request_service::BoxService,
) -> crate::services::connector::request_service::BoxService {
self.connector_request_service(service)
}

fn name(&self) -> &'static str {
self.name()
}
Expand Down
41 changes: 16 additions & 25 deletions apollo-router/src/plugins/authentication/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,32 @@ use tower::ServiceBuilder;
use tower::ServiceExt;

use crate::plugins::authentication::subgraph::SigningParamsConfig;
use crate::services::connector_service::ConnectorInfo;
use crate::services::connector;
use crate::services::connector_service::ConnectorSourceRef;
use crate::services::connector_service::CONNECTOR_INFO_CONTEXT_KEY;
use crate::services::http::HttpRequest;

pub(super) struct ConnectorAuth {
pub(super) signing_params: Arc<HashMap<ConnectorSourceRef, Arc<SigningParamsConfig>>>,
}

impl ConnectorAuth {
pub(super) fn http_client_service(
pub(super) fn connector_request_service(
&self,
subgraph_name: &str,
service: crate::services::http::BoxService,
) -> crate::services::http::BoxService {
service: connector::request_service::BoxService,
) -> connector::request_service::BoxService {
let signing_params = self.signing_params.clone();
let subgraph_name = subgraph_name.to_string();
ServiceBuilder::new()
.map_request(move |req: HttpRequest| {
if let Ok(Some(connector_info)) = req
.context
.get::<&str, ConnectorInfo>(CONNECTOR_INFO_CONTEXT_KEY)
{
if let Some(source_name) = connector_info.source_name {
if let Some(signing_params) = signing_params
.get(&ConnectorSourceRef::new(
subgraph_name.clone(),
source_name.clone(),
))
.cloned()
{
req.context
.extensions()
.with_lock(|mut lock| lock.insert(signing_params));
}
.map_request(move |req: connector::request_service::Request| {
if let Some(ref source_name) = req.connector.id.source_name {
if let Some(signing_params) = signing_params
.get(&ConnectorSourceRef::new(
req.connector.id.subgraph_name.clone(),
source_name.clone(),
))
.cloned()
{
req.context
.extensions()
.with_lock(|mut lock| lock.insert(signing_params));
}
}
req
Expand Down
9 changes: 4 additions & 5 deletions apollo-router/src/plugins/authentication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,12 @@ impl PluginPrivate for AuthenticationPlugin {
}
}

fn http_client_service(
fn connector_request_service(
&self,
subgraph_name: &str,
service: crate::services::http::BoxService,
) -> crate::services::http::BoxService {
service: crate::services::connector::request_service::BoxService,
) -> crate::services::connector::request_service::BoxService {
if let Some(auth) = &self.connector {
auth.http_client_service(subgraph_name, service)
auth.connector_request_service(service)
} else {
service
}
Expand Down
58 changes: 0 additions & 58 deletions apollo-router/src/plugins/connectors/error.rs

This file was deleted.

Loading

0 comments on commit 5b421dc

Please sign in to comment.