graphql-engine/server/src-lib/Hasura/CustomSQL.hs
Daniel Harvey 06b284cf33 [server] metadata API for native access
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
2023-01-16 17:21:22 +00:00

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