Skip to content

Commit

Permalink
ROVER-69 Unify supergraph_config parsing
Browse files Browse the repository at this point in the history
We do this in both supergraph commands and dev
and having it in two places is not helping.
  • Loading branch information
jonathanrainer committed Jul 26, 2024
1 parent 9b49532 commit eba5e06
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 261 deletions.
53 changes: 14 additions & 39 deletions src/command/dev/do_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ use apollo_federation_types::config::FederationVersion;
use camino::Utf8PathBuf;
use crossbeam_channel::bounded as sync_channel;

use rover_std::{Emoji, Fs};
use rover_std::Emoji;

use crate::command::dev::protocol::FollowerMessage;
use crate::command::supergraph::expand_supergraph_yaml;
use crate::utils::client::StudioClientConfig;
use crate::utils::supergraph_config::get_supergraph_config;
use crate::{RoverError, RoverOutput, RoverResult};

use super::protocol::{FollowerChannel, FollowerMessenger, LeaderChannel, LeaderSession};
use super::remote_subgraphs::RemoteSubgraphs;
use super::router::RouterConfigHandler;
use super::Dev;

Expand All @@ -36,42 +35,18 @@ impl Dev {
let leader_channel = LeaderChannel::new();
let follower_channel = FollowerChannel::new();

// Read in Remote subgraphs
let remote_subgraphs = match &self.opts.supergraph_opts.graph_ref {
Some(graph_ref) => Some(RemoteSubgraphs::fetch(
&client_config.get_authenticated_client(&self.opts.plugin_opts.profile)?,
&self
.opts
.supergraph_opts
.federation_version
.clone()
.unwrap_or(FederationVersion::LatestFedTwo),
graph_ref,
)?),
None => None,
};

// Read in Local Supergraph Config
let supergraph_config =
if let Some(config_path) = &self.opts.supergraph_opts.supergraph_config_path {
let config_content = Fs::read_file(config_path)?;
Some(expand_supergraph_yaml(&config_content)?)
} else {
None
};

// Merge Remote and Local Supergraph Configs
let supergraph_config = match remote_subgraphs {
Some(remote_subgraphs) => match supergraph_config {
Some(supergraph_config) => {
let mut merged_supergraph_config = remote_subgraphs.inner().clone();
merged_supergraph_config.merge_subgraphs(&supergraph_config);
Some(merged_supergraph_config)
}
None => Some(remote_subgraphs.inner().clone()),
},
None => supergraph_config,
};
let supergraph_config = get_supergraph_config(
&self.opts.supergraph_opts.graph_ref,
&self.opts.supergraph_opts.supergraph_config_path,
&self
.opts
.supergraph_opts
.federation_version
.clone()
.unwrap_or(FederationVersion::LatestFedTwo),
client_config.clone(),
&self.opts.plugin_opts.profile,
)?;

// Build a Rayon Thread pool
let tp = rayon::ThreadPoolBuilder::new()
Expand Down
9 changes: 4 additions & 5 deletions src/command/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use std::net::IpAddr;
use apollo_federation_types::config::FederationVersion;
use camino::Utf8PathBuf;
use clap::Parser;
use rover_client::shared::GraphRef;
use serde::Serialize;

use rover_client::shared::GraphRef;

use crate::options::{OptionalSubgraphOpts, PluginOpts};
use crate::utils::parsers::FileDescriptorType;

#[cfg(feature = "composition-js")]
mod compose;
Expand All @@ -20,9 +22,6 @@ mod introspect;
#[cfg(feature = "composition-js")]
mod protocol;

#[cfg(feature = "composition-js")]
mod remote_subgraphs;

#[cfg(feature = "composition-js")]
mod router;

Expand Down Expand Up @@ -91,7 +90,7 @@ pub struct SupergraphOpts {
long = "supergraph-config",
conflicts_with_all = ["subgraph_name", "subgraph_url", "subgraph_schema_path"]
)]
supergraph_config_path: Option<Utf8PathBuf>,
supergraph_config_path: Option<FileDescriptorType>,

/// A [`GraphRef`] that is accessible in Apollo Studio.
/// This is used to initialize your supergraph with the values contained in this variant.
Expand Down
55 changes: 0 additions & 55 deletions src/command/dev/remote_subgraphs.rs

This file was deleted.

Loading

0 comments on commit eba5e06

Please sign in to comment.