Skip to content
Open
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
16 changes: 8 additions & 8 deletions apollo-federation/src/connectors/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,40 +409,40 @@ mod helpers {
// without at least a root-level Query)

let parent_pos = ObjectTypeDefinitionPosition {
type_name: parent_type.name.clone(),
type_name: parent_type.name().clone(),
};

self.insert_object_and_field(&mut schema, &parent_pos, field_def)?;
self.ensure_query_root_type(
&mut schema,
&query_alias,
Some(&parent_type.name),
Some(parent_type.name()),
)?;
if let Some(mutation_alias) = mutation_alias {
self.ensure_mutation_root_type(
&mut schema,
&mutation_alias,
&parent_type.name,
parent_type.name(),
)?;
}

// Process any outputs needed by the connector
self.process_outputs(
&mut schema,
connector,
parent_type.name.clone(),
parent_type.name().clone(),
field_def.ty.inner_named_type().clone(),
)?;
}
ConnectedElement::Type { type_def } => {
ConnectedElement::Type { type_ref } => {
SchemaVisitor::new(
self.original_schema,
&mut schema,
&self.directive_deny_list,
)
.walk((
ObjectTypeDefinitionPosition {
type_name: type_def.name.clone(),
type_name: type_ref.name().clone(),
},
connector
.selection
Expand All @@ -460,8 +460,8 @@ mod helpers {
self.process_outputs(
&mut schema,
connector,
type_def.name.clone(),
type_def.name.clone(),
type_ref.name().clone(),
type_ref.name().clone(),
)?;
}
}
Expand Down
40 changes: 10 additions & 30 deletions apollo-federation/src/connectors/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ use std::fmt::Formatter;
use std::hash::Hash;

use apollo_compiler::Name;
use apollo_compiler::Node;
use apollo_compiler::Schema;
use apollo_compiler::ast::FieldDefinition;
use apollo_compiler::ast::NamedType;
use apollo_compiler::schema::Component;
use apollo_compiler::schema::ExtendedType;
use apollo_compiler::schema::ObjectType;

use crate::connectors::schema_type_ref::SchemaTypeRef;
use crate::error::FederationError;
use crate::schema::position::ObjectOrInterfaceFieldDirectivePosition;

Expand All @@ -37,16 +35,7 @@ impl ConnectorPosition {
) -> Result<ConnectedElement<'s>, FederationError> {
match self {
Self::Field(pos) => Ok(ConnectedElement::Field {
parent_type: schema
.types
.get(pos.field.parent().type_name())
.and_then(|ty| {
if let ExtendedType::Object(obj) = ty {
Some(obj)
} else {
None
}
})
parent_type: SchemaTypeRef::new(schema, pos.field.parent().type_name())
.ok_or_else(|| {
FederationError::internal("Parent type for connector not found")
})?,
Expand All @@ -62,16 +51,7 @@ impl ConnectorPosition {
},
}),
Self::Type(pos) => Ok(ConnectedElement::Type {
type_def: schema
.types
.get(&pos.type_name)
.and_then(|ty| {
if let ExtendedType::Object(obj) = ty {
Some(obj)
} else {
None
}
})
type_ref: SchemaTypeRef::new(schema, &pos.type_name)
.ok_or_else(|| FederationError::internal("Type for connector not found"))?,
}),
}
Expand Down Expand Up @@ -173,20 +153,20 @@ impl ConnectorPosition {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ConnectedElement<'schema> {
Field {
parent_type: &'schema Node<ObjectType>,
parent_type: SchemaTypeRef<'schema>,
field_def: &'schema Component<FieldDefinition>,
parent_category: ObjectCategory,
},
Type {
type_def: &'schema Node<ObjectType>,
type_ref: SchemaTypeRef<'schema>,
},
}

impl ConnectedElement<'_> {
pub(super) fn base_type_name(&self) -> NamedType {
match self {
ConnectedElement::Field { field_def, .. } => field_def.ty.inner_named_type().clone(),
ConnectedElement::Type { type_def } => type_def.name.clone(),
ConnectedElement::Type { type_ref } => type_ref.name().clone(),
}
}

Expand All @@ -201,7 +181,7 @@ impl ConnectedElement<'_> {
.as_ref()
.is_some_and(|query| match self {
ConnectedElement::Field { .. } => false,
ConnectedElement::Type { type_def } => type_def.name == query.name,
ConnectedElement::Type { type_ref } => type_ref.name() == query.name.as_str(),
})
}

Expand All @@ -212,7 +192,7 @@ impl ConnectedElement<'_> {
.as_ref()
.is_some_and(|mutation| match self {
ConnectedElement::Field { .. } => false,
ConnectedElement::Type { type_def } => type_def.name == mutation.name,
ConnectedElement::Type { type_ref } => type_ref.name() == mutation.name.as_str(),
})
}
}
Expand All @@ -231,8 +211,8 @@ impl Display for ConnectedElement<'_> {
parent_type,
field_def,
..
} => write!(f, "{}.{}", parent_type.name, field_def.name),
Self::Type { type_def } => write!(f, "{}", type_def.name),
} => write!(f, "{}.{}", parent_type.name(), field_def.name),
Self::Type { type_ref } => write!(f, "{}", type_ref.name()),
}
}
}
1 change: 1 addition & 0 deletions apollo-federation/src/connectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod header;
mod id;
mod json_selection;
mod models;
mod schema_type_ref;
pub use models::ProblemLocation;
pub mod runtime;
pub(crate) mod spec;
Expand Down
Loading