From e9cdd4d0f2e295f393330c3c308c0da8783b912a Mon Sep 17 00:00:00 2001 From: benoit Date: Sun, 2 Feb 2025 07:35:16 +0000 Subject: [PATCH] add test for returning object relationship after insert --- .../configuration.json | 379 ++++++++++++++++++ .../request.json | 72 ++++ ..._v2_insert_return_object_relationship.snap | 85 ++++ .../query-engine/translation/tests/tests.rs | 11 + 4 files changed, 547 insertions(+) create mode 100644 crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/configuration.json create mode 100644 crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/request.json create mode 100644 crates/query-engine/translation/tests/snapshots/tests__mutations__v2_insert_return_object_relationship.snap diff --git a/crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/configuration.json b/crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/configuration.json new file mode 100644 index 00000000..920a6f01 --- /dev/null +++ b/crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/configuration.json @@ -0,0 +1,379 @@ +{ + "version": "5", + "$schema": "../../../../../../../static/configuration.schema.json", + "connectionSettings": { + "connectionUri": { + "variable": "CONNECTION_URI" + }, + "poolSettings": { + "maxConnections": 50, + "poolTimeout": 30, + "idleTimeout": 180, + "checkConnectionAfterIdle": 60, + "connectionLifetime": 600 + }, + "isolationLevel": "ReadCommitted" + }, + "metadata": { + "tables": { + "Album": { + "schemaName": "public", + "tableName": "Album", + "columns": { + "AlbumId": { + "name": "AlbumId", + "type": { + "scalarType": "int4" + }, + "nullable": "nullable", + "description": null + }, + "ArtistId": { + "name": "ArtistId", + "type": { + "scalarType": "int4" + }, + "nullable": "nullable", + "description": null + }, + "Title": { + "name": "Title", + "type": { + "scalarType": "varchar" + }, + "nullable": "nullable", + "description": null + } + }, + "uniquenessConstraints": {}, + "foreignRelations": {}, + "description": null + }, + "Artist": { + "schemaName": "public", + "tableName": "Artist", + "columns": { + "ArtistId": { + "name": "ArtistId", + "type": { + "scalarType": "int4" + }, + "nullable": "nullable", + "description": null + }, + "Name": { + "name": "Name", + "type": { + "scalarType": "varchar" + }, + "nullable": "nullable", + "description": null + } + }, + "uniquenessConstraints": {}, + "foreignRelations": {}, + "description": null + } + }, + "types": { + "scalar": { + "int4": { + "typeName": "int4", + "schemaName": "pg_catalog", + "description": null, + "aggregateFunctions": {}, + "comparisonOperators": {}, + "typeRepresentation": "int32" + }, + "varchar": { + "typeName": "varchar", + "schemaName": "pg_catalog", + "description": null, + "aggregateFunctions": {}, + "comparisonOperators": {}, + "typeRepresentation": "string" + } + }, + "composite": {} + }, + "nativeOperations": { + "queries": {}, + "mutations": {} + } + }, + "introspectionOptions": { + "excludedSchemas": [ + "information_schema", + "pg_catalog", + "tiger", + "crdb_internal", + "columnar", + "columnar_internal" + ], + "unqualifiedSchemasForTables": [ + "public" + ], + "unqualifiedSchemasForTypesAndProcedures": [ + "public", + "pg_catalog", + "tiger" + ], + "comparisonOperatorMapping": [ + { + "operatorName": "=", + "exposedName": "_eq", + "operatorKind": "equal" + }, + { + "operatorName": "<=", + "exposedName": "_lte", + "operatorKind": "custom" + }, + { + "operatorName": ">", + "exposedName": "_gt", + "operatorKind": "custom" + }, + { + "operatorName": ">=", + "exposedName": "_gte", + "operatorKind": "custom" + }, + { + "operatorName": "<", + "exposedName": "_lt", + "operatorKind": "custom" + }, + { + "operatorName": "<>", + "exposedName": "_neq", + "operatorKind": "custom" + }, + { + "operatorName": "!=", + "exposedName": "_neq", + "operatorKind": "custom" + }, + { + "operatorName": "LIKE", + "exposedName": "_like", + "operatorKind": "custom" + }, + { + "operatorName": "NOT LIKE", + "exposedName": "_nlike", + "operatorKind": "custom" + }, + { + "operatorName": "ILIKE", + "exposedName": "_ilike", + "operatorKind": "custom" + }, + { + "operatorName": "NOT ILIKE", + "exposedName": "_nilike", + "operatorKind": "custom" + }, + { + "operatorName": "SIMILAR TO", + "exposedName": "_similar", + "operatorKind": "custom" + }, + { + "operatorName": "NOT SIMILAR TO", + "exposedName": "_nsimilar", + "operatorKind": "custom" + }, + { + "operatorName": "~~", + "exposedName": "_like", + "operatorKind": "custom" + }, + { + "operatorName": "!~~", + "exposedName": "_nlike", + "operatorKind": "custom" + }, + { + "operatorName": "~~*", + "exposedName": "_ilike", + "operatorKind": "custom" + }, + { + "operatorName": "!~~*", + "exposedName": "_nilike", + "operatorKind": "custom" + }, + { + "operatorName": "~", + "exposedName": "_regex", + "operatorKind": "custom" + }, + { + "operatorName": "!~", + "exposedName": "_nregex", + "operatorKind": "custom" + }, + { + "operatorName": "~*", + "exposedName": "_iregex", + "operatorKind": "custom" + }, + { + "operatorName": "!~*", + "exposedName": "_niregex", + "operatorKind": "custom" + } + ], + "introspectPrefixFunctionComparisonOperators": [ + "box_above", + "box_below", + "box_contain", + "box_contain_pt", + "box_contained", + "box_left", + "box_overabove", + "box_overbelow", + "box_overlap", + "box_overleft", + "box_overright", + "box_right", + "box_same", + "circle_above", + "circle_below", + "circle_contain", + "circle_contain_pt", + "circle_contained", + "circle_left", + "circle_overabove", + "circle_overbelow", + "circle_overlap", + "circle_overleft", + "circle_overright", + "circle_right", + "circle_same", + "contains_2d", + "equals", + "geography_overlaps", + "geometry_above", + "geometry_below", + "geometry_contained_3d", + "geometry_contains", + "geometry_contains_3d", + "geometry_contains_nd", + "geometry_left", + "geometry_overabove", + "geometry_overbelow", + "geometry_overlaps", + "geometry_overlaps_3d", + "geometry_overlaps_nd", + "geometry_overleft", + "geometry_overright", + "geometry_right", + "geometry_same", + "geometry_same_3d", + "geometry_same_nd", + "geometry_within", + "geometry_within_nd", + "inet_same_family", + "inter_lb", + "inter_sb", + "inter_sl", + "is_contained_2d", + "ishorizontal", + "isparallel", + "isperp", + "isvertical", + "jsonb_contained", + "jsonb_contains", + "jsonb_exists", + "jsonb_path_exists_opr", + "jsonb_path_match_opr", + "line_intersect", + "line_parallel", + "line_perp", + "lseg_intersect", + "lseg_parallel", + "lseg_perp", + "network_overlap", + "network_sub", + "network_sup", + "on_pb", + "on_pl", + "on_ppath", + "on_ps", + "on_sb", + "on_sl", + "overlaps_2d", + "path_contain_pt", + "path_inter", + "point_above", + "point_below", + "point_horiz", + "point_left", + "point_right", + "point_vert", + "poly_above", + "poly_below", + "poly_contain", + "poly_contain_pt", + "poly_contained", + "poly_left", + "poly_overabove", + "poly_overbelow", + "poly_overlap", + "poly_overleft", + "poly_overright", + "poly_right", + "poly_same", + "pt_contained_poly", + "st_3dintersects", + "st_contains", + "st_containsproperly", + "st_coveredby", + "st_covers", + "st_crosses", + "st_disjoint", + "st_equals", + "st_intersects", + "st_isvalid", + "st_orderingequals", + "st_overlaps", + "st_relatematch", + "st_touches", + "st_within", + "starts_with", + "ts_match_qv", + "ts_match_tq", + "ts_match_tt", + "ts_match_vq", + "tsq_mcontained", + "tsq_mcontains", + "xmlexists", + "xmlvalidate", + "xpath_exists" + ], + "typeRepresentations": { + "bit": "string", + "bool": "boolean", + "bpchar": "string", + "char": "string", + "date": "date", + "float4": "float32", + "float8": "float64", + "int2": "int16", + "int4": "int32", + "int8": "int64AsString", + "numeric": "bigDecimalAsString", + "text": "string", + "time": "time", + "timestamp": "timestamp", + "timestamptz": "timestamptz", + "timetz": "timetz", + "uuid": "uUID", + "varchar": "string" + } + }, + "mutationsVersion": "v2", + "mutationsPrefix": null +} \ No newline at end of file diff --git a/crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/request.json b/crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/request.json new file mode 100644 index 00000000..d641ac58 --- /dev/null +++ b/crates/query-engine/translation/tests/goldenfiles/mutations/v2_insert_return_object_relationship/request.json @@ -0,0 +1,72 @@ +{ + "$schema": "../../../../../../../static/mutation.schema.json", + "operations": [ + { + "type": "procedure", + "name": "v2_insert_Album", + "arguments": { + "objects": [ + { + "ArtistId": 276, + "AlbumId": 348, + "Title": "Lake Mannion" + } + ], + "post_check": { + "type": "or", + "expressions": [] + } + }, + "fields": { + "type": "object", + "fields": { + "affected_rows": { + "column": "affected_rows", + "type": "column" + }, + "returning": { + "type": "column", + "column": "returning", + "fields": { + "type": "array", + "fields": { + "type": "object", + "fields": { + "Title": { + "type": "column", + "column": "Title" + }, + "Artist": { + "type": "relationship", + "arguments": {}, + "relationship": "Album_Artist", + "query": { + "fields": { + "Name": { + "type": "column", + "column": "Name" + } + } + } + } + } + } + } + } + } + } + } + ], + "collection_relationships": { + "Album_Artist": { + "arguments": {}, + "column_mapping": { + "ArtistId": [ + "ArtistId" + ] + }, + "relationship_type": "object", + "target_collection": "Artist" + } + } +} \ No newline at end of file diff --git a/crates/query-engine/translation/tests/snapshots/tests__mutations__v2_insert_return_object_relationship.snap b/crates/query-engine/translation/tests/snapshots/tests__mutations__v2_insert_return_object_relationship.snap new file mode 100644 index 00000000..845fce96 --- /dev/null +++ b/crates/query-engine/translation/tests/snapshots/tests__mutations__v2_insert_return_object_relationship.snap @@ -0,0 +1,85 @@ +--- +source: crates/query-engine/translation/tests/tests.rs +expression: result +snapshot_kind: text +--- +BEGIN +ISOLATION LEVEL READ COMMITTED READ WRITE; + +WITH "%0_generated_mutation" AS ( + INSERT INTO + "public"."Album"("AlbumId", "ArtistId", "Title") + VALUES + (348, 276, cast($1 as "pg_catalog"."varchar")) RETURNING *, + false AS "%check__constraint" +) +SELECT + ( + SELECT + json_build_object('result', row_to_json("%8_universe"), 'type', $2) AS "universe" + FROM + ( + SELECT + * + FROM + ( + SELECT + coalesce(json_agg(row_to_json("%9_returning")), '[]') AS "returning" + FROM + ( + SELECT + "%1_Album"."Title" AS "Title", + "%2_RELATIONSHIP_Artist"."Artist" AS "Artist" + FROM + "%0_generated_mutation" AS "%1_Album" + LEFT OUTER JOIN LATERAL ( + SELECT + row_to_json("%2_RELATIONSHIP_Artist") AS "Artist" + FROM + ( + SELECT + * + FROM + ( + SELECT + coalesce(json_agg(row_to_json("%4_rows")), '[]') AS "rows" + FROM + ( + SELECT + "%3_Artist"."Name" AS "Name" + FROM + "public"."Artist" AS "%3_Artist" + WHERE + ("%1_Album"."ArtistId" = "%3_Artist"."ArtistId") + ) AS "%4_rows" + ) AS "%4_rows" + ) AS "%2_RELATIONSHIP_Artist" + ) AS "%2_RELATIONSHIP_Artist" ON ('true') + ) AS "%9_returning" + ) AS "%9_returning" + CROSS JOIN ( + SELECT + COUNT(*) AS "affected_rows" + FROM + ( + SELECT + "%6_Album".* + FROM + "%0_generated_mutation" AS "%6_Album" + ) AS "%7_Album" + ) AS "%10_aggregates" + ) AS "%8_universe" + ) AS "%results", + ( + SELECT + coalesce( + bool_and("%11_v2_insert_Album"."%check__constraint"), + true + ) AS "%check__constraint" + FROM + "%0_generated_mutation" AS "%11_v2_insert_Album" + ) AS "%check__constraint"; + +COMMIT; + +[[(1, String("Lake Mannion")), (2, String("procedure"))]] diff --git a/crates/query-engine/translation/tests/tests.rs b/crates/query-engine/translation/tests/tests.rs index 3061197e..8b0cb0c1 100644 --- a/crates/query-engine/translation/tests/tests.rs +++ b/crates/query-engine/translation/tests/tests.rs @@ -438,4 +438,15 @@ mod mutations { .unwrap(); insta::assert_snapshot!(result); } + + #[tokio::test] + async fn v2_insert_return_object_relationship() { + let result = common::test_mutation_translation( + IsolationLevel::default(), + "v2_insert_return_object_relationship", + ) + .await + .unwrap(); + insta::assert_snapshot!(result); + } }