From 680cf5b3c00658828d2dfe37e07e16a2d79c2589 Mon Sep 17 00:00:00 2001 From: paritosh-08 <85472423+paritosh-08@users.noreply.github.com> Date: Mon, 4 Jul 2022 11:10:16 +0530 Subject: [PATCH] server: fix missing/wrong `graphql-default` field name transformations PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4927 GitOrigin-RevId: 02dc61f05e06f46c193be3685abbef9c8535edef --- .../Backends/Postgres/Instances/Schema.hs | 21 ++++++++++--------- .../src-lib/Hasura/GraphQL/Schema/OrderBy.hs | 7 ++++--- .../GraphQL/Schema/RemoteRelationship.hs | 6 ++++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/server/src-lib/Hasura/Backends/Postgres/Instances/Schema.hs b/server/src-lib/Hasura/Backends/Postgres/Instances/Schema.hs index 97e343670fa..81d96eb171d 100644 --- a/server/src-lib/Hasura/Backends/Postgres/Instances/Schema.hs +++ b/server/src-lib/Hasura/Backends/Postgres/Instances/Schema.hs @@ -338,22 +338,22 @@ orderByOperators :: orderByOperators tCase = (Name._order_by,) $ NE.fromList - [ ( define (applyFieldNameCaseCust tCase Name._asc) "in ascending order, nulls last", + [ ( define (applyEnumValueCase tCase Name._asc) "in ascending order, nulls last", (PG.OTAsc, PG.NLast) ), - ( define (applyFieldNameCaseCust tCase Name._asc_nulls_first) "in ascending order, nulls first", + ( define (applyEnumValueCase tCase Name._asc_nulls_first) "in ascending order, nulls first", (PG.OTAsc, PG.NFirst) ), - ( define (applyFieldNameCaseCust tCase Name._asc_nulls_last) "in ascending order, nulls last", + ( define (applyEnumValueCase tCase Name._asc_nulls_last) "in ascending order, nulls last", (PG.OTAsc, PG.NLast) ), - ( define (applyFieldNameCaseCust tCase Name._desc) "in descending order, nulls first", + ( define (applyEnumValueCase tCase Name._desc) "in descending order, nulls first", (PG.OTDesc, PG.NFirst) ), - ( define (applyFieldNameCaseCust tCase Name._desc_nulls_first) "in descending order, nulls first", + ( define (applyEnumValueCase tCase Name._desc_nulls_first) "in descending order, nulls first", (PG.OTDesc, PG.NFirst) ), - ( define (applyFieldNameCaseCust tCase Name._desc_nulls_last) "in descending order, nulls last", + ( define (applyEnumValueCase tCase Name._desc_nulls_last) "in descending order, nulls last", (PG.OTDesc, PG.NLast) ) ] @@ -388,8 +388,8 @@ comparisonExps = memoize 'comparisonExps \columnType -> do lqueryParser <- columnParser (ColumnScalar PGLquery) (G.Nullability False) -- `ltxtquery` represents a full-text-search-like pattern for matching `ltree` values. ltxtqueryParser <- columnParser (ColumnScalar PGLtxtquery) (G.Nullability False) - maybeCastParser <- castExp columnType tCase <- asks getter + maybeCastParser <- castExp columnType tCase let name = applyTypeNameCaseCust tCase $ P.getName typedParser <> Name.__comparison_exp desc = G.Description $ @@ -675,8 +675,8 @@ comparisonExps = memoize 'comparisonExps \columnType -> do (ColumnScalar $ PG.PGArray scalarType) (PG.PGValArray $ cvValue <$> columnValues) - castExp :: ColumnType ('Postgres pgKind) -> m (Maybe (Parser 'Input n (CastExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))) - castExp sourceType = do + castExp :: ColumnType ('Postgres pgKind) -> NamingCase -> m (Maybe (Parser 'Input n (CastExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))) + castExp sourceType tCase = do let maybeScalars = case sourceType of ColumnScalar PGGeography -> Just (PGGeography, PGGeometry) ColumnScalar PGGeometry -> Just (PGGeometry, PGGeography) @@ -684,10 +684,11 @@ comparisonExps = memoize 'comparisonExps \columnType -> do _ -> Nothing forM maybeScalars $ \(sourceScalar, targetScalar) -> do - sourceName <- mkScalarTypeName sourceScalar <&> (<> Name.__cast_exp) + scalarTypeName <- C.fromName <$> mkScalarTypeName sourceScalar targetName <- mkScalarTypeName targetScalar targetOpExps <- comparisonExps $ ColumnScalar targetScalar let field = P.fieldOptional targetName Nothing $ (targetScalar,) <$> targetOpExps + sourceName = applyTypeNameCaseIdentifier tCase (scalarTypeName <> (C.fromTuple $$(G.litGQLIdentifier ["cast", "exp"]))) pure $ P.object sourceName Nothing $ M.fromList . maybeToList <$> field geographyWithinDistanceInput :: diff --git a/server/src-lib/Hasura/GraphQL/Schema/OrderBy.hs b/server/src-lib/Hasura/GraphQL/Schema/OrderBy.hs index 6059d69bbb1..36d3dac23e7 100644 --- a/server/src-lib/Hasura/GraphQL/Schema/OrderBy.hs +++ b/server/src-lib/Hasura/GraphQL/Schema/OrderBy.hs @@ -7,6 +7,7 @@ module Hasura.GraphQL.Schema.OrderBy where import Data.Has +import Data.Text.Casing qualified as C import Data.Text.Extended import Hasura.GraphQL.Parser.Class import Hasura.GraphQL.Schema.Backend @@ -99,7 +100,7 @@ orderByExp sourceInfo tableInfo = memoizeOn 'orderByExp (_siName sourceInfo, tab otherTableOrderBy <- join <$> P.fieldOptional fieldName Nothing (P.nullable otherTableParser) pure $ fmap (map $ fmap $ IR.AOCObjectRelation relationshipInfo newPerms) otherTableOrderBy ArrRel -> do - let aggregateFieldName = fieldName <> Name.__aggregate + let aggregateFieldName = applyFieldNameCaseIdentifier tCase $ C.fromTuple (fieldName, [G.convertNameToSuffix Name._aggregate]) aggregationParser <- lift $ orderByAggregation sourceInfo remoteTableInfo pure $ do aggregationOrderBy <- join <$> P.fieldOptional aggregateFieldName Nothing (P.nullable aggregationParser) @@ -123,7 +124,7 @@ orderByExp sourceInfo tableInfo = memoizeOn 'orderByExp (_siName sourceInfo, tab (orderByOperator @b tCase sourceInfo) <&> fmap (pure . mkOrderByItemG @b (IR.AOCComputedField computedFieldOrderBy)) . join ReturnsTable table -> do - let aggregateFieldName = fieldName <> Name.__aggregate + let aggregateFieldName = applyFieldNameCaseIdentifier tCase $ C.fromTuple (fieldName, [G.convertNameToSuffix Name._aggregate]) tableInfo' <- askTableInfo sourceInfo table perms <- MaybeT $ tableSelectPermissions tableInfo' let newPerms = fmap partialSQLExpToUnpreparedValue <$> spiFilter perms @@ -238,7 +239,7 @@ orderByOperator' :: Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b)) orderByOperator' tCase sourceInfo = let (sourcePrefix, orderOperators) = orderByOperators @b sourceInfo tCase - in P.nullable $ P.enum (applyFieldNameCaseCust tCase sourcePrefix) (Just "column ordering options") $ orderOperators + in P.nullable $ P.enum (applyTypeNameCaseCust tCase sourcePrefix) (Just "column ordering options") $ orderOperators mkOrderByItemG :: forall b a. a -> (BasicOrderType b, NullsOrderType b) -> IR.OrderByItemG b a mkOrderByItemG column (orderType, nullsOrder) = diff --git a/server/src-lib/Hasura/GraphQL/Schema/RemoteRelationship.hs b/server/src-lib/Hasura/GraphQL/Schema/RemoteRelationship.hs index b98ca49ee28..320dc71a5b4 100644 --- a/server/src-lib/Hasura/GraphQL/Schema/RemoteRelationship.hs +++ b/server/src-lib/Hasura/GraphQL/Schema/RemoteRelationship.hs @@ -7,6 +7,7 @@ import Control.Lens import Data.Has import Data.HashMap.Strict.Extended qualified as Map import Data.List.NonEmpty qualified as NE +import Data.Text.Casing qualified as C import Data.Text.Extended import Hasura.Base.Error import Hasura.GraphQL.Schema.Backend @@ -29,7 +30,7 @@ import Hasura.RQL.Types.RemoteSchema import Hasura.RQL.Types.ResultCustomization import Hasura.RQL.Types.SchemaCache hiding (askTableInfo) import Hasura.RQL.Types.Source -import Hasura.RQL.Types.SourceCustomization (NamingCase (..), mkCustomizedTypename) +import Hasura.RQL.Types.SourceCustomization import Hasura.SQL.AnyBackend import Hasura.Session import Language.GraphQL.Draft.Syntax qualified as G @@ -182,6 +183,7 @@ remoteRelationshipToSourceField :: m [FieldParser n (IR.RemoteSourceSelect (IR.RemoteRelationshipField IR.UnpreparedValue) IR.UnpreparedValue tgt)] remoteRelationshipToSourceField sourceCache RemoteSourceFieldInfo {..} = P.withTypenameCustomization (mkCustomizedTypename (Just _rsfiSourceCustomization) HasuraCase) do + tCase <- asks getter sourceInfo <- onNothing (unsafeSourceInfo @tgt =<< Map.lookup _rsfiSource sourceCache) $ throw500 $ "source not found " <> dquote _rsfiSource @@ -202,7 +204,7 @@ remoteRelationshipToSourceField sourceCache RemoteSourceFieldInfo {..} = IR.SourceRelationshipObject $ IR.AnnObjectSelectG fields _rsfiTable $ IR._tpFilter $ tablePermissionsInfo tablePerms ArrRel -> do - let aggFieldName = fieldName <> Name.__aggregate + let aggFieldName = applyFieldNameCaseIdentifier tCase $ C.fromTuple (fieldName, [G.convertNameToSuffix Name._aggregate]) selectionSetParser <- selectTable sourceInfo tableInfo fieldName Nothing aggSelectionSetParser <- selectTableAggregate sourceInfo tableInfo aggFieldName Nothing pure $