Skip to content

Commit 9e82367

Browse files
Merge pull request apollographql#309 from apollographql/lb/connectors-81
fix: make parent field suffix less ambiguous
2 parents 0e59ff7 + 7221042 commit 9e82367

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

apollo-router/src/plugins/connectors/join_spec_helpers.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ pub(super) fn make_any_scalar() -> ExtendedType {
512512

513513
use apollo_compiler::ast::Selection as GraphQLSelection;
514514

515+
use super::request_inputs::PARENT_PREFIX;
516+
515517
fn new_field(name: String, selection: Option<Vec<GraphQLSelection>>) -> GraphQLSelection {
516518
GraphQLSelection::Field(
517519
apollo_compiler::ast::Field {
@@ -538,8 +540,8 @@ pub(super) fn parameters_to_selection_set(paths: &Vec<String>) -> Vec<GraphQLSel
538540

539541
for path in paths {
540542
let mut parts: Vec<&str> = path.split('.').collect();
541-
// "this" is an alias, so we can ignore it
542-
if parts.first() == Some(&"this") {
543+
// "$this" is an alias, so we can ignore it
544+
if parts.first() == Some(&PARENT_PREFIX) {
543545
parts = parts[1..].to_vec();
544546
}
545547

@@ -598,8 +600,8 @@ mod tests {
598600
"b.c".to_string(),
599601
"b.d.e".to_string(),
600602
"b.d.f".to_string(),
601-
"this.g".to_string(),
602-
"this.h.i".to_string()
603+
"$this.g".to_string(),
604+
"$this.h.i".to_string()
603605
])),
604606
"id b { c d { e f } } g h { i }"
605607
)

apollo-router/src/plugins/connectors/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod subgraph_connector;
88
mod supergraph;
99
pub(crate) use supergraph::generate_connector_supergraph;
1010
mod http_json_transport;
11+
mod request_inputs;
1112
mod request_response;
1213
mod url_path_parser;
1314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use serde_json_bytes::ByteString;
2+
use serde_json_bytes::Map;
3+
use serde_json_bytes::Value;
4+
5+
pub(super) const PARENT_PREFIX: &str = "$this";
6+
7+
#[derive(Debug, Default)]
8+
pub(super) struct RequestInputs {
9+
pub(super) arguments: Map<ByteString, Value>,
10+
pub(super) parent: Map<ByteString, Value>,
11+
}
12+
13+
impl RequestInputs {
14+
pub(super) fn merge(&self) -> Value {
15+
let mut new = Map::new();
16+
new.extend(self.parent.clone());
17+
new.extend(self.arguments.clone());
18+
// if parent types are shadowed by arguments, we can use `$this.` to access them
19+
new.insert(PARENT_PREFIX, Value::Object(self.parent.clone()));
20+
Value::Object(new)
21+
}
22+
}

apollo-router/src/plugins/connectors/request_response.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use apollo_compiler::validation::Valid;
55
use apollo_compiler::ExecutableDocument;
66
use apollo_compiler::Schema;
77
use serde_json_bytes::ByteString;
8-
use serde_json_bytes::Map;
98
use serde_json_bytes::Value;
109

1110
use super::connector::ConnectorKind;
1211
use super::connector::ConnectorTransport;
1312
use super::http_json_transport::HttpJsonTransportError;
13+
use super::request_inputs::RequestInputs;
1414
use super::Connector;
1515
use crate::json_ext::Object;
1616
use crate::services::SubgraphRequest;
@@ -25,23 +25,6 @@ pub(crate) struct ResponseParams {
2525
key: ResponseKey,
2626
}
2727

28-
#[derive(Debug, Default)]
29-
struct RequestInputs {
30-
arguments: Map<ByteString, Value>,
31-
parent: Map<ByteString, Value>,
32-
}
33-
34-
impl RequestInputs {
35-
fn merge(&self) -> Value {
36-
let mut new = Map::new();
37-
new.extend(self.parent.clone());
38-
new.extend(self.arguments.clone());
39-
// if parent types are shadowed by arguments, we can use `this.` to access them
40-
new.insert("this", Value::Object(self.parent.clone()));
41-
Value::Object(new)
42-
}
43-
}
44-
4528
#[derive(Clone, Debug)]
4629
enum ResponseKey {
4730
RootField {

0 commit comments

Comments
 (0)