Skip to content

Commit b8f583c

Browse files
authored
feat(config): configuration override using env vars, enable/disable graphiql via config (#519)
Closes #508 ## TODO - [x] setup nice way to define env vars and their overrides - [x] Define logger overrides - [x] Define supergraph overrides (file/hive) - [x] Define HTTP overrides - [x] Remove existing `config` extractor - [x] Fix printing of error message in cases where server fails to start and logger is not configured yet - [x] graphiql disable/enable - [x] hive supergraph poll interval - [x] Fix CI - [x] Update docs and README - [x] Docs graphql-hive/console#7172
1 parent dc623d7 commit b8f583c

File tree

18 files changed

+300
-40
lines changed

18 files changed

+300
-40
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ jobs:
218218
echo "Docker image: ${{ env.DOCKER_IMAGE_NAME }}@${{ needs.docker.outputs.docker_image_digest }}"
219219
220220
docker run -d --name router -p 4000:4000 \
221-
-e HIVE__SUPERGRAPH__SOURCE="file" \
222-
-e HIVE__SUPERGRAPH__PATH="/app/supergraph.graphql" \
221+
-e SUPERGRAPH_FILE_PATH="/app/supergraph.graphql" \
223222
-v ./bench/supergraph.graphql:/app/supergraph.graphql \
224223
${{ env.DOCKER_IMAGE_NAME }}@${{ needs.docker.outputs.docker_image_digest }}
225224

.github/workflows/ci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ jobs:
130130
- name: Run router
131131
run: ./target/release/hive_router & sleep 5
132132
env:
133-
HIVE__SUPERGRAPH__SOURCE: file
134-
HIVE__SUPERGRAPH__PATH: bench/supergraph.graphql
133+
SUPERGRAPH_FILE_PATH: bench/supergraph.graphql
135134
- name: Run k6 benchmark
136135
run: k6 run bench/k6.js
137136

Cargo.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ supergraph:
3535
Alternativly, you can use environment variables to configure the router:
3636
3737
```env
38-
HIVE__SUPERGRAPH__SOURCE=file
39-
HIVE__SUPERGRAPH__PATH=./supergraph.graphql
38+
SUPERGRAPH_FILE_PATH=./supergraph.graphql
4039
```
4140

4241
Then, run the router:
@@ -58,8 +57,7 @@ The router image is being published to [Docker to GitHub Container Registry]().
5857
```bash
5958
docker run \
6059
-p 4000:4000 \
61-
-e HIVE__SUPERGRAPH__SOURCE="file" \
62-
-e HIVE__SUPERGRAPH__PATH="/app/supergraph.graphql" \
60+
-e SUPERGRAPH_FILE_PATH="/app/supergraph.graphql" \
6361
-v ./my-supergraph.graphql:/app/supergraph.graphql \
6462
ghcr.io/graphql-hive/router:latest
6563
```

audits/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"test:federation-all": "graphql-federation-audit test --run-script=\"./run-router.sh\" --graphql=\"http://localhost:4000/graphql\" --healthcheck=\"http://localhost:4000/health\" --junit",
77
"test:federation-single": "graphql-federation-audit test-suite --run-script=\"./run-router.sh\" --graphql=\"http://localhost:4000/graphql\" --healthcheck=\"http://localhost:4000/health\" --write=\"federation-audit-results.txt\"",
8-
"start:test-router": "cd .. && HIVE__SUPERGRAPH__SOURCE=file HIVE__SUPERGRAPH__PATH=lib/query-planner/fixture/spotify-supergraph.graphql cargo router",
8+
"start:test-router": "cd .. && SUPERGRAPH_FILE_PATH=lib/query-planner/fixture/spotify-supergraph.graphql cargo router",
99
"test:graphql-over-http": "node --test graphql-over-http.test.js",
1010
"test-junit:graphql-over-http": "node --test --test-reporter=junit --test-reporter-destination=\"./reports/graphql-over-http.xml\" graphql-over-http.test.js",
1111
"ci:test:graphql-over-http": "start-server-and-test start:test-router http://localhost:4000 test-junit:graphql-over-http"

audits/run-router.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ echo "running router..."
1111

1212
cd ..
1313

14-
export HIVE__SUPERGRAPH__SOURCE="file"
15-
export HIVE__SUPERGRAPH__PATH="audits/fed-audit-supergraph.graphql"
14+
export SUPERGRAPH_FILE_PATH="audits/fed-audit-supergraph.graphql"
1615
cargo router

bench/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
```
44
cargo subgraphs
55
6-
export HIVE__SUPERGRAPH__SOURCE="file"
7-
export HIVE__SUPERGRAPH__PATH="bench/supergraph.graphql"
6+
export SUPERGRAPH_FILE_PATH="bench/supergraph.graphql"
87
cargo router
98
```
109

bin/router/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
55

66
#[ntex::main]
77
async fn main() -> Result<(), Box<dyn std::error::Error>> {
8-
router_entrypoint().await
8+
match router_entrypoint().await {
9+
Ok(_) => Ok(()),
10+
Err(err) => {
11+
eprintln!("Failed to start Hive Router:\n {}", err);
12+
13+
Err(err)
14+
}
15+
}
916
}

bin/router/src/pipeline/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ pub async fn graphql_request_handler(
5353
schema_state: &Arc<SchemaState>,
5454
) -> web::HttpResponse {
5555
if req.method() == Method::GET && req.accepts_content_type(*TEXT_HTML_CONTENT_TYPE) {
56-
return web::HttpResponse::Ok()
57-
.header(CONTENT_TYPE, *TEXT_HTML_CONTENT_TYPE)
58-
.body(GRAPHIQL_HTML);
56+
if shared_state.router_config.graphiql.enabled {
57+
return web::HttpResponse::Ok()
58+
.header(CONTENT_TYPE, *TEXT_HTML_CONTENT_TYPE)
59+
.body(GRAPHIQL_HTML);
60+
} else {
61+
return web::HttpResponse::NotFound().into();
62+
}
5963
}
6064

6165
if let Some(jwt) = &shared_state.jwt_auth_runtime {

docker/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ Use the following command to run the Docker image locally:
3737

3838
```bash
3939
docker run -p 4000:4000 \
40-
-e HIVE__SUPERGRAPH__SOURCE="file" \
41-
-e HIVE__SUPERGRAPH__PATH="/app/supergraph.graphql" \
40+
-e SUPERGRAPH_FILE_PATH="/app/supergraph.graphql" \
4241
-v ./bench/supergraph.graphql:/app/supergraph.graphql \
4342
<ID_OF_THE_LOCAL_IMAGE>
4443
```

0 commit comments

Comments
 (0)