Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changesets/fix_lb_carryover_input_types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Fix directive inputs with `@composeDirective` and Connectors ([PR #7383](https://github.com/apollographql/router/pull/7383))

Prior to this fix, any time a directive added with `@composeDirective` has its own input types (custom scalars, enums, input types) and a Connector is used, those types would be lost and the supergraph would fail to compose.

<!-- https://apollographql.atlassian.net/browse/CNN-755 -->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be here?


By [@lennyburdette](https://github.com/lennyburdette) in https://github.com/apollographql/router/pull/7383
40 changes: 10 additions & 30 deletions apollo-federation/src/sources/connect/expand/carryover.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
mod inputs;

use apollo_compiler::Name;
use apollo_compiler::Node;
use apollo_compiler::ast::Argument;
use apollo_compiler::ast::Directive;
use apollo_compiler::ast::Value;
use apollo_compiler::collections::HashSet;
use apollo_compiler::name;
use inputs::copy_input_types;
use multimap::MultiMap;

use crate::error::FederationError;
use crate::link::DEFAULT_LINK_NAME;
Expand Down Expand Up @@ -45,6 +49,7 @@ pub(super) fn carryover_directives(
from: &FederationSchema,
to: &mut FederationSchema,
specs: impl Iterator<Item = ConnectSpec>,
subgraph_name_replacements: &MultiMap<&str, String>,
) -> Result<(), FederationError> {
let Some(metadata) = from.metadata() else {
return Ok(());
Expand All @@ -61,6 +66,10 @@ pub(super) fn carryover_directives(
SchemaDefinitionPosition.insert_directive(to, link.to_directive_application().into())?;
}

// before copying over directive definitions, we need to ensure we copy over
// any input types (scalars, enums, input objects) they use
copy_input_types(from, to, subgraph_name_replacements)?;

// @inaccessible

if let Some(link) = metadata.for_identity(&Identity::inaccessible_identity()) {
Expand Down Expand Up @@ -136,21 +145,6 @@ pub(super) fn carryover_directives(
SchemaDefinitionPosition
.insert_directive(to, link.to_directive_application().into())?;

let scalar_type_pos = ScalarTypeDefinitionPosition {
type_name: link.type_name_in_schema(&name!(Scope)),
};

// The scalar might already exist if a subgraph defined it
if scalar_type_pos.get(to.schema()).is_err() {
scalar_type_pos
.get(from.schema())
.map_err(From::from)
.and_then(|def| {
scalar_type_pos.pre_insert(to)?;
scalar_type_pos.insert(to, def.clone())
})?;
}

copy_directive_definition(from, to, directive_name.clone())?;
}
referencers.copy_directives(from, to, &directive_name)
Expand All @@ -171,21 +165,6 @@ pub(super) fn carryover_directives(
SchemaDefinitionPosition
.insert_directive(to, link.to_directive_application().into())?;

let scalar_type_pos = ScalarTypeDefinitionPosition {
type_name: link.type_name_in_schema(&name!(Policy)),
};

// The scalar might already exist if a subgraph defined it
if scalar_type_pos.get(to.schema()).is_err() {
scalar_type_pos
.get(from.schema())
.map_err(From::from)
.and_then(|def| {
scalar_type_pos.pre_insert(to)?;
scalar_type_pos.insert(to, def.clone())
})?;
}

copy_directive_definition(from, to, directive_name.clone())?;
}
referencers.copy_directives(from, to, &directive_name)
Expand Down Expand Up @@ -683,6 +662,7 @@ mod tests {
&supergraph_schema,
&mut schema,
[ConnectSpec::V0_1].into_iter(),
&Default::default(),
)
.expect("carryover failed");
assert_snapshot!(schema.schema().serialize().to_string());
Expand Down
Loading