Skip to content

Commit 247c1ce

Browse files
authored
Rename original_url to default for subgraph url overrides (#589)
Rename it to `default` to follow the same pattern as for timeout expressions
1 parent cd1d576 commit 247c1ce

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
config: minor
3+
router: minor
4+
executor: minor
5+
---
6+
7+
# Rename `original_url` variable to `default` in subgraph URL override expressions.
8+
9+
This change aligns the variable naming with other configuration expressions, such as timeout configuration.
10+
11+
When using expressions to override subgraph URLs, use `.default` to refer to the original URL defined in the subgraph definition.
12+
13+
Example:
14+
15+
```yaml
16+
url:
17+
expression: |
18+
if .request.headers."x-region" == "us-east" {
19+
"https://products-us-east.example.com/graphql"
20+
} else {
21+
.default
22+
}
23+
```

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ override_subgraph_urls:
105105
} else if .request.headers."x-region" == "eu-west" {
106106
"https://products-eu-west.example.com/graphql"
107107
} else {
108-
.original_url
108+
.default
109109
}
110110
111111
query_planner:
@@ -1691,7 +1691,7 @@ products:
16911691
} else if .request.headers."x-region" == "eu-west" {
16921692
"https://products-eu-west.example.com/graphql"
16931693
} else {
1694-
.original_url
1694+
.default
16951695
}
16961696
16971697
@@ -1704,7 +1704,7 @@ products:
17041704

17051705
|Name|Type|Description|Required|
17061706
|----|----|-----------|--------|
1707-
|**url**||Overrides for the URL of the subgraph.<br/><br/>For convenience, a plain string in your configuration will be treated as a static URL.<br/><br/>### Static URL Example<br/>```yaml<br/>url: "https://api.example.com/graphql"<br/>```<br/><br/>### Dynamic Expression Example<br/><br/>The expression has access to the following variables:<br/>- `request`: The incoming HTTP request, including headers and other metadata.<br/>- `original_url`: The original URL of the subgraph (from supergraph sdl).<br/><br/>```yaml<br/>url:<br/> expression: \|<br/> if .request.headers."x-region" == "us-east" {<br/> "https://products-us-east.example.com/graphql"<br/> } else if .request.headers."x-region" == "eu-west" {<br/> "https://products-eu-west.example.com/graphql"<br/> } else {<br/> .original_url<br/> }<br/>|yes|
1707+
|**url**||Overrides for the URL of the subgraph.<br/><br/>For convenience, a plain string in your configuration will be treated as a static URL.<br/><br/>### Static URL Example<br/>```yaml<br/>url: "https://api.example.com/graphql"<br/>```<br/><br/>### Dynamic Expression Example<br/><br/>The expression has access to the following variables:<br/>- `request`: The incoming HTTP request, including headers and other metadata.<br/>- `default`: The original URL of the subgraph (from supergraph sdl).<br/><br/>```yaml<br/>url:<br/> expression: \|<br/> if .request.headers."x-region" == "us-east" {<br/> "https://products-us-east.example.com/graphql"<br/> } else if .request.headers."x-region" == "eu-west" {<br/> "https://products-eu-west.example.com/graphql"<br/> } else {<br/> .default<br/> }<br/>|yes|
17081708

17091709
<a name="query_planner"></a>
17101710
## query\_planner: object

e2e/configs/override_subgraph_urls/override_dynamic_header.router.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ override_subgraph_urls:
99
if .request.headers."x-accounts-port" == "4100" {
1010
"http://0.0.0.0:4100/accounts"
1111
} else {
12-
.original_url
12+
.default
1313
}

e2e/src/override_subgraph_urls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod override_subgraph_urls_e2e_tests {
4343
/// The router config overrides the URL for the "accounts" subgraph to point to 4100
4444
/// when a specific header is present.
4545
/// This way we can verify that the override is applied correctly.
46-
/// Without the header, the request goes to 4200 and fail (thanks to `.original_url`).
46+
/// Without the header, the request goes to 4200 and fail (thanks to `.default`).
4747
async fn should_override_subgraph_url_based_on_header_value() {
4848
let subgraphs_server = SubgraphsServer::start_with_port(4100).await;
4949
let app = init_router_from_config_file(
@@ -68,7 +68,7 @@ mod override_subgraph_urls_e2e_tests {
6868
"expected 1 request to accounts subgraph"
6969
);
7070

71-
// Makes the expression to evaluate to port 4200 (value of .original_url)
71+
// Makes the expression to evaluate to port 4200 (value of .default)
7272
// which is not running, so the request fails
7373
let req = init_graphql_request("{ users { id } }", None);
7474
let resp = test::call_service(&app.app, req.to_request()).await;

lib/executor/src/executors/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl SubgraphExecutorMap {
237237

238238
let value = VrlValue::Object(BTreeMap::from([
239239
("request".into(), client_request.into()),
240-
("original_url".into(), original_url_value),
240+
("default".into(), original_url_value),
241241
]));
242242

243243
// Resolve the expression to get an endpoint URL.

lib/router-config/src/override_subgraph_urls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct PerSubgraphConfig {
3232
///
3333
/// The expression has access to the following variables:
3434
/// - `request`: The incoming HTTP request, including headers and other metadata.
35-
/// - `original_url`: The original URL of the subgraph (from supergraph sdl).
35+
/// - `default`: The original URL of the subgraph (from supergraph sdl).
3636
///
3737
/// ```yaml
3838
/// url:
@@ -42,7 +42,7 @@ pub struct PerSubgraphConfig {
4242
/// } else if .request.headers."x-region" == "eu-west" {
4343
/// "https://products-eu-west.example.com/graphql"
4444
/// } else {
45-
/// .original_url
45+
/// .default
4646
/// }
4747
pub url: UrlOrExpression,
4848
}
@@ -62,7 +62,7 @@ fn override_subgraph_urls_example_1() -> OverrideSubgraphUrlsConfig {
6262
} else if .request.headers."x-region" == "eu-west" {
6363
"https://products-eu-west.example.com/graphql"
6464
} else {
65-
.original_url
65+
.default
6666
}
6767
"#;
6868
let mut subgraphs = HashMap::new();

0 commit comments

Comments
 (0)