Skip to content

Commit

Permalink
Fixed command targeted relationships not using data connector argumen…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
daniel-chambers authored and hasura-bot committed Jul 17, 2024
1 parent 9f6ac66 commit 455724d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
6 changes: 6 additions & 0 deletions v3/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"name": "get_movie_by_id",
"arguments": [
{
"name": "movie_id",
"name": "id",
"type": "Int!"
}
],
Expand All @@ -231,7 +231,7 @@
"function": "get_movie_by_id"
},
"argumentMapping": {
"movie_id": "movie_id"
"id": "movie_id"
}
},
"graphql": {
Expand All @@ -241,6 +241,8 @@
}
},
{
"kind": "Relationship",
"version": "v1",
"definition": {
"sourceType": "actor",
"name": "MovieFromCommand",
Expand All @@ -260,14 +262,12 @@
},
"target": {
"argument": {
"argumentName": "movie_id"
"argumentName": "id"
}
}
}
]
},
"version": "v1",
"kind": "Relationship"
}
}
]
}
Expand Down
16 changes: 15 additions & 1 deletion v3/crates/execute/src/plan/error.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,

Expand Down
17 changes: 16 additions & 1 deletion v3/crates/execute/src/plan/relationships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 455724d

Please sign in to comment.