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

Reporting followups #1020

Merged
merged 22 commits into from May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion apollo-router-core/src/spec/schema.rs
Expand Up @@ -5,6 +5,8 @@ use apollo_parser::ast;
use http::Uri;
use itertools::Itertools;
use router_bridge::api_schema;
use sha2::Digest;
use sha2::Sha256;
use std::collections::{HashMap, HashSet};

/// A GraphQL schema.
Expand All @@ -19,6 +21,7 @@ pub struct Schema {
pub(crate) custom_scalars: HashSet<String>,
pub(crate) enums: HashMap<String, HashSet<String>>,
api_schema: Option<Box<Schema>>,
pub schema_id: Option<String>,
}

impl std::str::FromStr for Schema {
Expand Down Expand Up @@ -366,6 +369,10 @@ impl std::str::FromStr for Schema {
})
.collect();

let mut hasher = Sha256::new();
hasher.update(schema.as_bytes());
let schema_id = Some(format!("{:x}", hasher.finalize()));

Ok(Schema {
subtype_map,
string: schema.to_owned(),
Expand All @@ -376,6 +383,7 @@ impl std::str::FromStr for Schema {
custom_scalars,
enums,
api_schema: None,
schema_id,
})
}
}
Expand Down Expand Up @@ -692,7 +700,6 @@ mod tests {
.parse()
.unwrap();

println!("subgraphs: {:?}", schema.subgraphs);
assert_eq!(schema.subgraphs.len(), 4);
assert_eq!(
schema
Expand Down Expand Up @@ -750,6 +757,23 @@ mod tests {
.is_none());
}

#[test]
fn schema_id() {
let schema = Schema::from_str(include_str!("../testdata/contract_schema.graphql")).unwrap();

// Line endings affect the schema hash.
#[cfg(windows)]
assert_eq!(
schema.schema_id,
Some("c081a7ff570f630bdf22cb6ca73a2bb1d46657ef69fc66749f5a1f99332b5ecb".to_string())
);
#[cfg(not(windows))]
assert_eq!(
schema.schema_id,
Some("6881633761291f4a6e4f9a4a6bbe7ad69a80c63ebebfc357464b7a6ef276ef0a".to_string())
);
}

// test for https://github.com/apollographql/federation/pull/1769
#[test]
fn inaccessible_on_non_core() {
Expand Down
7 changes: 7 additions & 0 deletions apollo-router/Cargo.toml
Expand Up @@ -76,6 +76,7 @@ serde = { version = "1.0.136", features = ["derive", "rc"] }
serde_json_bytes = { version = "0.2.0", features = ["preserve_order"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde_yaml = "0.8.24"
sys-info = "0.9.1"
thiserror = "1.0.30"
tokio = { version = "1.17.0", features = ["full"] }
tokio-util = { version = "0.7.1", features = ["net", "codec"] }
Expand All @@ -95,6 +96,12 @@ rhai = { version = "1.7.0", features = ["sync", "serde", "internals"] }
libc = "0.2.125"
yaml-rust = "0.4.5"

[target.'cfg(macos)'.dependencies]
uname = "0.1.1"

[target.'cfg(unix)'.dependencies]
uname = "0.1.1"

[dev-dependencies]
insta = "1.12.0"
jsonpath_lib = "0.3.0"
Expand Down
6 changes: 6 additions & 0 deletions apollo-router/src/plugins/telemetry/apollo.rs
Expand Up @@ -32,6 +32,11 @@ pub struct Config {
default = "client_version_header_default"
)]
pub client_version_header: HeaderName,

// This'll get overridden if a user tries to set it.
// The purpose is to allow is to pass this in to the plugin.
#[schemars(skip)]
pub(crate) schema_id: String,
}

fn apollo_key_env_str() -> Option<String> {
Expand Down Expand Up @@ -74,6 +79,7 @@ impl Default for Config {
apollo_graph_ref: None,
client_name_header: client_name_header_default(),
client_version_header: client_version_header_default(),
schema_id: "<no_schema_id>".to_string(),
}
}
}