Projects STRLCPY graphql-engine Commits fcfc4e06
🤬
  • cherry-pick PR #10625 into release v2.36

    PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10627
    GitOrigin-RevId: ee7b7489da4057892bc159168fe0524c4d141ad5
  • Loading...
  • Rakesh Emmadi committed with hasura-bot 4 months ago
    fcfc4e06
    1 parent 79fa4e16
  • ■ ■ ■ ■ ■ ■
    server/lib/hasura-extras/hasura-extras.cabal
    skipped 95 lines
    96 96   , x509-store
    97 97   , x509-system
    98 98   , x509-validation
     99 + , vector
     100 + , extra
    99 101   
    100 102   
    101 103   default-extensions:
    skipped 50 lines
    152 154   
    153 155   System.Monitor.Heartbeat
    154 156   
     157 + Kriti.Extended
     158 + 
  • ■ ■ ■ ■ ■ ■
    server/lib/hasura-extras/src/Kriti/Extended.hs
     1 +module Kriti.Extended (fieldAccessPathTailValues) where
     2 + 
     3 +import Data.Aeson.KeyMap qualified as KeyMap
     4 +import Data.List.Extra (unsnoc)
     5 +import Data.Vector qualified as Vector
     6 +import Hasura.Prelude
     7 +import Kriti.Parser qualified as Kriti
     8 + 
     9 +-- | Extracts tail values of the given field access path.
     10 +-- Traverses the kriti template recursively to match the path with the field accessors.
     11 +-- If the path is matched, then the tail value is extracted.
     12 +fieldAccessPathTailValues :: [Text] -> Kriti.ValueExt -> [Text]
     13 +fieldAccessPathTailValues path = \case
     14 + -- Field accessors
     15 + Kriti.RequiredFieldAccess _span value tailValue -> fieldAccessTail path value tailValue
     16 + Kriti.OptionalFieldAccess _span value tailValues -> concatMap (fieldAccessTail path value) tailValues
     17 + -- We need to recurse into for the following cases
     18 + Kriti.Object _span keyMap -> concatMap (fieldAccessPathTailValues path) $ KeyMap.elems keyMap
     19 + Kriti.Array _span values -> concatMap (fieldAccessPathTailValues path) $ Vector.toList values
     20 + Kriti.StringTem _span values -> concatMap (fieldAccessPathTailValues path) $ Vector.toList values
     21 + Kriti.Iff _span value1 value2 elIfs elseValue ->
     22 + fieldAccessPathTailValues path value1
     23 + <> fieldAccessPathTailValues path value2
     24 + <> concatMap (\(Kriti.Elif _span val1 val2) -> fieldAccessPathTailValues path val1 <> fieldAccessPathTailValues path val2) elIfs
     25 + <> fieldAccessPathTailValues path elseValue
     26 + Kriti.Eq _span value1 value2 ->
     27 + fieldAccessPathTailValues path value1
     28 + <> fieldAccessPathTailValues path value2
     29 + Kriti.NotEq _span value1 value2 ->
     30 + fieldAccessPathTailValues path value1
     31 + <> fieldAccessPathTailValues path value2
     32 + Kriti.Gt _span value1 value2 ->
     33 + fieldAccessPathTailValues path value1
     34 + <> fieldAccessPathTailValues path value2
     35 + Kriti.Gte _span value1 value2 ->
     36 + fieldAccessPathTailValues path value1
     37 + <> fieldAccessPathTailValues path value2
     38 + Kriti.Lt _span value1 value2 ->
     39 + fieldAccessPathTailValues path value1
     40 + <> fieldAccessPathTailValues path value2
     41 + Kriti.Lte _span value1 value2 ->
     42 + fieldAccessPathTailValues path value1
     43 + <> fieldAccessPathTailValues path value2
     44 + Kriti.And _span value1 value2 ->
     45 + fieldAccessPathTailValues path value1
     46 + <> fieldAccessPathTailValues path value2
     47 + Kriti.Or _span value1 value2 ->
     48 + fieldAccessPathTailValues path value1
     49 + <> fieldAccessPathTailValues path value2
     50 + Kriti.In _span value1 value2 ->
     51 + fieldAccessPathTailValues path value1
     52 + <> fieldAccessPathTailValues path value2
     53 + Kriti.Defaulting _span value1 value2 ->
     54 + fieldAccessPathTailValues path value1
     55 + <> fieldAccessPathTailValues path value2
     56 + Kriti.Range _span _ _ value1 value2 ->
     57 + fieldAccessPathTailValues path value1
     58 + <> fieldAccessPathTailValues path value2
     59 + Kriti.Function _span _ value -> fieldAccessPathTailValues path value
     60 + -- We don't need to recurse into for the following cases
     61 + Kriti.String _span _ -> []
     62 + Kriti.Number _span _ -> []
     63 + Kriti.Boolean _span _ -> []
     64 + Kriti.Null _span -> []
     65 + Kriti.Var _span _varName -> []
     66 + 
     67 +-- | Match the path with the field accessors in the kriti template
     68 +matchPath :: [Text] -> Kriti.ValueExt -> Bool
     69 +matchPath path kritiValue =
     70 + case unsnoc path of
     71 + Nothing ->
     72 + -- Received an empty path
     73 + False
     74 + Just ([], firstElem) ->
     75 + -- Reached the initial end of the path
     76 + -- Now, kritiValue should be a variable that matches the firstElem
     77 + case kritiValue of
     78 + Kriti.Var _span varName -> varName == firstElem
     79 + _ -> False
     80 + Just (initPath, tail') ->
     81 + -- We need to recurse into for field access
     82 + case kritiValue of
     83 + Kriti.RequiredFieldAccess _span value tailValue ->
     84 + matchPath initPath value && ((Just tail') == coerceTailValueAsText tailValue)
     85 + _ -> False
     86 + 
     87 +-- | Get the tail of the path for a field access
     88 +--
     89 +-- fieldAccessTail ["a", "b"]
     90 +-- match case:
     91 +-- $.a.b.c -> ["c"]
     92 +-- $.a.b.[c] -> ["c"]
     93 +-- $.a.b.['c'] -> ["c"]
     94 +-- $.a.b.["c"] -> ["c"]
     95 +-- $.a.b.[<kriti_exp>] -> []
     96 +-- not match case:
     97 +-- $.c.d.[<kriti_exp>] -> fieldAccessPathTailValues ["a", "b"] kriti_exp
     98 +fieldAccessTail ::
     99 + [Text] ->
     100 + Kriti.ValueExt ->
     101 + Either Text Kriti.ValueExt ->
     102 + [Text]
     103 +fieldAccessTail path accessPath tailValue =
     104 + if matchPath path accessPath
     105 + then maybeToList $ coerceTailValueAsText tailValue
     106 + else -- If path is not matched, look for kriti expressions in the tailValue
     107 + case tailValue of
     108 + Right kritiExp -> fieldAccessPathTailValues path kritiExp
     109 + Left _ -> []
     110 + 
     111 +-- | Coerce the tail value of the path as text
     112 +--
     113 +-- path.tail_value => Left text
     114 +-- path.[tail_value] => Right (Var _ text)
     115 +-- path.['tail_value'] => Right (String _ text)
     116 +-- path.["tail_value"] => Right (StringTem _ [String _ text])
     117 +coerceTailValueAsText :: Either Text Kriti.ValueExt -> Maybe Text
     118 +coerceTailValueAsText = \case
     119 + Left t -> Just t
     120 + Right (Kriti.Var _span t) -> Just t
     121 + Right (Kriti.String _span t) -> Just t
     122 + Right (Kriti.StringTem _span templates) ->
     123 + case Vector.toList templates of
     124 + [Kriti.String _span' t] -> Just t
     125 + _ -> Nothing
     126 + Right _ -> Nothing
     127 + 
  • ■ ■ ■ ■
    server/src-lib/Hasura/Backends/BigQuery/Instances/Types.hs
    skipped 125 lines
    126 126   type SourceConfig 'BigQuery = BigQuery.BigQuerySourceConfig
    127 127   type SourceConnConfiguration 'BigQuery = BigQuery.BigQueryConnSourceConfig
    128 128   sourceConfigNumReadReplicas = const 0 -- not supported
    129  - sourceConfigConnectonTemplateEnabled = const False -- not supported
     129 + sourceConfigConnectonTemplate = const Nothing -- not supported
    130 130   sourceSupportsColumnRedaction = const True
    131 131   sourceConfigBackendSourceKind _sourceConfig = BigQueryKind
    132 132   
  • ■ ■ ■ ■
    server/src-lib/Hasura/Backends/DataConnector/Adapter/Backend.hs
    skipped 187 lines
    188 188   type ScalarTypeParsingContext 'DataConnector = API.ScalarTypesCapabilities
    189 189   
    190 190   sourceConfigNumReadReplicas = const 0 -- not supported
    191  - sourceConfigConnectonTemplateEnabled = const False -- not supported
     191 + sourceConfigConnectonTemplate = const Nothing -- not supported
    192 192   sourceSupportsColumnRedaction DC.SourceConfig {..} =
    193 193   _scCapabilities & API._cQueries >>= API._qcRedaction & isJust
    194 194   sourceConfigBackendSourceKind DC.SourceConfig {..} = DataConnectorKind _scDataConnectorName
    skipped 40 lines
  • ■ ■ ■ ■
    server/src-lib/Hasura/Backends/MSSQL/Instances/Types.hs
    skipped 131 lines
    132 132   type SourceConfig 'MSSQL = MSSQL.MSSQLSourceConfig
    133 133   type SourceConnConfiguration 'MSSQL = MSSQL.MSSQLConnConfiguration
    134 134   sourceConfigNumReadReplicas = MSSQL._mscReadReplicas
    135  - sourceConfigConnectonTemplateEnabled = const False -- not supported
     135 + sourceConfigConnectonTemplate = const Nothing -- not supported
    136 136   sourceSupportsColumnRedaction = const True
    137 137   sourceConfigBackendSourceKind _sourceConfig = MSSQLKind
    138 138   
  • ■ ■ ■ ■ ■ ■
    server/src-lib/Hasura/Backends/Postgres/Execute/Types.hs
    skipped 26 lines
    27 27   pgResolveConnectionTemplate,
    28 28   resolvePostgresConnectionTemplate,
    29 29   sourceConfigNumReadReplicas,
    30  - sourceConfigConnectonTemplateEnabled,
     30 + sourceConfigConnectonTemplate,
    31 31   getPGColValues,
    32 32   )
    33 33  where
    skipped 25 lines
    59 59  import Hasura.SQL.Types (ExtensionsSchema, toSQL)
    60 60  import Hasura.Session (UserInfo (_uiRole, _uiSession), getSessionVariableValue, maybeRoleFromSessionVariables)
    61 61  import Kriti.Error qualified as Kriti
     62 +import Kriti.Parser qualified as Kriti
    62 63  import Network.HTTP.Types qualified as HTTP
    63 64   
    64 65  -- See Note [Existentially Quantified Types]
    skipped 135 lines
    200 201   = -- | Connection templates are disabled for Hasura CE
    201 202   ConnTemplate_NotApplicable
    202 203   | ConnTemplate_NotConfigured
    203  - | ConnTemplate_Resolver ConnectionTemplateResolver
     204 + | ConnTemplate_Resolver Kriti.ValueExt ConnectionTemplateResolver
    204 205   
    205 206  connectionTemplateConfigResolver :: ConnectionTemplateConfig -> Maybe ConnectionTemplateResolver
    206 207  connectionTemplateConfigResolver = \case
    207 208   ConnTemplate_NotApplicable -> Nothing
    208 209   ConnTemplate_NotConfigured -> Nothing
    209  - ConnTemplate_Resolver resolver -> Just resolver
     210 + ConnTemplate_Resolver _template resolver -> Just resolver
    210 211   
    211 212  -- | A hook to resolve connection template
    212 213  newtype ConnectionTemplateResolver = ConnectionTemplateResolver
    skipped 85 lines
    298 299   ConnTemplate_NotApplicable -> connectionTemplateNotApplicableError
    299 300   ConnTemplate_NotConfigured ->
    300 301   throw400 TemplateResolutionFailed "Connection template not defined for the source"
    301  - ConnTemplate_Resolver resolver ->
     302 + ConnTemplate_Resolver _template resolver ->
    302 303   pure resolver
    303 304   Just connectionTemplate ->
    304 305   case _pscConnectionTemplateConfig sourceConfig of
    skipped 34 lines
    339 340  sourceConfigNumReadReplicas =
    340 341   maybe 0 List.NonEmpty.length . _pscReadReplicaConnInfos
    341 342   
    342  -sourceConfigConnectonTemplateEnabled :: PGSourceConfig -> Bool
    343  -sourceConfigConnectonTemplateEnabled pgSourceConfig =
     343 +sourceConfigConnectonTemplate :: PGSourceConfig -> Maybe Kriti.ValueExt
     344 +sourceConfigConnectonTemplate pgSourceConfig =
    344 345   case _pscConnectionTemplateConfig pgSourceConfig of
    345  - ConnTemplate_NotApplicable -> False
    346  - ConnTemplate_NotConfigured -> False
    347  - ConnTemplate_Resolver _ -> True
     346 + ConnTemplate_NotApplicable -> Nothing
     347 + ConnTemplate_NotConfigured -> Nothing
     348 + ConnTemplate_Resolver template _ -> Just template
    348 349   
    349 350  getPGColValues ::
    350 351   (MonadIO m, MonadError QErr m) =>
    skipped 74 lines
  • ■ ■ ■ ■
    server/src-lib/Hasura/Backends/Postgres/Instances/Types.hs
    skipped 189 lines
    190 190   type SourceConfig ('Postgres pgKind) = Postgres.PGSourceConfig
    191 191   type SourceConnConfiguration ('Postgres pgKind) = Postgres.PostgresConnConfiguration
    192 192   sourceConfigNumReadReplicas = Postgres.sourceConfigNumReadReplicas
    193  - sourceConfigConnectonTemplateEnabled = Postgres.sourceConfigConnectonTemplateEnabled
     193 + sourceConfigConnectonTemplate = Postgres.sourceConfigConnectonTemplate
    194 194   sourceSupportsColumnRedaction = const True
    195 195   sourceConfigBackendSourceKind _sourceConfig =
    196 196   case backendTag @('Postgres pgKind) of
    skipped 4 lines
  • ■ ■ ■ ■ ■ ■
    server/src-lib/Hasura/GraphQL/Transport/HTTP.hs
    skipped 22 lines
    23 23   CacheStoreResponse (..),
    24 24   SessVarPred,
    25 25   filterVariablesFromQuery,
     26 + filterSessionVariableByName,
    26 27   runSessVarPred,
    27 28   )
    28 29  where
    skipped 204 lines
    233 234   
    234 235  keepAllSessionVariables :: SessVarPred
    235 236  keepAllSessionVariables = SessVarPred $ Just $ \_ _ -> True
     237 + 
     238 +filterSessionVariableByName :: (SessionVariable -> Bool) -> SessVarPred
     239 +filterSessionVariableByName f = SessVarPred $ Just $ \sv _ -> f sv
    236 240   
    237 241  runSessVarPred :: SessVarPred -> SessionVariables -> SessionVariables
    238 242  runSessVarPred = filterSessionVariables . fromMaybe (\_ _ -> False) . unSessVarPred
    skipped 548 lines
  • ■ ■ ■ ■ ■ ■
    server/src-lib/Hasura/RQL/Types/SourceConfiguration.hs
    skipped 12 lines
    13 13  import Hasura.Prelude
    14 14  import Hasura.RQL.Types.BackendTag
    15 15  import Hasura.RQL.Types.BackendType
     16 +import Kriti.Parser qualified as Kriti
    16 17   
    17 18  type Representable a = (Show a, Eq a, Hashable a, NFData a)
    18 19   
    skipped 27 lines
    46 47   -- | The number of read replicas specified in the source configuration
    47 48   sourceConfigNumReadReplicas :: SourceConfig b -> Int
    48 49   
    49  - -- | Whether the source configuration specifies the use of a connection
    50  - -- template
    51  - sourceConfigConnectonTemplateEnabled :: SourceConfig b -> Bool
     50 + -- | The connection template specified in the source configuration, if any
     51 + sourceConfigConnectonTemplate :: SourceConfig b -> Maybe Kriti.ValueExt
    52 52   
    53 53   -- | Whether or not the source supports performing column redaction.
    54 54   -- See note [SQL generation for inherited roles] for more information
    skipped 4 lines
Please wait...
Page is in error, reload to recover