Skip to content

Commit 656d433

Browse files
Implement print-json-schema command
This takes Dylan's work from #2139 and makes it work with the latest work in Rover
1 parent 132ce31 commit 656d433

File tree

4 files changed

+78
-29
lines changed

4 files changed

+78
-29
lines changed

Cargo.lock

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ apollo-parser = "0.8"
6969
apollo-encoder = "0.8"
7070

7171
# https://github.com/apollographql/federation-rs
72-
apollo-federation-types = "0.15.2"
72+
apollo-federation-types = { version = "0.15.2", features = ["json_schema"] }
7373

7474
apollo-language-server = { version = "0.4.0", default-features = false, features = ["tokio"] }
7575

@@ -122,6 +122,7 @@ pretty_assertions = "1"
122122
regex = "1"
123123
reqwest = { version = "0.12", default-features = false }
124124
rstest = "0.23.0"
125+
schemars = "0.8.21"
125126
semver = "1"
126127
serial_test = "3"
127128
serde = "1.0"
@@ -196,6 +197,7 @@ rover-client = { workspace = true }
196197
rover-graphql = { workspace = true }
197198
rover-http = { workspace = true }
198199
rover-std = { workspace = true }
200+
schemars = { workspace = true }
199201
rover-studio = { workspace = true }
200202
semver = { workspace = true }
201203
serde = { workspace = true }

src/command/output.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
use std::{
2-
collections::BTreeMap,
3-
fmt::Write,
4-
io::{self, IsTerminal},
5-
};
1+
use std::collections::BTreeMap;
2+
use std::fmt::Write;
3+
use std::io::{self, IsTerminal};
64

75
use calm_io::{stderr, stderrln};
86
use camino::Utf8PathBuf;
97
use comfy_table::Attribute::Bold;
108
use comfy_table::Cell;
119
use comfy_table::CellAlignment::Center;
12-
use serde_json::{json, Value};
13-
use termimad::{crossterm::style::Attribute::Underlined, MadSkin};
14-
1510
use rover_client::operations::contract::describe::ContractDescribeResponse;
1611
use rover_client::operations::contract::publish::ContractPublishResponse;
1712
use rover_client::operations::graph::publish::GraphPublishResponse;
@@ -25,11 +20,13 @@ use rover_client::shared::{
2520
};
2621
use rover_client::RoverClientError;
2722
use rover_std::Style;
23+
use serde_json::{json, Value};
24+
use termimad::crossterm::style::Attribute::Underlined;
25+
use termimad::MadSkin;
2826

2927
use crate::command::supergraph::compose::CompositionOutput;
3028
use crate::command::template::queries::list_templates_for_language::ListTemplatesForLanguageTemplates;
31-
use crate::options::JsonVersion;
32-
use crate::options::ProjectLanguage;
29+
use crate::options::{JsonVersion, ProjectLanguage};
3330
use crate::utils::table;
3431
use crate::RoverError;
3532

@@ -56,6 +53,7 @@ pub enum RoverOutput {
5653
DocsList(BTreeMap<&'static str, &'static str>),
5754
FetchResponse(FetchResponse),
5855
SupergraphSchema(String),
56+
JsonSchema(String),
5957
CompositionResult(CompositionOutput),
6058
SubgraphList(SubgraphListResponse),
6159
CheckWorkflowResponse(CheckWorkflowResponse),
@@ -284,6 +282,7 @@ impl RoverOutput {
284282
}
285283
}
286284
RoverOutput::SupergraphSchema(csdl) => Some((csdl).to_string()),
285+
RoverOutput::JsonSchema(schema) => Some(schema.clone()),
287286
RoverOutput::CompositionResult(composition_output) => {
288287
let warn_prefix = Style::HintPrefix.paint("HINT:");
289288

@@ -498,6 +497,7 @@ impl RoverOutput {
498497
}
499498
RoverOutput::FetchResponse(fetch_response) => json!(fetch_response),
500499
RoverOutput::SupergraphSchema(csdl) => json!({ "core_schema": csdl }),
500+
RoverOutput::JsonSchema(schema) => Value::String(schema.clone()),
501501
RoverOutput::CompositionResult(composition_output) => {
502502
if let Some(federation_version) = &composition_output.federation_version {
503503
json!({
@@ -681,28 +681,20 @@ mod tests {
681681
use apollo_federation_types::rover::{BuildError, BuildErrors};
682682
use assert_json_diff::assert_json_eq;
683683
use chrono::{DateTime, Local, Utc};
684-
685684
use console::strip_ansi_codes;
686-
use rover_client::{
687-
operations::{
688-
graph::publish::{ChangeSummary, FieldChanges, TypeChanges},
689-
persisted_queries::publish::PersistedQueriesOperationCounts,
690-
subgraph::{
691-
delete::SubgraphDeleteResponse,
692-
list::{SubgraphInfo, SubgraphUpdatedAt},
693-
},
694-
},
695-
shared::{
696-
ChangeSeverity, CheckTaskStatus, CheckWorkflowResponse, CustomCheckResponse,
697-
Diagnostic, LintCheckResponse, OperationCheckResponse, ProposalsCheckResponse,
698-
ProposalsCheckSeverityLevel, ProposalsCoverage, RelatedProposal, SchemaChange, Sdl,
699-
SdlType, Violation,
700-
},
685+
use rover_client::operations::graph::publish::{ChangeSummary, FieldChanges, TypeChanges};
686+
use rover_client::operations::persisted_queries::publish::PersistedQueriesOperationCounts;
687+
use rover_client::operations::subgraph::delete::SubgraphDeleteResponse;
688+
use rover_client::operations::subgraph::list::{SubgraphInfo, SubgraphUpdatedAt};
689+
use rover_client::shared::{
690+
ChangeSeverity, CheckTaskStatus, CheckWorkflowResponse, CustomCheckResponse, Diagnostic,
691+
LintCheckResponse, OperationCheckResponse, ProposalsCheckResponse,
692+
ProposalsCheckSeverityLevel, ProposalsCoverage, RelatedProposal, SchemaChange, Sdl,
693+
SdlType, Violation,
701694
};
702695

703-
use crate::options::JsonOutput;
704-
705696
use super::*;
697+
use crate::options::JsonOutput;
706698

707699
#[test]
708700
fn docs_list_json() {

src/command/supergraph/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use apollo_federation_types::config::SupergraphConfig;
12
use camino::Utf8PathBuf;
23
use clap::Parser;
4+
use schemars::schema_for;
35
use serde::Serialize;
46

57
use crate::utils::client::StudioClientConfig;
@@ -19,6 +21,9 @@ pub enum Command {
1921
/// Locally compose supergraph SDL from a set of subgraph schemas
2022
Compose(compose::Compose),
2123

24+
/// Print the JSON Schema of the config for `compose`
25+
PrintJsonSchema,
26+
2227
/// Fetch supergraph SDL from the graph registry
2328
Fetch(fetch::Fetch),
2429
}
@@ -37,6 +42,12 @@ impl Supergraph {
3742
.run(override_install_path, client_config, output_file)
3843
.await
3944
}
45+
Command::PrintJsonSchema => {
46+
let schema = schema_for!(SupergraphConfig);
47+
Ok(RoverOutput::JsonSchema(
48+
serde_json::to_string_pretty(&schema).unwrap(),
49+
))
50+
}
4051
}
4152
}
4253
}

0 commit comments

Comments
 (0)