Skip to content

Commit f1f3371

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 c31c00e commit f1f3371

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 @@ prettytable-rs = "0.10"
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"
@@ -197,6 +198,7 @@ rover-client = { workspace = true }
197198
rover-graphql = { workspace = true }
198199
rover-http = { workspace = true }
199200
rover-std = { workspace = true }
201+
schemars = { workspace = true }
200202
rover-studio = { workspace = true }
201203
semver = { workspace = true }
202204
serde = { workspace = true }

src/command/output.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
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;
9-
use serde_json::{json, Value};
10-
use termimad::{crossterm::style::Attribute::Underlined, MadSkin};
11-
127
use rover_client::operations::contract::describe::ContractDescribeResponse;
138
use rover_client::operations::contract::publish::ContractPublishResponse;
149
use rover_client::operations::graph::publish::GraphPublishResponse;
@@ -22,11 +17,13 @@ use rover_client::shared::{
2217
};
2318
use rover_client::RoverClientError;
2419
use rover_std::Style;
20+
use serde_json::{json, Value};
21+
use termimad::crossterm::style::Attribute::Underlined;
22+
use termimad::MadSkin;
2523

2624
use crate::command::supergraph::compose::CompositionOutput;
2725
use crate::command::template::queries::list_templates_for_language::ListTemplatesForLanguageTemplates;
28-
use crate::options::JsonVersion;
29-
use crate::options::ProjectLanguage;
26+
use crate::options::{JsonVersion, ProjectLanguage};
3027
use crate::utils::table::{self, row};
3128
use crate::RoverError;
3229

@@ -53,6 +50,7 @@ pub enum RoverOutput {
5350
DocsList(BTreeMap<&'static str, &'static str>),
5451
FetchResponse(FetchResponse),
5552
SupergraphSchema(String),
53+
JsonSchema(String),
5654
CompositionResult(CompositionOutput),
5755
SubgraphList(SubgraphListResponse),
5856
CheckWorkflowResponse(CheckWorkflowResponse),
@@ -278,6 +276,7 @@ impl RoverOutput {
278276
}
279277
}
280278
RoverOutput::SupergraphSchema(csdl) => Some((csdl).to_string()),
279+
RoverOutput::JsonSchema(schema) => Some(schema.clone()),
281280
RoverOutput::CompositionResult(composition_output) => {
282281
let warn_prefix = Style::HintPrefix.paint("HINT:");
283282

@@ -486,6 +485,7 @@ impl RoverOutput {
486485
}
487486
RoverOutput::FetchResponse(fetch_response) => json!(fetch_response),
488487
RoverOutput::SupergraphSchema(csdl) => json!({ "core_schema": csdl }),
488+
RoverOutput::JsonSchema(schema) => Value::String(schema.clone()),
489489
RoverOutput::CompositionResult(composition_output) => {
490490
if let Some(federation_version) = &composition_output.federation_version {
491491
json!({
@@ -669,28 +669,20 @@ mod tests {
669669
use apollo_federation_types::rover::{BuildError, BuildErrors};
670670
use assert_json_diff::assert_json_eq;
671671
use chrono::{DateTime, Local, Utc};
672-
673672
use console::strip_ansi_codes;
674-
use rover_client::{
675-
operations::{
676-
graph::publish::{ChangeSummary, FieldChanges, TypeChanges},
677-
persisted_queries::publish::PersistedQueriesOperationCounts,
678-
subgraph::{
679-
delete::SubgraphDeleteResponse,
680-
list::{SubgraphInfo, SubgraphUpdatedAt},
681-
},
682-
},
683-
shared::{
684-
ChangeSeverity, CheckTaskStatus, CheckWorkflowResponse, CustomCheckResponse,
685-
Diagnostic, LintCheckResponse, OperationCheckResponse, ProposalsCheckResponse,
686-
ProposalsCheckSeverityLevel, ProposalsCoverage, RelatedProposal, SchemaChange, Sdl,
687-
SdlType, Violation,
688-
},
673+
use rover_client::operations::graph::publish::{ChangeSummary, FieldChanges, TypeChanges};
674+
use rover_client::operations::persisted_queries::publish::PersistedQueriesOperationCounts;
675+
use rover_client::operations::subgraph::delete::SubgraphDeleteResponse;
676+
use rover_client::operations::subgraph::list::{SubgraphInfo, SubgraphUpdatedAt};
677+
use rover_client::shared::{
678+
ChangeSeverity, CheckTaskStatus, CheckWorkflowResponse, CustomCheckResponse, Diagnostic,
679+
LintCheckResponse, OperationCheckResponse, ProposalsCheckResponse,
680+
ProposalsCheckSeverityLevel, ProposalsCoverage, RelatedProposal, SchemaChange, Sdl,
681+
SdlType, Violation,
689682
};
690683

691-
use crate::options::JsonOutput;
692-
693684
use super::*;
685+
use crate::options::JsonOutput;
694686

695687
#[test]
696688
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+
return Ok(RoverOutput::JsonSchema(
48+
serde_json::to_string_pretty(&schema).unwrap(),
49+
));
50+
}
4051
}
4152
}
4253
}

0 commit comments

Comments
 (0)