mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
cd5186be90
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7574 GitOrigin-RevId: 0cb4638a7dd79abf6ccb05092c0c663c84675bbd
55 lines
1.5 KiB
Haskell
55 lines
1.5 KiB
Haskell
{-# LANGUAGE UndecidableInstances #-}
|
|
|
|
-- | Types concerned with user-specified custom SQL fragments.
|
|
module Hasura.CustomSQL
|
|
( CustomSQLParameter (..),
|
|
CustomSQLParameterName (..),
|
|
CustomSQLParameterType (..),
|
|
)
|
|
where
|
|
|
|
import Autodocodec (HasCodec (codec))
|
|
import Autodocodec qualified as AC
|
|
import Data.Aeson
|
|
import Hasura.Prelude
|
|
|
|
----------------------------------
|
|
|
|
newtype CustomSQLParameterName = CustomSQLParameterName {cspnName :: Text}
|
|
deriving newtype (Show, Eq, FromJSON, ToJSON)
|
|
|
|
instance HasCodec CustomSQLParameterName where
|
|
codec = AC.dimapCodec CustomSQLParameterName cspnName codec
|
|
|
|
newtype CustomSQLParameterType = CustomSQLParameterType {cspnType :: Text}
|
|
deriving newtype (Show, Eq, FromJSON, ToJSON)
|
|
|
|
instance HasCodec CustomSQLParameterType where
|
|
codec = AC.dimapCodec CustomSQLParameterType cspnType codec
|
|
|
|
data CustomSQLParameter = CustomSQLParameter
|
|
{ cspName :: CustomSQLParameterName,
|
|
cspType :: CustomSQLParameterType
|
|
}
|
|
deriving (Show, Eq)
|
|
|
|
instance FromJSON CustomSQLParameter where
|
|
parseJSON = withObject "CustomSQLParameter" $ \o -> do
|
|
cspName <- o .: "name"
|
|
cspType <- o .: "type"
|
|
pure CustomSQLParameter {..}
|
|
|
|
instance ToJSON CustomSQLParameter where
|
|
toJSON CustomSQLParameter {..} =
|
|
object
|
|
[ "name" .= cspName,
|
|
"type" .= cspType
|
|
]
|
|
|
|
instance HasCodec CustomSQLParameter where
|
|
codec =
|
|
AC.object "CustomSQLParameter" $
|
|
CustomSQLParameter
|
|
<$> AC.requiredField' "name" AC..= cspName
|
|
<*> AC.requiredField' "type" AC..= cspType
|