graphql-engine/server/src-lib/Hasura/LogicalModel/Cache.hs
Daniel Harvey e93d3d2735 feature(server): allow nullability in Logical Model arguments
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8214
GitOrigin-RevId: 1ecf4c9c362aad9eabad2134a70266ff1170577b
2023-03-07 10:04:58 +00:00

48 lines
1.5 KiB
Haskell

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
-- | The representation of logical models as derived from the schema cache.
module Hasura.LogicalModel.Cache
( LogicalModelInfo (..),
LogicalModelCache,
lmiRootFieldName,
lmiCode,
lmiReturns,
lmiArguments,
lmiPermissions,
lmiDescription,
)
where
import Control.Lens (makeLenses)
import Data.Aeson (ToJSON (toJSON), genericToJSON)
import Hasura.CustomReturnType (CustomReturnType)
import Hasura.LogicalModel.Metadata (InterpolatedQuery, LogicalModelArgumentName, LogicalModelName)
import Hasura.LogicalModel.Types (NullableScalarType)
import Hasura.Prelude
import Hasura.RQL.Types.Backend (Backend)
import Hasura.RQL.Types.Table (RolePermInfoMap)
import Hasura.SQL.Backend (BackendType)
type LogicalModelCache b = HashMap LogicalModelName (LogicalModelInfo b)
-- | The type into which 'LogicalModelMetadata' is resolved in
-- 'Hasura/RQL/DDL/Schema/Cache.buildSchemaCacheRule'.
data LogicalModelInfo (b :: BackendType) = LogicalModelInfo
{ _lmiRootFieldName :: LogicalModelName,
_lmiCode :: InterpolatedQuery LogicalModelArgumentName,
_lmiReturns :: CustomReturnType b,
_lmiArguments :: HashMap LogicalModelArgumentName (NullableScalarType b),
_lmiPermissions :: RolePermInfoMap b,
_lmiDescription :: Maybe Text
}
deriving stock (Generic)
instance
(Backend b, ToJSON (RolePermInfoMap b)) =>
ToJSON (LogicalModelInfo b)
where
toJSON = genericToJSON hasuraJSON
makeLenses ''LogicalModelInfo