Fixed command targeted relationships not using data connector argument names (#841)

### What
This PR fixes an issue where relationships that target commands do not
correctly use the data connector's argument name when making the ndc
request. Instead, they use the OpenDD argument name, which is incorrect.

For metadata where the OpenDD argument name is the same as the data
connector's argument name, the code works but only coincidentally.

### How
I've updated an existing test to change the name of the command argument
to be different from the data connector's argument name. This test
failed but is now fixed by this PR, which simply looks up the name of
the data connector argument name and uses that instead.

V3_GIT_ORIGIN_REV_ID: 71f1e812174c7bb9922792523129e4bcdce911ed
This commit is contained in:
Daniel Chambers 2024-07-17 18:36:30 +10:00 committed by hasura-bot
parent 9f6ac66746
commit 455724dd07
4 changed files with 43 additions and 8 deletions

View File

@ -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

View File

@ -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"
}
}
]
}

View File

@ -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<CustomTypeName>,
relationship_name: RelationshipName,
command_name: Qualified<CommandName>,
argument_name: ArgumentName,
},
#[error("remote relationships should have been handled separately")]
RemoteRelationshipsAreNotSupported,

View File

@ -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()