From 3bfd3fc1ec6ce2b11f9dc98c6158430aea5fb95a Mon Sep 17 00:00:00 2001 From: Jonathan Rainer Date: Fri, 28 Jun 2024 13:35:24 +0100 Subject: [PATCH] Add a check to ensure correct URL is used if a `subgraph_url` and a `routing_url` are provided in a `supergraph.yml` (#1948) Fixes #1782 --- src/command/dev/schema.rs | 22 ++++++++++++++-------- src/command/dev/watcher.rs | 29 +++++++++++++++++------------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/command/dev/schema.rs b/src/command/dev/schema.rs index 3396f46ac..0393e6026 100644 --- a/src/command/dev/schema.rs +++ b/src/command/dev/schema.rs @@ -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; @@ -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, ) } } @@ -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") diff --git a/src/command/dev/watcher.rs b/src/command/dev/watcher.rs index f5e8fad70..a1724603a 100644 --- a/src/command/dev/watcher.rs +++ b/src/command/dev/watcher.rs @@ -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 { @@ -49,11 +51,14 @@ impl SubgraphSchemaWatcher { message_sender: FollowerMessenger, polling_interval: u64, headers: Option>, + subgraph_url: Url, ) -> RoverResult { - 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,