Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rover supergraph print-json-schema #2139

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement breaking changes for apollo-federation-types 0.14
  • Loading branch information
dylan-apollo committed Sep 6, 2024
commit 44676fc80c5ea0428a292eb982db5266a5573f63
1,459 changes: 667 additions & 792 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ apollo-parser = "0.8"
apollo-encoder = "0.8"

# https://github.com/apollographql/federation-rs
apollo-federation-types = "0.13.1"
apollo-federation-types = "0.14.0-alpha.0"

# crates.io dependencies
ariadne = "0.4"
Expand All @@ -72,7 +72,7 @@ assert_cmd = "2"
assert-json-diff = "2"
anyhow = "1"
backtrace = "0.3"
backoff = { version = "0.4", features = [ "tokio" ]}
backoff = { version = "0.4", features = ["tokio"] }
base64 = "0.22"
billboard = "0.2"
buildstructor = "0.5.4"
Expand Down Expand Up @@ -201,7 +201,7 @@ assert_fs = { workspace = true }
assert-json-diff = { workspace = true }
dircpy = "0.3.19"
duct = "0.13.7"
git2 = { workspace = true, features = ["https"]}
git2 = { workspace = true, features = ["https"] }
graphql-schema-diff = "0.2.0"
httpmock = { workspace = true }
indoc = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use apollo_federation_types::build::BuildErrors;
use apollo_federation_types::rover::BuildErrors;
use thiserror::Error;

use crate::shared::{CheckTaskStatus, CheckWorkflowResponse, GraphRef, LintResponse};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::{Duration, Instant};

use apollo_federation_types::build::BuildError;
use apollo_federation_types::rover::BuildError;
use graphql_client::*;

use crate::blocking::StudioClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::operations::subgraph::delete::types::*;
use crate::shared::GraphRef;
use crate::RoverClientError;

use apollo_federation_types::build::{BuildError, BuildErrors};
use apollo_federation_types::rover::{BuildError, BuildErrors};

