diff --git a/changelog.md b/changelog.md index 0be9bae67..7b4cc1668 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,9 @@ ### Fixed +- Fix schema conflict result_type for native query mutations. + ([#405](https://github.com/hasura/ndc-postgres/pull/405)) + ## [v0.5.2] - 2024-03-29 ### Added diff --git a/crates/connectors/ndc-postgres/src/schema.rs b/crates/connectors/ndc-postgres/src/schema.rs index e96989fc3..f1e924539 100644 --- a/crates/connectors/ndc-postgres/src/schema.rs +++ b/crates/connectors/ndc-postgres/src/schema.rs @@ -268,25 +268,29 @@ pub async fn get_schema( .0 .iter() .filter(|(_, nq_info)| nq_info.is_procedure) - .map(|(nq_name, nq_info)| models::ProcedureInfo { - name: nq_name.clone(), - description: nq_info.description.clone(), - arguments: nq_info - .arguments - .iter() - .map(|(column_name, column_info)| { - ( - column_name.clone(), - models::ArgumentInfo { - description: column_info.description.clone(), - argument_type: readonly_column_to_type(column_info), - }, - ) - }) - .collect(), - result_type: models::Type::Named { - name: nq_name.clone(), - }, + .map(|(nq_name, nq_info)| { + make_procedure_type( + nq_name.clone(), + nq_info.description.clone(), + nq_info + .arguments + .iter() + .map(|(column_name, column_info)| { + ( + column_name.clone(), + models::ArgumentInfo { + description: column_info.description.clone(), + argument_type: readonly_column_to_type(column_info), + }, + ) + }) + .collect(), + models::Type::Named { + name: nq_name.clone(), + }, + &mut object_types, + &mut scalar_types, + ) }) .collect(); @@ -566,7 +570,6 @@ fn make_procedure_type( description: Option, arguments: BTreeMap, result_type: models::Type, - object_types: &mut BTreeMap, scalar_types: &mut BTreeMap, ) -> models::ProcedureInfo { diff --git a/crates/tests/databases-tests/src/citus/snapshots/databases_tests__citus__schema_tests__schema_test__get_schema.snap b/crates/tests/databases-tests/src/citus/snapshots/databases_tests__citus__schema_tests__schema_test__get_schema.snap index 07daaad00..2994356e8 100644 --- a/crates/tests/databases-tests/src/citus/snapshots/databases_tests__citus__schema_tests__schema_test__get_schema.snap +++ b/crates/tests/databases-tests/src/citus/snapshots/databases_tests__citus__schema_tests__schema_test__get_schema.snap @@ -2899,6 +2899,28 @@ expression: result } } }, + "delete_playlist_track_response": { + "description": "Responses from the 'delete_playlist_track' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "delete_playlist_track" + } + } + } + } + }, "discoverable_types": { "fields": { "only_occurring_here1": { @@ -2963,6 +2985,28 @@ expression: result } } }, + "insert_album_response": { + "description": "Responses from the 'insert_album' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "insert_album" + } + } + } + } + }, "insert_artist": { "fields": { "ArtistId": { @@ -2985,6 +3029,28 @@ expression: result } } }, + "insert_artist_response": { + "description": "Responses from the 'insert_artist' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "insert_artist" + } + } + } + } + }, "make_person": { "description": "A native query used to test support for composite types", "fields": { @@ -4976,7 +5042,7 @@ expression: result }, "result_type": { "type": "named", - "name": "delete_playlist_track" + "name": "delete_playlist_track_response" } }, { @@ -5012,7 +5078,7 @@ expression: result }, "result_type": { "type": "named", - "name": "insert_album" + "name": "insert_album_response" } }, { @@ -5039,7 +5105,7 @@ expression: result }, "result_type": { "type": "named", - "name": "insert_artist" + "name": "insert_artist_response" } }, { diff --git a/crates/tests/databases-tests/src/cockroach/snapshots/databases_tests__cockroach__schema_tests__schema_test__get_schema.snap b/crates/tests/databases-tests/src/cockroach/snapshots/databases_tests__cockroach__schema_tests__schema_test__get_schema.snap index fc38b65e2..e50a28845 100644 --- a/crates/tests/databases-tests/src/cockroach/snapshots/databases_tests__cockroach__schema_tests__schema_test__get_schema.snap +++ b/crates/tests/databases-tests/src/cockroach/snapshots/databases_tests__cockroach__schema_tests__schema_test__get_schema.snap @@ -2398,6 +2398,28 @@ expression: result } } }, + "delete_playlist_track_response": { + "description": "Responses from the 'delete_playlist_track' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "delete_playlist_track" + } + } + } + } + }, "discoverable_types_root_occurrence": { "fields": { "col": { @@ -2448,6 +2470,28 @@ expression: result } } }, + "insert_album_response": { + "description": "Responses from the 'insert_album' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "insert_album" + } + } + } + } + }, "insert_artist": { "fields": { "ArtistId": { @@ -2470,6 +2514,28 @@ expression: result } } }, + "insert_artist_response": { + "description": "Responses from the 'insert_artist' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "insert_artist" + } + } + } + } + }, "pg_extension_spatial_ref_sys": { "description": "Shows all defined Spatial Reference Identifiers (SRIDs). Matches PostGIS' spatial_ref_sys table.", "fields": { @@ -4421,7 +4487,7 @@ expression: result }, "result_type": { "type": "named", - "name": "delete_playlist_track" + "name": "delete_playlist_track_response" } }, { @@ -4457,7 +4523,7 @@ expression: result }, "result_type": { "type": "named", - "name": "insert_album" + "name": "insert_album_response" } }, { @@ -4484,7 +4550,7 @@ expression: result }, "result_type": { "type": "named", - "name": "insert_artist" + "name": "insert_artist_response" } }, { diff --git a/crates/tests/databases-tests/src/postgres/snapshots/databases_tests__postgres__schema_tests__schema_test__get_schema.snap b/crates/tests/databases-tests/src/postgres/snapshots/databases_tests__postgres__schema_tests__schema_test__get_schema.snap index 2f779bd75..df4e7c728 100644 --- a/crates/tests/databases-tests/src/postgres/snapshots/databases_tests__postgres__schema_tests__schema_test__get_schema.snap +++ b/crates/tests/databases-tests/src/postgres/snapshots/databases_tests__postgres__schema_tests__schema_test__get_schema.snap @@ -3085,6 +3085,28 @@ expression: result } } }, + "delete_playlist_track_response": { + "description": "Responses from the 'delete_playlist_track' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "delete_playlist_track" + } + } + } + } + }, "discoverable_types": { "fields": { "only_occurring_here1": { @@ -3457,6 +3479,28 @@ expression: result } } }, + "insert_album_response": { + "description": "Responses from the 'insert_album' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "insert_album" + } + } + } + } + }, "insert_artist": { "fields": { "ArtistId": { @@ -3479,6 +3523,28 @@ expression: result } } }, + "insert_artist_response": { + "description": "Responses from the 'insert_artist' procedure", + "fields": { + "affected_rows": { + "description": "The number of rows affected by the mutation", + "type": { + "type": "named", + "name": "int4" + } + }, + "returning": { + "description": "Data from rows affected by the mutation", + "type": { + "type": "array", + "element_type": { + "type": "named", + "name": "insert_artist" + } + } + } + } + }, "make_person": { "description": "A native query used to test support for composite types", "fields": { @@ -5711,7 +5777,7 @@ expression: result }, "result_type": { "type": "named", - "name": "delete_playlist_track" + "name": "delete_playlist_track_response" } }, { @@ -5747,7 +5813,7 @@ expression: result }, "result_type": { "type": "named", - "name": "insert_album" + "name": "insert_album_response" } }, { @@ -5774,7 +5840,7 @@ expression: result }, "result_type": { "type": "named", - "name": "insert_artist" + "name": "insert_artist_response" } }, {