mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
06b284cf33
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7476 Co-authored-by: Tom Harding <6302310+i-am-tom@users.noreply.github.com> GitOrigin-RevId: 781c29666e92004dc82918c2292fdacc27fded4c
53 lines
1.5 KiB
Haskell
53 lines
1.5 KiB
Haskell
{-# LANGUAGE UndecidableInstances #-}
|
|
|
|
-- | Types concerned with user-specified custom SQL fragments.
|
|
module Hasura.CustomSQL
|
|
( CustomSQLParameter (..),
|
|
)
|
|
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
|