RemoveHasura.RQL.Types dependency on Backends.Postgres.Execute.Types

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8869
Co-authored-by: Daniel Harvey <4729125+danieljharvey@users.noreply.github.com>
GitOrigin-RevId: acabf17b5b9bde9f0f319eeae120ccc9527075a3
This commit is contained in:
Tom Harding 2023-04-24 15:39:23 +01:00 committed by hasura-bot
parent 4c2ab2db4b
commit 982bf2cec6
4 changed files with 47 additions and 38 deletions

View File

@ -721,6 +721,7 @@ library
, Hasura.LogicalModel.Schema , Hasura.LogicalModel.Schema
, Hasura.LogicalModel.Types , Hasura.LogicalModel.Types
, Hasura.ClientCredentials
, Hasura.EncJSON , Hasura.EncJSON
, Hasura.Function.API , Hasura.Function.API

View File

@ -90,6 +90,7 @@ import Hasura.App.State
import Hasura.Backends.MSSQL.Connection import Hasura.Backends.MSSQL.Connection
import Hasura.Backends.Postgres.Connection import Hasura.Backends.Postgres.Connection
import Hasura.Base.Error import Hasura.Base.Error
import Hasura.ClientCredentials (getEEClientCredentialsTx, setEEClientCredentialsTx)
import Hasura.Eventing.Common import Hasura.Eventing.Common
import Hasura.Eventing.EventTrigger import Hasura.Eventing.EventTrigger
import Hasura.Eventing.ScheduledTrigger import Hasura.Eventing.ScheduledTrigger
@ -125,7 +126,6 @@ import Hasura.RQL.DDL.Schema.Catalog
import Hasura.RQL.Types.Allowlist import Hasura.RQL.Types.Allowlist
import Hasura.RQL.Types.Backend import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Common import Hasura.RQL.Types.Common
import Hasura.RQL.Types.EECredentials
import Hasura.RQL.Types.Eventing.Backend import Hasura.RQL.Types.Eventing.Backend
import Hasura.RQL.Types.Metadata import Hasura.RQL.Types.Metadata
import Hasura.RQL.Types.ResizePool import Hasura.RQL.Types.ResizePool

View File

@ -0,0 +1,45 @@
{-# LANGUAGE QuasiQuotes #-}
module Hasura.ClientCredentials
( EEClientCredentials (..),
EEClientId (..),
getEEClientCredentialsTx,
setEEClientCredentialsTx,
)
where
import Database.PG.Query qualified as PG
import Hasura.Backends.Postgres.Execute.Types
import Hasura.Base.Error
import Hasura.Prelude
import Hasura.RQL.Types.EECredentials (EEClientCredentials (..), EEClientId (..))
getEEClientCredentialsTx :: PG.TxE QErr (Maybe EEClientCredentials)
getEEClientCredentialsTx =
makeClientCredentials . PG.getRow
<$> PG.withQE
defaultTxErrorHandler
[PG.sql|
SELECT ee_client_id::text, ee_client_secret
FROM hdb_catalog.hdb_version
|]
()
False
where
makeClientCredentials :: (Maybe Text, Maybe Text) -> Maybe EEClientCredentials
makeClientCredentials (clientIdMaybe, clientSecretMaybe) = do
eccClientId <- EEClientId <$> clientIdMaybe
eccClientSecret <- clientSecretMaybe
pure EEClientCredentials {..}
setEEClientCredentialsTx :: EEClientCredentials -> PG.TxE QErr ()
setEEClientCredentialsTx EEClientCredentials {..} =
PG.unitQE
defaultTxErrorHandler
[PG.sql|
UPDATE hdb_catalog.hdb_version
SET ee_client_id = $1,
ee_client_secret = $2
|]
(_getEEClientId eccClientId, eccClientSecret)
True

View File

@ -1,18 +1,11 @@
{-# LANGUAGE QuasiQuotes #-}
module Hasura.RQL.Types.EECredentials module Hasura.RQL.Types.EECredentials
( EEClientCredentials (..), ( EEClientCredentials (..),
EEClientId (..), EEClientId (..),
getEEClientCredentialsTx,
setEEClientCredentialsTx,
) )
where where
import Data.Aeson (FromJSON, (.:)) import Data.Aeson (FromJSON, (.:))
import Data.Aeson qualified as Aeson import Data.Aeson qualified as Aeson
import Database.PG.Query qualified as PG
import Hasura.Backends.Postgres.Execute.Types
import Hasura.Base.Error
import Hasura.Prelude import Hasura.Prelude
data EEClientCredentials = EEClientCredentials data EEClientCredentials = EEClientCredentials
@ -28,33 +21,3 @@ instance FromJSON EEClientCredentials where
eccClientId <- o .: "client_id" eccClientId <- o .: "client_id"
eccClientSecret <- o .: "client_secret" eccClientSecret <- o .: "client_secret"
pure EEClientCredentials {..} pure EEClientCredentials {..}
getEEClientCredentialsTx :: PG.TxE QErr (Maybe EEClientCredentials)
getEEClientCredentialsTx =
makeClientCredentials . PG.getRow
<$> PG.withQE
defaultTxErrorHandler
[PG.sql|
SELECT ee_client_id::text, ee_client_secret
FROM hdb_catalog.hdb_version
|]
()
False
where
makeClientCredentials :: (Maybe Text, Maybe Text) -> Maybe EEClientCredentials
makeClientCredentials (clientIdMaybe, clientSecretMaybe) = do
eccClientId <- EEClientId <$> clientIdMaybe
eccClientSecret <- clientSecretMaybe
pure EEClientCredentials {..}
setEEClientCredentialsTx :: EEClientCredentials -> PG.TxE QErr ()
setEEClientCredentialsTx EEClientCredentials {..} =
PG.unitQE
defaultTxErrorHandler
[PG.sql|
UPDATE hdb_catalog.hdb_version
SET ee_client_id = $1,
ee_client_secret = $2
|]
(_getEEClientId eccClientId, eccClientSecret)
True