Skip to content
Open
Changes from all commits
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
40 changes: 40 additions & 0 deletions apollo-federation-types/src/config/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub enum SchemaSource {
File {
file: Utf8PathBuf,
},
Remote {
remote_url: Url,
headers: Option<HashMap<String, String>>,
},
SubgraphIntrospection {
subgraph_url: Url,
introspection_headers: Option<HashMap<String, String>>,
Expand All @@ -59,6 +63,7 @@ pub enum SchemaSource {
mod test_schema_source {
use crate::config::SchemaSource;
use serde_yaml::from_str;
use std::collections::HashMap;

#[test]
fn test_file() {
Expand Down Expand Up @@ -115,6 +120,41 @@ subgraph: my-subgraph
assert_eq!(source, expected);
}

#[test]
fn test_remote() {
let yaml = r#"
remote_url: https://example.com/some/schema/v1.0.graphqls
headers:
Authorization: ${env.AUTH_TOKEN}
"#;
let source: SchemaSource = from_str(yaml).unwrap();
let expected = SchemaSource::Remote {
remote_url: "https://example.com/some/schema/v1.0.graphqls"
.parse()
.unwrap(),
headers: Some(HashMap::from([(
"Authorization".to_string(),
"${env.AUTH_TOKEN}".to_string(),
)])),
};
assert_eq!(source, expected);
}

#[test]
fn test_remote_no_headers() {
let yaml = r#"
remote_url: https://example.com/some/schema/v1.0.graphqls
"#;
let source: SchemaSource = from_str(yaml).unwrap();
let expected = SchemaSource::Remote {
remote_url: "https://example.com/some/schema/v1.0.graphqls"
.parse()
.unwrap(),
headers: None,
};
assert_eq!(source, expected);
}

#[test]
fn test_sdl() {
let yaml = r#"
Expand Down