Add /metadata endpoint which serves the initial, raw metadata (#459)

## Description

As a temporary means of supporting a local development setup, this PR
adds a `/metadata` endpoint that serves the raw metadata that the engine
was started with.

![image](https://github.com/hasura/v3-engine/assets/358550/bf34c3f8-d153-4a93-9044-dbaa15299481)

V3_GIT_ORIGIN_REV_ID: 44c552cfe29ee587fa0d383f7788aacc5579770f
This commit is contained in:
Philip Lykke Carlsen 2024-04-11 13:07:24 +02:00 committed by hasura-bot
parent 93d608c1ab
commit 624df9a594

View File

@ -128,7 +128,8 @@ impl TraceableError for StartupError {
async fn start_engine(server: &ServerOptions) -> Result<(), StartupError> {
let auth_config =
read_auth_config(&server.authn_config_path).map_err(StartupError::ReadAuth)?;
let schema = read_schema(&server.metadata_path).map_err(StartupError::ReadSchema)?;
let (raw_metadata, schema) =
read_schema(&server.metadata_path).map_err(StartupError::ReadSchema)?;
let http_context = HttpContext {
client: reqwest::Client::new(),
ndc_response_size_limit: None,
@ -139,6 +140,8 @@ async fn start_engine(server: &ServerOptions) -> Result<(), StartupError> {
auth_config,
});
let metadata_route = Router::new().route("/metadata", get(|| async { raw_metadata }));
let graphql_route = Router::new()
.route("/graphql", post(handle_request))
.layer(axum::middleware::from_fn(
@ -180,6 +183,7 @@ async fn start_engine(server: &ServerOptions) -> Result<(), StartupError> {
let app = Router::new()
// serve graphiql at root
.route("/", get(graphiql))
.merge(metadata_route)
.merge(graphql_route)
.merge(explain_route)
.merge(health_route)
@ -401,10 +405,12 @@ async fn handle_explain_request(
response
}
fn read_schema(metadata_path: &PathBuf) -> Result<gql::schema::Schema<GDS>, anyhow::Error> {
fn read_schema(
metadata_path: &PathBuf,
) -> Result<(String, gql::schema::Schema<GDS>), anyhow::Error> {
let raw_metadata = std::fs::read_to_string(metadata_path)?;
let metadata = open_dds::Metadata::from_json_str(&raw_metadata)?;
Ok(engine::build::build_schema(metadata)?)
Ok((raw_metadata, engine::build::build_schema(metadata)?))
}
fn read_auth_config(path: &PathBuf) -> Result<AuthConfig, anyhow::Error> {