Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Update subgraph/merge logic for Name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sachindshinde committed Nov 13, 2023
1 parent d9aba96 commit 9723442
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 320 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(dead_code)] // TODO: This is fine while we're iterating, but should be removed later.
use apollo_compiler::ast::Directives;
use apollo_compiler::ast::DirectiveList;
use apollo_compiler::schema::ExtendedType;
use apollo_compiler::Schema;

Expand Down Expand Up @@ -60,7 +60,7 @@ impl Supergraph {
&& !graphql_type
.directives()
.iter()
.any(|d| d.name.eq("inaccessible"))
.any(|d| d.name == "inaccessible")
});
// remove directive applications
for (_, graphql_type) in api_schema.types.iter_mut() {
Expand Down Expand Up @@ -146,8 +146,8 @@ fn is_join_type(type_name: &str) -> bool {
JOIN_TYPES.contains(&type_name)
}

fn is_inaccessible_applied(directives: &Directives) -> bool {
directives.iter().any(|d| d.name.eq("inaccessible"))
fn is_inaccessible_applied(directives: &DirectiveList) -> bool {
directives.iter().any(|d| d.name == "inaccessible")
}

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion src/link/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ fn parse_link_if_bootstrap_directive(schema: &Schema, directive: &Directive) ->
.and_then(|value| value.as_str())
{
let url = url.parse::<Url>();
let default_link_name = DEFAULT_LINK_NAME;
let expected_name = directive
.argument_by_name("as")
.and_then(|value| value.as_str())
.unwrap_or(DEFAULT_LINK_NAME);
.unwrap_or(default_link_name.as_str());
return url.map_or(false, |url| {
url.identity == Identity::link_identity() && directive.name == expected_name
});
Expand Down
17 changes: 14 additions & 3 deletions src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::link::spec::Identity;
use crate::link::spec::Url;
use crate::link::spec_definition::spec_definitions;
use apollo_compiler::ast::{Directive, Value};
use apollo_compiler::name;
use apollo_compiler::schema::Name;
use std::fmt;
use std::ops::Deref;
use std::str;
Expand All @@ -18,9 +20,9 @@ pub(crate) mod link_spec_definition;
pub mod spec;
pub(crate) mod spec_definition;

pub const DEFAULT_LINK_NAME: &str = "link";
pub const DEFAULT_IMPORT_SCALAR_NAME: &str = "Import";
pub const DEFAULT_PURPOSE_ENUM_NAME: &str = "Purpose";
pub const DEFAULT_LINK_NAME: Name = name!("link");
pub const DEFAULT_IMPORT_SCALAR_NAME: Name = name!("Import");
pub const DEFAULT_PURPOSE_ENUM_NAME: Name = name!("Purpose");

// TODO: we should provide proper "diagnostic" here, linking to ast, accumulating more than one
// error and whatnot.
Expand Down Expand Up @@ -83,6 +85,15 @@ impl fmt::Display for Purpose {
}
}

impl From<&Purpose> for Name {
fn from(value: &Purpose) -> Self {
match value {
Purpose::SECURITY => name!("SECURITY"),
Purpose::EXECUTION => name!("EXECUTION"),
}
}
}

#[derive(Eq, PartialEq, Debug)]
pub struct Import {
/// The name of the element that is being imported.
Expand Down
Loading

0 comments on commit 9723442

Please sign in to comment.