Skip to content

Commit

Permalink
Add a check to ensure correct URL is used if a subgraph_url and a `…
Browse files Browse the repository at this point in the history
…routing_url` are provided in a `supergraph.yml` (#1948)

Fixes #1782
  • Loading branch information
jonathanrainer authored Jun 28, 2024
1 parent 74eb9d7 commit 3bfd3fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
22 changes: 14 additions & 8 deletions src/command/dev/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{net::SocketAddr, time::Duration};
use anyhow::anyhow;
use apollo_federation_types::config::SchemaSource;
use reqwest::Url;

use rover_client::blocking::StudioClient;
use rover_std::Fs;

Expand Down Expand Up @@ -82,11 +83,12 @@ impl OptionalSubgraphOpts {
.with_timeout(Duration::from_secs(5))
.build()?;
SubgraphSchemaWatcher::new_from_url(
(name, url),
(name, url.clone()),
client,
follower_messenger,
self.subgraph_polling_interval,
None,
url,
)
}
}
Expand Down Expand Up @@ -138,13 +140,17 @@ impl SupergraphOpts {
SchemaSource::SubgraphIntrospection {
subgraph_url,
introspection_headers,
} => SubgraphSchemaWatcher::new_from_url(
(yaml_subgraph_name, subgraph_url),
client.clone(),
follower_messenger.clone(),
polling_interval,
introspection_headers,
),
} => {
let url = routing_url.unwrap_or(subgraph_url.clone());
SubgraphSchemaWatcher::new_from_url(
(yaml_subgraph_name, url),
client.clone(),
follower_messenger.clone(),
polling_interval,
introspection_headers,
subgraph_url,
)
}
SchemaSource::Sdl { sdl } => {
let routing_url = routing_url.ok_or_else(|| {
anyhow!("`routing_url` must be set when providing SDL directly")
Expand Down
29 changes: 17 additions & 12 deletions src/command/dev/watcher.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
use crate::{
command::dev::{
introspect::{IntrospectRunnerKind, UnknownIntrospectRunner},
protocol::{FollowerMessenger, SubgraphKey},
},
RoverError, RoverErrorSuggestion, RoverResult,
};
use anyhow::{anyhow, Context};
use std::collections::HashMap;
use std::str::FromStr;

use anyhow::{anyhow, Context};
use apollo_federation_types::build::SubgraphDefinition;
use camino::{Utf8Path, Utf8PathBuf};
use crossbeam_channel::unbounded;
use reqwest::blocking::Client;
use url::Url;

use rover_client::blocking::StudioClient;
use rover_client::operations::subgraph::fetch;
use rover_client::operations::subgraph::fetch::SubgraphFetchInput;
use rover_client::shared::GraphRef;
use rover_std::{Emoji, Fs};
use url::Url;

use crate::{
command::dev::{
introspect::{IntrospectRunnerKind, UnknownIntrospectRunner},
protocol::{FollowerMessenger, SubgraphKey},
},
RoverError, RoverErrorSuggestion, RoverResult,
};

#[derive(Debug)]
pub struct SubgraphSchemaWatcher {
Expand Down Expand Up @@ -49,11 +51,14 @@ impl SubgraphSchemaWatcher {
message_sender: FollowerMessenger,
polling_interval: u64,
headers: Option<HashMap<String, String>>,
subgraph_url: Url,
) -> RoverResult<Self> {
let (_, url) = subgraph_key.clone();
let headers = headers.map(|header_map| header_map.into_iter().collect());
let introspect_runner =
IntrospectRunnerKind::Unknown(UnknownIntrospectRunner::new(url, client, headers));
let introspect_runner = IntrospectRunnerKind::Unknown(UnknownIntrospectRunner::new(
subgraph_url,
client,
headers,
));
Self::new_from_introspect_runner(
subgraph_key,
introspect_runner,
Expand Down

0 comments on commit 3bfd3fc

Please sign in to comment.