From 2c5e89e5d82b6b03571789212e6e5a804fad06cd Mon Sep 17 00:00:00 2001 From: Tom Harding Date: Tue, 6 Jun 2023 18:19:35 +0100 Subject: [PATCH] Fix array relationship aliasing (good news) PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9438 Co-authored-by: Daniel Harvey <4729125+danieljharvey@users.noreply.github.com> GitOrigin-RevId: 14b225ad8c834f2aa9863cee951d39f203046282 --- .../Postgres/Translate/Select/Internal/Process.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/server/src-lib/Hasura/Backends/Postgres/Translate/Select/Internal/Process.hs b/server/src-lib/Hasura/Backends/Postgres/Translate/Select/Internal/Process.hs index 58d9dd91f01..001368db3c4 100644 --- a/server/src-lib/Hasura/Backends/Postgres/Translate/Select/Internal/Process.hs +++ b/server/src-lib/Hasura/Backends/Postgres/Translate/Select/Internal/Process.hs @@ -229,7 +229,7 @@ processAnnAggregateSelect sourcePrefixes fieldAlias annAggSel = do aggregateFieldToExp thisSourcePrefix aggFields strfyNum ) TAFNodes _ annFields -> do - annFieldExtr <- processAnnFields thisSourcePrefix fieldName similarArrayFields annFields tCase + annFieldExtr <- processAnnFields thisSourcePrefix fieldName annFields tCase pure ( [annFieldExtr], withJsonAggExtr permLimitSubQuery (orderByForJsonAgg selectSource) @@ -301,11 +301,10 @@ processAnnFields :: ) => TableIdentifier -> FieldName -> - SimilarArrayFields -> AnnFields ('Postgres pgKind) -> Maybe NamingCase -> m (S.ColumnAlias, S.SQLExp) -processAnnFields sourcePrefix fieldAlias similarArrFields annFields tCase = do +processAnnFields sourcePrefix fieldAlias annFields tCase = do fieldExps <- forM annFields $ \(fieldName, field) -> (fieldName,) <$> case field of @@ -345,15 +344,15 @@ processAnnFields sourcePrefix fieldAlias similarArrFields annFields tCase = do let sourcePrefixes = mkSourcePrefixes objRelSourcePrefix selectSource = ObjectSelectSource (_pfThis sourcePrefixes) ident filterExp objRelSource = ObjectRelationSource relName relMapping selectSource nullable - annFieldsExtr <- processAnnFields (identifierToTableIdentifier $ _pfThis sourcePrefixes) fieldName HashMap.empty objAnnFields tCase + annFieldsExtr <- processAnnFields (identifierToTableIdentifier $ _pfThis sourcePrefixes) fieldName objAnnFields tCase pure ( objRelSource, uncurry InsOrdHashMap.singleton annFieldsExtr, S.mkQIdenExp objRelSourcePrefix fieldName ) AFArrayRelation arrSel -> do - let arrRelSourcePrefix = mkArrayRelationSourcePrefix sourcePrefix fieldAlias similarArrFields fieldName - arrRelAlias = mkArrayRelationAlias fieldAlias similarArrFields fieldName + let arrRelSourcePrefix = mkArrayRelationSourcePrefix sourcePrefix fieldAlias HashMap.empty fieldName + arrRelAlias = mkArrayRelationAlias fieldAlias HashMap.empty fieldName processArrayRelation (mkSourcePrefixes arrRelSourcePrefix) fieldName arrRelAlias arrSel tCase pure $ S.mkQIdenExp arrRelSourcePrefix fieldName AFComputedField _ _ (CFSScalar scalar caseBoolExpMaybe) -> do @@ -619,7 +618,6 @@ processAnnSimpleSelect sourcePrefixes fieldAlias permLimitSubQuery annSimpleSel processAnnFields (identifierToTableIdentifier $ _pfThis sourcePrefixes) fieldAlias - similarArrayFields annSelFields tCase let allExtractors = InsOrdHashMap.fromList $ annFieldsExtr : orderByAndDistinctExtrs @@ -785,7 +783,7 @@ processConnectionSelect sourcePrefixes fieldAlias relAlias colMapping connection <> "." <> edgeText edgeFieldIdentifier = toIdentifier edgeFieldName - annFieldsExtrExp <- lift $ processAnnFields thisPrefix edgeFieldName similarArrayFields annFields tCase + annFieldsExtrExp <- lift $ processAnnFields thisPrefix edgeFieldName annFields tCase modify' (<> [annFieldsExtrExp]) pure $ S.SEIdentifier edgeFieldIdentifier