use graphql_client::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{operations::subgraph::delete::runner::subgraph_delete_mutation, shar
pub(crate) type MutationComposition = subgraph_delete_mutation::SubgraphDeleteMutationGraphRemoveImplementingServiceAndTriggerComposition;
pub(crate) type MutationVariables = subgraph_delete_mutation::Variables;

use apollo_federation_types::build::BuildErrors;
use apollo_federation_types::rover::BuildErrors;

use serde::Serialize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::RoverClientError;

use graphql_client::*;

use apollo_federation_types::build::{BuildError, BuildErrors};
use apollo_federation_types::rover::{BuildError, BuildErrors};

#[derive(GraphQLQuery)]
// The paths are relative to the directory where your `Cargo.toml` is located.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) type MutationVariables = subgraph_publish_mutation::Variables;
pub(crate) type UpdateResponse =
subgraph_publish_mutation::SubgraphPublishMutationGraphPublishSubgraph;

use apollo_federation_types::build::BuildErrors;
use apollo_federation_types::rover::BuildErrors;

type SchemaInput = subgraph_publish_mutation::PartialSchemaInput;
type GitContextInput = subgraph_publish_mutation::GitContextInput;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use apollo_federation_types::build::BuildError;
use apollo_federation_types::rover::BuildError;
use graphql_client::*;

use crate::blocking::StudioClient;
Expand Down
2 changes: 1 addition & 1 deletion src/command/dev/protocol/follower/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::anyhow;
use apollo_federation_types::build::SubgraphDefinition;
use apollo_federation_types::javascript::SubgraphDefinition;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

Expand Down
2 changes: 1 addition & 1 deletion src/command/dev/protocol/follower/messenger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

use anyhow::anyhow;
use apollo_federation_types::build::SubgraphDefinition;
use apollo_federation_types::javascript::SubgraphDefinition;
use crossbeam_channel::{Receiver, Sender};

use crate::command::dev::protocol::{
Expand Down
8 changes: 6 additions & 2 deletions src/command/dev/protocol/leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{

use anyhow::{anyhow, Context};
use apollo_federation_types::{
build::SubgraphDefinition,
config::{FederationVersion, SupergraphConfig},
javascript::SubgraphDefinition,
};
use camino::Utf8PathBuf;
use crossbeam_channel::{bounded, Receiver, Sender};
Expand Down Expand Up @@ -414,7 +414,11 @@ impl LeaderSession {
let mut supergraph_config: SupergraphConfig = self
.subgraphs
.iter()
.map(|((name, url), sdl)| SubgraphDefinition::new(name, url.to_string(), sdl))
.map(|((name, url), sdl)| SubgraphDefinition {
name: name.clone(),
url: url.to_string(),
sdl: sdl.clone(),
})
.collect::<Vec<SubgraphDefinition>>()
.into();

Expand Down
2 changes: 1 addition & 1 deletion src/command/dev/protocol/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::command::supergraph::compose::CompositionOutput;

use anyhow::Result;
use apollo_federation_types::build::SubgraphDefinition;
use apollo_federation_types::javascript::SubgraphDefinition;
use reqwest::Url;

pub type SubgraphName = String;
Expand Down
8 changes: 6 additions & 2 deletions src/command/dev/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;
use std::{collections::HashMap, time::Duration};

use anyhow::{anyhow, Context};
use apollo_federation_types::build::SubgraphDefinition;
use apollo_federation_types::javascript::SubgraphDefinition;
use camino::{Utf8Path, Utf8PathBuf};
use reqwest::Client;
use tokio::time::MissedTickBehavior::Delay;
Expand Down Expand Up @@ -195,7 +195,11 @@ impl SubgraphSchemaWatcher {
SubgraphSchemaWatcherKind::Once(sdl) => (sdl.clone(), None),
};

let subgraph_definition = SubgraphDefinition::new(name, url, sdl);
let subgraph_definition = SubgraphDefinition {
name,
url: url.to_string(),
sdl,
};

Ok((subgraph_definition, refresher))
}
Expand Down
2 changes: 1 addition & 1 deletion src/command/supergraph/compose/do_compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::{anyhow, Context};
use apollo_federation_types::config::FederationVersion::LatestFedTwo;
use apollo_federation_types::config::SupergraphConfig;
use apollo_federation_types::{
build::BuildResult,
config::{FederationVersion, PluginVersion},
rover::BuildResult,
};
use camino::Utf8PathBuf;
use clap::{Args, Parser};
Expand Down
2 changes: 1 addition & 1 deletion src/command/supergraph/compose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod do_compose;
#[cfg(feature = "composition-js")]
pub(crate) use do_compose::Compose;

use apollo_federation_types::build::BuildHint;
use apollo_federation_types::rover::BuildHint;

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CompositionOutput {
Expand Down
2 changes: 1 addition & 1 deletion src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::borrow::BorrowMut;
use std::error::Error;
use std::fmt::{self, Debug, Display};

use apollo_federation_types::build::BuildErrors;
use apollo_federation_types::rover::BuildErrors;

use crate::options::JsonVersion;

Expand Down
40 changes: 24 additions & 16 deletions src/utils/supergraph_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::str::FromStr;

use anyhow::anyhow;
use apollo_federation_types::build::{BuildError, BuildErrors, SubgraphDefinition};
use apollo_federation_types::config::{
FederationVersion, SchemaSource, SubgraphConfig, SupergraphConfig,
};
use apollo_federation_types::javascript::SubgraphDefinition;
use apollo_federation_types::rover::{BuildError, BuildErrors};
use apollo_parser::{cst, Parser};
use futures::future::join_all;

Expand Down Expand Up @@ -701,10 +702,10 @@ pub(crate) async fn resolve_supergraph_yaml(
// futs we're able to run them all at once rather than in parallel (even when async); takes
// resolution down from ~1min for 100 subgraphs to ~10s
let futs = supergraph_config
.iter()
.into_iter()
.map(|(subgraph_name, subgraph_data)| async {
let cloned_subgraph_name = subgraph_name.to_string();
let result = match &subgraph_data.schema {
let result = match subgraph_data.schema {
SchemaSource::File { file } => {
let relative_schema_path = match unresolved_supergraph_yaml {
FileDescriptorType::File(config_path) => match config_path.parent() {
Expand All @@ -729,8 +730,10 @@ pub(crate) async fn resolve_supergraph_yaml(
.routing_url
.clone()
.ok_or_else(err_no_routing_url)
.map(|url| {
SubgraphDefinition::new(subgraph_name.clone(), url, &schema)
.map(|url| SubgraphDefinition {
name: subgraph_name,
url,
sdl: schema,
})
})
}
Expand Down Expand Up @@ -762,11 +765,14 @@ pub(crate) async fn resolve_supergraph_yaml(

// We don't require a routing_url in config for this variant of a schema,
// if one isn't provided, just use the URL they passed for introspection.
let url = &subgraph_data
let url = subgraph_data
.routing_url
.clone()
.unwrap_or_else(|| subgraph_url.to_string());
SubgraphDefinition::new(subgraph_name.clone(), url, schema)
SubgraphDefinition {
name: subgraph_name,
url,
sdl: schema,
}
})
.map_err(RoverError::from)
}
Expand All @@ -776,7 +782,7 @@ pub(crate) async fn resolve_supergraph_yaml(
} => {
// WARNING: here's where we're returning an error on invalid graph refs; before
// this would bubble up and, I _think_, early abort the resolving
let graph_ref = match GraphRef::from_str(graph_ref) {
let graph_ref = match GraphRef::from_str(&graph_ref) {
Ok(graph_ref) => graph_ref,
Err(_err) => return Err(err_invalid_graph_ref()),
};
Expand Down Expand Up @@ -806,23 +812,25 @@ pub(crate) async fn resolve_supergraph_yaml(
{
let url = subgraph_data
.routing_url
.clone()
.unwrap_or(graph_registry_routing_url);
SubgraphDefinition::new(
subgraph_name.clone(),
SubgraphDefinition {
name: subgraph_name,
url,
&result.sdl.contents,
)
sdl: result.sdl.contents,
}
} else {
panic!("whoops: rebase me");
}
})
}
SchemaSource::Sdl { sdl } => subgraph_data
.routing_url
.clone()
.ok_or_else(err_no_routing_url)
.map(|url| SubgraphDefinition::new(subgraph_name.clone(), url, sdl)),
.map(|url| SubgraphDefinition {
name: subgraph_name,
url,
sdl,
}),
};
Ok((cloned_subgraph_name, result))
});
Expand Down