diff --git a/v3/changelog.md b/v3/changelog.md index c8326e0da43a1..1054d00e6a6ba 100644 --- a/v3/changelog.md +++ b/v3/changelog.md @@ -2,6 +2,12 @@ ## [Unreleased] +### Fixed + +- Fixed a bug where command targeted relationships were not using the Open DD + argument name instead of the data connector's argument name when querying the + data connector + ## [v2024.07.10] ### Fixed diff --git a/v3/crates/engine/tests/execute/relationships/model_to_command/metadata.json b/v3/crates/engine/tests/execute/relationships/model_to_command/metadata.json index 788ca8267d90d..cecf3320c58dc 100644 --- a/v3/crates/engine/tests/execute/relationships/model_to_command/metadata.json +++ b/v3/crates/engine/tests/execute/relationships/model_to_command/metadata.json @@ -220,7 +220,7 @@ "name": "get_movie_by_id", "arguments": [ { - "name": "movie_id", + "name": "id", "type": "Int!" } ], @@ -231,7 +231,7 @@ "function": "get_movie_by_id" }, "argumentMapping": { - "movie_id": "movie_id" + "id": "movie_id" } }, "graphql": { @@ -241,6 +241,8 @@ } }, { + "kind": "Relationship", + "version": "v1", "definition": { "sourceType": "actor", "name": "MovieFromCommand", @@ -260,14 +262,12 @@ }, "target": { "argument": { - "argumentName": "movie_id" + "argumentName": "id" } } } ] - }, - "version": "v1", - "kind": "Relationship" + } } ] } diff --git a/v3/crates/execute/src/plan/error.rs b/v3/crates/execute/src/plan/error.rs index 85897db8a88a4..1325641f71c69 100644 --- a/v3/crates/execute/src/plan/error.rs +++ b/v3/crates/execute/src/plan/error.rs @@ -1,4 +1,10 @@ -use open_dds::{relationships::RelationshipName, types::FieldName}; +use metadata_resolve::Qualified; +use open_dds::{ + arguments::ArgumentName, + commands::CommandName, + relationships::RelationshipName, + types::{CustomTypeName, FieldName}, +}; use tracing_util::TraceableError; use crate::ndc; @@ -25,6 +31,14 @@ pub enum InternalError { relationship_name: RelationshipName, }, + #[error("Missing argument mapping to command {command_name} data connector source for argument {argument_name} used in relationship {relationship_name} on type {source_type}")] + MissingArgumentMappingInCommandRelationship { + source_type: Qualified, + relationship_name: RelationshipName, + command_name: Qualified, + argument_name: ArgumentName, + }, + #[error("remote relationships should have been handled separately")] RemoteRelationshipsAreNotSupported, diff --git a/v3/crates/execute/src/plan/relationships.rs b/v3/crates/execute/src/plan/relationships.rs index 2dc19ff72f25d..0cd8b96ebd7aa 100644 --- a/v3/crates/execute/src/plan/relationships.rs +++ b/v3/crates/execute/src/plan/relationships.rs @@ -190,9 +190,24 @@ pub(crate) fn process_command_relationship_definition( name: ndc_models::FieldName::from(source_column.column.as_str()), }; + let connector_argument_name = target_source + .details + .argument_mappings + .get(target_argument) + .ok_or_else(|| { + error::Error::Internal( + error::InternalError::MissingArgumentMappingInCommandRelationship { + source_type: annotation.source_type.clone(), + relationship_name: annotation.relationship_name.clone(), + command_name: annotation.command_name.clone(), + argument_name: target_argument.clone(), + }, + ) + })?; + if arguments .insert( - ndc_models::ArgumentName::from(target_argument.as_str()), + ndc_models::ArgumentName::from(connector_argument_name.as_str()), relationship_argument, ) .is_some()