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 6 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
18 changes: 17 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,15 @@ mod tests {
.is_none());
}

#[test]
fn schema_id() {
let schema = Schema::from_str(include_str!("../testdata/contract_schema.graphql")).unwrap();
assert_eq!(
schema.schema_id,
Some("6881633761291F4A6E4F9A4A6BBE7AD69A80C63EBEBFC357464B7A6EF276EF0A".to_string())
BrynCooke marked this conversation as resolved.
Show resolved Hide resolved
);
}

// test for https://github.com/apollographql/federation/pull/1769
#[test]
fn inaccessible_on_non_core() {
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: Option<String>,
BrynCooke marked this conversation as resolved.
Show resolved Hide resolved
}

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: None,
BrynCooke marked this conversation as resolved.
Show resolved Hide resolved
}
}
}