mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
Remove panic in type mappings, allow arrays in command return types (#1425)
<!-- The PR description should answer 2 important questions: --> ### What When an array return type was used in a command that we using in type mappings we panicked, however this should be allowed. Return a proper error if a Predicate is used as a command return type though, as that is not allowed. This fixes the immediate error in the ticket, but the reproducer throws another one - I think this is because the reproduction is so minimal though. Worth testing with the full reproduction before merging @jberryman . V3_GIT_ORIGIN_REV_ID: ae0a2f0a6fe83c82e5ab01adaba9b317743688ba
This commit is contained in:
parent
a205dc80ab
commit
38595d0536
@ -6,6 +6,9 @@
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed a bug where commands with array return types would not build when header
|
||||
forwarding was in effect.
|
||||
|
||||
- GraphQL queries with `order_by` arguments that contain multiple properties set
|
||||
on one input object now properly return an error. For example
|
||||
`order_by: { location: { city: Asc, country: Asc } }` is no longer allowed.
|
||||
|
@ -38,6 +38,10 @@ pub enum TypeMappingCollectionError {
|
||||
data_connector: Qualified<DataConnectorName>,
|
||||
ndc_type_name: DataConnectorObjectType,
|
||||
},
|
||||
|
||||
#[error("Cannot return a predicate type from a command")]
|
||||
PredicateAsResponseType,
|
||||
|
||||
#[error("Internal Error: Unknown type {type_name:} when collecting type mappings")]
|
||||
InternalUnknownType {
|
||||
type_name: Qualified<CustomTypeName>,
|
||||
@ -176,7 +180,10 @@ fn handle_special_case_type_mapping<'a>(
|
||||
.get(response_config.result_field.as_str())
|
||||
.unwrap()
|
||||
.r#type;
|
||||
let ndc_object_type_name = unwrap_ndc_object_type_name(ndc_object_type);
|
||||
|
||||
// get the type found in `response` field, and look up it's type mappings too
|
||||
let ndc_object_type_name = unwrap_ndc_object_type_name(ndc_object_type)?;
|
||||
|
||||
object_type_representation
|
||||
.type_mappings
|
||||
.get(data_connector_name, ndc_object_type_name.as_str())
|
||||
@ -207,14 +214,17 @@ fn handle_special_case_type_mapping<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
fn unwrap_ndc_object_type_name(ndc_type: &ndc_models::Type) -> &ndc_models::TypeName {
|
||||
fn unwrap_ndc_object_type_name(
|
||||
ndc_type: &ndc_models::Type,
|
||||
) -> Result<&ndc_models::TypeName, TypeMappingCollectionError> {
|
||||
match ndc_type {
|
||||
ndc_models::Type::Named { name } => name,
|
||||
ndc_models::Type::Named { name } => Ok(name),
|
||||
ndc_models::Type::Nullable { underlying_type } => {
|
||||
unwrap_ndc_object_type_name(underlying_type)
|
||||
}
|
||||
ndc_models::Type::Array { .. } | ndc_models::Type::Predicate { .. } => {
|
||||
panic!("unexpected ndc type; only object is supported")
|
||||
ndc_models::Type::Array { element_type } => unwrap_ndc_object_type_name(element_type),
|
||||
ndc_models::Type::Predicate { .. } => {
|
||||
Err(TypeMappingCollectionError::PredicateAsResponseType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user