{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.RQL.Types.Table
( CombinedSelPermInfo (..),
Constraint (..),
ColumnConfig (..),
CustomRootField (..),
DBTableMetadata (..),
DBTablesMetadata,
DelPermInfo (..),
FieldInfo (..),
FieldInfoMap,
ForeignKey (..),
ForeignKeyMetadata (..),
InsPermInfo (..),
PrimaryKey (..),
RolePermInfo (..),
RolePermInfoMap,
SelPermInfo (..),
TableCache,
TableConfig (..),
TableCoreCache,
TableCoreInfo,
TableEventTriggers,
TableCoreInfoG (..),
TableCustomRootFields (..),
TableInfo (..),
UniqueConstraint (..),
UpdPermInfo (..),
ViewInfo (..),
askColInfo,
askColumnType,
askFieldInfo,
assertColumnExists,
askRelType,
askComputedFieldInfo,
askRemoteRel,
combinedSelPermInfoToSelPermInfo,
emptyCustomRootFields,
emptyTableConfig,
fieldInfoGraphQLName,
fieldInfoGraphQLNames,
fieldInfoName,
getAllCustomRootFields,
getCols,
getColumnInfoM,
getComputedFieldInfos,
getFieldInfoM,
getRels,
getRemoteFieldInfoName,
isMutable,
mkAdminRolePermInfo,
permDel,
permIns,
permSel,
permUpd,
pkColumns,
pkConstraint,
sortCols,
tableInfoName,
getRolePermInfo,
tableArrayRelationships,
tcCustomName,
tcCustomRootFields,
tcComment,
tcColumnConfig,
tciCustomConfig,
tciDescription,
tciApolloFederationConfig,
tciEnumValues,
tciExtraTableMetadata,
tciFieldInfoMap,
tciForeignKeys,
tciName,
tciPrimaryKey,
tciUniqueConstraints,
tciUniqueOrPrimaryKeyConstraints,
tciViewInfo,
tiAdminRolePermInfo,
tiCoreInfo,
tiEventTriggerInfoMap,
tiName,
tiRolePermInfoMap,
_FIColumn,
_FIComputedField,
_FIRelationship,
_FIRemoteRelationship,
)
where
import Control.Lens hiding ((.=))
import Data.Aeson.Casing
import Data.Aeson.Extended
import Data.Aeson.TH
import Data.Aeson.Types (Parser, prependFailure, typeMismatch)
import Data.HashMap.Strict qualified as M
import Data.HashMap.Strict.Extended qualified as M
import Data.HashMap.Strict.NonEmpty (NEHashMap)
import Data.HashMap.Strict.NonEmpty qualified as NEHashMap
import Data.HashSet qualified as HS
import Data.List.Extended (duplicates)
import Data.List.NonEmpty qualified as NE
import Data.Semigroup (Any (..), Max (..))
import Data.Text qualified as T
import Data.Text.Extended
import Hasura.Backends.Postgres.SQL.Types qualified as PG (PGDescription)
import Hasura.Base.Error
import Hasura.Incremental (Cacheable)
import Hasura.Name qualified as Name
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.ComputedField
import Hasura.RQL.Types.EventTrigger
import Hasura.RQL.Types.Permission (AllowedRootFields (..), QueryRootFieldType (..), SubscriptionRootFieldType (..))
import Hasura.RQL.Types.Relationships.Local
import Hasura.RQL.Types.Relationships.Remote
import Hasura.SQL.AnyBackend (runBackend)
import Hasura.SQL.Backend
import Hasura.Server.Utils (englishList)
import Hasura.Session
import Language.GraphQL.Draft.Syntax qualified as G
data CustomRootField = CustomRootField
{ CustomRootField -> Maybe Name
_crfName :: Maybe G.Name,
:: Comment
}
deriving (Int -> CustomRootField -> ShowS
[CustomRootField] -> ShowS
CustomRootField -> String
(Int -> CustomRootField -> ShowS)
-> (CustomRootField -> String)
-> ([CustomRootField] -> ShowS)
-> Show CustomRootField
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomRootField] -> ShowS
$cshowList :: [CustomRootField] -> ShowS
show :: CustomRootField -> String
$cshow :: CustomRootField -> String
showsPrec :: Int -> CustomRootField -> ShowS
$cshowsPrec :: Int -> CustomRootField -> ShowS
Show, CustomRootField -> CustomRootField -> Bool
(CustomRootField -> CustomRootField -> Bool)
-> (CustomRootField -> CustomRootField -> Bool)
-> Eq CustomRootField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomRootField -> CustomRootField -> Bool
$c/= :: CustomRootField -> CustomRootField -> Bool
== :: CustomRootField -> CustomRootField -> Bool
$c== :: CustomRootField -> CustomRootField -> Bool
Eq, (forall x. CustomRootField -> Rep CustomRootField x)
-> (forall x. Rep CustomRootField x -> CustomRootField)
-> Generic CustomRootField
forall x. Rep CustomRootField x -> CustomRootField
forall x. CustomRootField -> Rep CustomRootField x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomRootField x -> CustomRootField
$cfrom :: forall x. CustomRootField -> Rep CustomRootField x
Generic)
instance NFData CustomRootField
instance Cacheable CustomRootField
instance FromJSON CustomRootField where
parseJSON :: Value -> Parser CustomRootField
parseJSON = \case
Value
Null -> CustomRootField -> Parser CustomRootField
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CustomRootField -> Parser CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a b. (a -> b) -> a -> b
$ Maybe Name -> Comment -> CustomRootField
CustomRootField Maybe Name
forall a. Maybe a
Nothing Comment
Automatic
String Text
text -> CustomRootField -> Parser CustomRootField
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CustomRootField -> Parser CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a b. (a -> b) -> a -> b
$ Maybe Name -> Comment -> CustomRootField
CustomRootField (Text -> Maybe Name
G.mkName Text
text) Comment
Automatic
Object Object
obj ->
Maybe Name -> Comment -> CustomRootField
CustomRootField
(Maybe Name -> Comment -> CustomRootField)
-> Parser (Maybe Name) -> Parser (Comment -> CustomRootField)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object
obj Object -> Key -> Parser (Maybe Name)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"name")
Parser (Comment -> CustomRootField)
-> Parser Comment -> Parser CustomRootField
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe Comment)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment" Parser (Maybe Comment) -> Comment -> Parser Comment
forall a. Parser (Maybe a) -> a -> Parser a
.!= Comment
Automatic)
Value
val -> String -> Parser CustomRootField -> Parser CustomRootField
forall a. String -> Parser a -> Parser a
prependFailure String
"parsing CustomRootField failed, " (String -> Value -> Parser CustomRootField
forall a. String -> Value -> Parser a
typeMismatch String
"Object, String or Null" Value
val)
instance ToJSON CustomRootField where
toJSON :: CustomRootField -> Value
toJSON (CustomRootField Maybe Name
Nothing Comment
Automatic) = Value
Null
toJSON (CustomRootField (Just Name
name) Comment
Automatic) = Text -> Value
String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Name -> Text
G.unName Name
name
toJSON (CustomRootField Maybe Name
name Comment
comment) =
[Pair] -> Value
object
[ Key
"name" Key -> Maybe Name -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Name
name,
Key
"comment" Key -> Comment -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Comment
comment
]
defaultCustomRootField :: CustomRootField
defaultCustomRootField :: CustomRootField
defaultCustomRootField = Maybe Name -> Comment -> CustomRootField
CustomRootField Maybe Name
forall a. Maybe a
Nothing Comment
Automatic
data TableCustomRootFields = TableCustomRootFields
{ TableCustomRootFields -> CustomRootField
_tcrfSelect :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfSelectByPk :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfSelectAggregate :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfSelectStream :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfInsert :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfInsertOne :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfUpdate :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfUpdateByPk :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfUpdateMany :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfDelete :: CustomRootField,
TableCustomRootFields -> CustomRootField
_tcrfDeleteByPk :: CustomRootField
}
deriving (Int -> TableCustomRootFields -> ShowS
[TableCustomRootFields] -> ShowS
TableCustomRootFields -> String
(Int -> TableCustomRootFields -> ShowS)
-> (TableCustomRootFields -> String)
-> ([TableCustomRootFields] -> ShowS)
-> Show TableCustomRootFields
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TableCustomRootFields] -> ShowS
$cshowList :: [TableCustomRootFields] -> ShowS
show :: TableCustomRootFields -> String
$cshow :: TableCustomRootFields -> String
showsPrec :: Int -> TableCustomRootFields -> ShowS
$cshowsPrec :: Int -> TableCustomRootFields -> ShowS
Show, TableCustomRootFields -> TableCustomRootFields -> Bool
(TableCustomRootFields -> TableCustomRootFields -> Bool)
-> (TableCustomRootFields -> TableCustomRootFields -> Bool)
-> Eq TableCustomRootFields
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TableCustomRootFields -> TableCustomRootFields -> Bool
$c/= :: TableCustomRootFields -> TableCustomRootFields -> Bool
== :: TableCustomRootFields -> TableCustomRootFields -> Bool
$c== :: TableCustomRootFields -> TableCustomRootFields -> Bool
Eq, (forall x. TableCustomRootFields -> Rep TableCustomRootFields x)
-> (forall x. Rep TableCustomRootFields x -> TableCustomRootFields)
-> Generic TableCustomRootFields
forall x. Rep TableCustomRootFields x -> TableCustomRootFields
forall x. TableCustomRootFields -> Rep TableCustomRootFields x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TableCustomRootFields x -> TableCustomRootFields
$cfrom :: forall x. TableCustomRootFields -> Rep TableCustomRootFields x
Generic)
instance NFData TableCustomRootFields
instance Cacheable TableCustomRootFields
instance ToJSON TableCustomRootFields where
toJSON :: TableCustomRootFields -> Value
toJSON TableCustomRootFields {CustomRootField
_tcrfDeleteByPk :: CustomRootField
_tcrfDelete :: CustomRootField
_tcrfUpdateMany :: CustomRootField
_tcrfUpdateByPk :: CustomRootField
_tcrfUpdate :: CustomRootField
_tcrfInsertOne :: CustomRootField
_tcrfInsert :: CustomRootField
_tcrfSelectStream :: CustomRootField
_tcrfSelectAggregate :: CustomRootField
_tcrfSelectByPk :: CustomRootField
_tcrfSelect :: CustomRootField
_tcrfDeleteByPk :: TableCustomRootFields -> CustomRootField
_tcrfDelete :: TableCustomRootFields -> CustomRootField
_tcrfUpdateMany :: TableCustomRootFields -> CustomRootField
_tcrfUpdateByPk :: TableCustomRootFields -> CustomRootField
_tcrfUpdate :: TableCustomRootFields -> CustomRootField
_tcrfInsertOne :: TableCustomRootFields -> CustomRootField
_tcrfInsert :: TableCustomRootFields -> CustomRootField
_tcrfSelectStream :: TableCustomRootFields -> CustomRootField
_tcrfSelectAggregate :: TableCustomRootFields -> CustomRootField
_tcrfSelectByPk :: TableCustomRootFields -> CustomRootField
_tcrfSelect :: TableCustomRootFields -> CustomRootField
..} =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
(Pair -> Bool) -> [Pair] -> [Pair]
forall a. (a -> Bool) -> [a] -> [a]
filter
((Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
/= Value
Null) (Value -> Bool) -> (Pair -> Value) -> Pair -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pair -> Value
forall a b. (a, b) -> b
snd)
[ Key
"select" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfSelect,
Key
"select_by_pk" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfSelectByPk,
Key
"select_aggregate" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfSelectAggregate,
Key
"select_stream" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfSelectStream,
Key
"insert" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfInsert,
Key
"insert_one" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfInsertOne,
Key
"update" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfUpdate,
Key
"update_by_pk" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfUpdateByPk,
Key
"update_many" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfUpdateMany,
Key
"delete" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfDelete,
Key
"delete_by_pk" Key -> CustomRootField -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CustomRootField
_tcrfDeleteByPk
]
instance FromJSON TableCustomRootFields where
parseJSON :: Value -> Parser TableCustomRootFields
parseJSON = String
-> (Object -> Parser TableCustomRootFields)
-> Value
-> Parser TableCustomRootFields
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Object" ((Object -> Parser TableCustomRootFields)
-> Value -> Parser TableCustomRootFields)
-> (Object -> Parser TableCustomRootFields)
-> Value
-> Parser TableCustomRootFields
forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
TableCustomRootFields
tableCustomRootFields <-
CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields
TableCustomRootFields
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"select" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"select_by_pk" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"select_aggregate" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"select_stream" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"insert" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"insert_one" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"update" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField
-> CustomRootField -> CustomRootField -> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"update_by_pk" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField
-> CustomRootField -> CustomRootField -> TableCustomRootFields)
-> Parser CustomRootField
-> Parser
(CustomRootField -> CustomRootField -> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"update_many" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser
(CustomRootField -> CustomRootField -> TableCustomRootFields)
-> Parser CustomRootField
-> Parser (CustomRootField -> TableCustomRootFields)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"delete" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
Parser (CustomRootField -> TableCustomRootFields)
-> Parser CustomRootField -> Parser TableCustomRootFields
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
obj Object -> Key -> Parser (Maybe CustomRootField)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"delete_by_pk" Parser (Maybe CustomRootField)
-> CustomRootField -> Parser CustomRootField
forall a. Parser (Maybe a) -> a -> Parser a
.!= CustomRootField
defaultCustomRootField)
let duplicateRootFields :: [Name]
duplicateRootFields = HashSet Name -> [Name]
forall a. HashSet a -> [a]
HS.toList (HashSet Name -> [Name])
-> ([CustomRootField] -> HashSet Name)
-> [CustomRootField]
-> [Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
duplicates ([Name] -> HashSet Name)
-> ([CustomRootField] -> [Name])
-> [CustomRootField]
-> HashSet Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CustomRootField -> Maybe Name) -> [CustomRootField] -> [Name]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe CustomRootField -> Maybe Name
_crfName ([CustomRootField] -> [Name]) -> [CustomRootField] -> [Name]
forall a b. (a -> b) -> a -> b
$ TableCustomRootFields -> [CustomRootField]
getAllCustomRootFields TableCustomRootFields
tableCustomRootFields
Maybe (NonEmpty Name) -> (NonEmpty Name -> Parser Any) -> Parser ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ ([Name] -> Maybe (NonEmpty Name)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty [Name]
duplicateRootFields) \NonEmpty Name
duplicatedFields ->
String -> Parser Any
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Any) -> (Text -> String) -> Text -> Parser Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text -> Parser Any) -> Text -> Parser Any
forall a b. (a -> b) -> a -> b
$
Text
"the following custom root field names are duplicated: "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> NonEmpty Text -> Text
englishList Text
"and" (Name -> Text
forall a. ToTxt a => a -> Text
toTxt (Name -> Text) -> NonEmpty Name -> NonEmpty Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty Name
duplicatedFields)
TableCustomRootFields -> Parser TableCustomRootFields
forall (f :: * -> *) a. Applicative f => a -> f a
pure TableCustomRootFields
tableCustomRootFields
emptyCustomRootFields :: TableCustomRootFields
emptyCustomRootFields :: TableCustomRootFields
emptyCustomRootFields =
TableCustomRootFields :: CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> CustomRootField
-> TableCustomRootFields
TableCustomRootFields
{ _tcrfSelect :: CustomRootField
_tcrfSelect = CustomRootField
defaultCustomRootField,
_tcrfSelectByPk :: CustomRootField
_tcrfSelectByPk = CustomRootField
defaultCustomRootField,
_tcrfSelectStream :: CustomRootField
_tcrfSelectStream = CustomRootField
defaultCustomRootField,
_tcrfSelectAggregate :: CustomRootField
_tcrfSelectAggregate = CustomRootField
defaultCustomRootField,
_tcrfInsert :: CustomRootField
_tcrfInsert = CustomRootField
defaultCustomRootField,
_tcrfInsertOne :: CustomRootField
_tcrfInsertOne = CustomRootField
defaultCustomRootField,
_tcrfUpdate :: CustomRootField
_tcrfUpdate = CustomRootField
defaultCustomRootField,
_tcrfUpdateByPk :: CustomRootField
_tcrfUpdateByPk = CustomRootField
defaultCustomRootField,
_tcrfUpdateMany :: CustomRootField
_tcrfUpdateMany = CustomRootField
defaultCustomRootField,
_tcrfDelete :: CustomRootField
_tcrfDelete = CustomRootField
defaultCustomRootField,
_tcrfDeleteByPk :: CustomRootField
_tcrfDeleteByPk = CustomRootField
defaultCustomRootField
}
getAllCustomRootFields :: TableCustomRootFields -> [CustomRootField]
getAllCustomRootFields :: TableCustomRootFields -> [CustomRootField]
getAllCustomRootFields TableCustomRootFields {CustomRootField
_tcrfDeleteByPk :: CustomRootField
_tcrfDelete :: CustomRootField
_tcrfUpdateMany :: CustomRootField
_tcrfUpdateByPk :: CustomRootField
_tcrfUpdate :: CustomRootField
_tcrfInsertOne :: CustomRootField
_tcrfInsert :: CustomRootField
_tcrfSelectStream :: CustomRootField
_tcrfSelectAggregate :: CustomRootField
_tcrfSelectByPk :: CustomRootField
_tcrfSelect :: CustomRootField
_tcrfDeleteByPk :: TableCustomRootFields -> CustomRootField
_tcrfDelete :: TableCustomRootFields -> CustomRootField
_tcrfUpdateMany :: TableCustomRootFields -> CustomRootField
_tcrfUpdateByPk :: TableCustomRootFields -> CustomRootField
_tcrfUpdate :: TableCustomRootFields -> CustomRootField
_tcrfInsertOne :: TableCustomRootFields -> CustomRootField
_tcrfInsert :: TableCustomRootFields -> CustomRootField
_tcrfSelectStream :: TableCustomRootFields -> CustomRootField
_tcrfSelectAggregate :: TableCustomRootFields -> CustomRootField
_tcrfSelectByPk :: TableCustomRootFields -> CustomRootField
_tcrfSelect :: TableCustomRootFields -> CustomRootField
..} =
[ CustomRootField
_tcrfSelect,
CustomRootField
_tcrfSelectByPk,
CustomRootField
_tcrfSelectAggregate,
CustomRootField
_tcrfSelectStream,
CustomRootField
_tcrfInsert,
CustomRootField
_tcrfInsertOne,
CustomRootField
_tcrfUpdate,
CustomRootField
_tcrfUpdateByPk,
CustomRootField
_tcrfUpdateMany,
CustomRootField
_tcrfDelete,
CustomRootField
_tcrfDeleteByPk
]
data FieldInfo (b :: BackendType)
= FIColumn (ColumnInfo b)
| FIRelationship (RelInfo b)
| FIComputedField (ComputedFieldInfo b)
| FIRemoteRelationship (RemoteFieldInfo (DBJoinField b))
deriving ((forall x. FieldInfo b -> Rep (FieldInfo b) x)
-> (forall x. Rep (FieldInfo b) x -> FieldInfo b)
-> Generic (FieldInfo b)
forall x. Rep (FieldInfo b) x -> FieldInfo b
forall x. FieldInfo b -> Rep (FieldInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (FieldInfo b) x -> FieldInfo b
forall (b :: BackendType) x. FieldInfo b -> Rep (FieldInfo b) x
$cto :: forall (b :: BackendType) x. Rep (FieldInfo b) x -> FieldInfo b
$cfrom :: forall (b :: BackendType) x. FieldInfo b -> Rep (FieldInfo b) x
Generic)
deriving instance Backend b => Eq (FieldInfo b)
instance Backend b => Cacheable (FieldInfo b)
instance Backend b => ToJSON (FieldInfo b) where
toJSON :: FieldInfo b -> Value
toJSON =
Options -> FieldInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON (Options -> FieldInfo b -> Value)
-> Options -> FieldInfo b -> Value
forall a b. (a -> b) -> a -> b
$
Options
defaultOptions
{ constructorTagModifier :: ShowS
constructorTagModifier = ShowS
snakeCase ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
2,
sumEncoding :: SumEncoding
sumEncoding = String -> String -> SumEncoding
TaggedObject String
"type" String
"detail"
}
$(makePrisms ''FieldInfo)
type FieldInfoMap = M.HashMap FieldName
fieldInfoName :: forall b. Backend b => FieldInfo b -> FieldName
fieldInfoName :: FieldInfo b -> FieldName
fieldInfoName = \case
FIColumn ColumnInfo b
info -> Backend b => Column b -> FieldName
forall (b :: BackendType). Backend b => Column b -> FieldName
fromCol @b (Column b -> FieldName) -> Column b -> FieldName
forall a b. (a -> b) -> a -> b
$ ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ColumnInfo b
info
FIRelationship RelInfo b
info -> RelName -> FieldName
fromRel (RelName -> FieldName) -> RelName -> FieldName
forall a b. (a -> b) -> a -> b
$ RelInfo b -> RelName
forall (b :: BackendType). RelInfo b -> RelName
riName RelInfo b
info
FIComputedField ComputedFieldInfo b
info -> ComputedFieldName -> FieldName
fromComputedField (ComputedFieldName -> FieldName) -> ComputedFieldName -> FieldName
forall a b. (a -> b) -> a -> b
$ ComputedFieldInfo b -> ComputedFieldName
forall (b :: BackendType). ComputedFieldInfo b -> ComputedFieldName
_cfiName ComputedFieldInfo b
info
FIRemoteRelationship RemoteFieldInfo (DBJoinField b)
info -> RelName -> FieldName
fromRemoteRelationship (RelName -> FieldName) -> RelName -> FieldName
forall a b. (a -> b) -> a -> b
$ RemoteFieldInfo (DBJoinField b) -> RelName
forall lhsJoinField. RemoteFieldInfo lhsJoinField -> RelName
getRemoteFieldInfoName RemoteFieldInfo (DBJoinField b)
info
fieldInfoGraphQLName :: FieldInfo b -> Maybe G.Name
fieldInfoGraphQLName :: FieldInfo b -> Maybe Name
fieldInfoGraphQLName = \case
FIColumn ColumnInfo b
info -> Name -> Maybe Name
forall a. a -> Maybe a
Just (Name -> Maybe Name) -> Name -> Maybe Name
forall a b. (a -> b) -> a -> b
$ ColumnInfo b -> Name
forall (b :: BackendType). ColumnInfo b -> Name
ciName ColumnInfo b
info
FIRelationship RelInfo b
info -> Text -> Maybe Name
G.mkName (Text -> Maybe Name) -> Text -> Maybe Name
forall a b. (a -> b) -> a -> b
$ RelName -> Text
relNameToTxt (RelName -> Text) -> RelName -> Text
forall a b. (a -> b) -> a -> b
$ RelInfo b -> RelName
forall (b :: BackendType). RelInfo b -> RelName
riName RelInfo b
info
FIComputedField ComputedFieldInfo b
info -> Text -> Maybe Name
G.mkName (Text -> Maybe Name) -> Text -> Maybe Name
forall a b. (a -> b) -> a -> b
$ ComputedFieldName -> Text
computedFieldNameToText (ComputedFieldName -> Text) -> ComputedFieldName -> Text
forall a b. (a -> b) -> a -> b
$ ComputedFieldInfo b -> ComputedFieldName
forall (b :: BackendType). ComputedFieldInfo b -> ComputedFieldName
_cfiName ComputedFieldInfo b
info
FIRemoteRelationship RemoteFieldInfo (DBJoinField b)
info -> Text -> Maybe Name
G.mkName (Text -> Maybe Name) -> Text -> Maybe Name
forall a b. (a -> b) -> a -> b
$ RelName -> Text
relNameToTxt (RelName -> Text) -> RelName -> Text
forall a b. (a -> b) -> a -> b
$ RemoteFieldInfo (DBJoinField b) -> RelName
forall lhsJoinField. RemoteFieldInfo lhsJoinField -> RelName
getRemoteFieldInfoName RemoteFieldInfo (DBJoinField b)
info
getRemoteFieldInfoName :: RemoteFieldInfo lhsJoinField -> RelName
getRemoteFieldInfoName :: RemoteFieldInfo lhsJoinField -> RelName
getRemoteFieldInfoName RemoteFieldInfo {RemoteFieldInfoRHS
_rfiRHS :: forall lhsJoinField.
RemoteFieldInfo lhsJoinField -> RemoteFieldInfoRHS
_rfiRHS :: RemoteFieldInfoRHS
_rfiRHS} = case RemoteFieldInfoRHS
_rfiRHS of
RFISchema RemoteSchemaFieldInfo
schema -> RemoteSchemaFieldInfo -> RelName
_rrfiName RemoteSchemaFieldInfo
schema
RFISource AnyBackend RemoteSourceFieldInfo
source -> AnyBackend RemoteSourceFieldInfo
-> (forall (b :: BackendType). RemoteSourceFieldInfo b -> RelName)
-> RelName
forall (i :: BackendType -> *) r.
AnyBackend i -> (forall (b :: BackendType). i b -> r) -> r
runBackend AnyBackend RemoteSourceFieldInfo
source forall (b :: BackendType). RemoteSourceFieldInfo b -> RelName
_rsfiName
fieldInfoGraphQLNames :: FieldInfo b -> [G.Name]
fieldInfoGraphQLNames :: FieldInfo b -> [Name]
fieldInfoGraphQLNames FieldInfo b
info = case FieldInfo b
info of
FIColumn ColumnInfo b
_ -> Maybe Name -> [Name]
forall a. Maybe a -> [a]
maybeToList (Maybe Name -> [Name]) -> Maybe Name -> [Name]
forall a b. (a -> b) -> a -> b
$ FieldInfo b -> Maybe Name
forall (b :: BackendType). FieldInfo b -> Maybe Name
fieldInfoGraphQLName FieldInfo b
info
FIRelationship RelInfo b
relationshipInfo -> Maybe [Name] -> [Name]
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold do
Name
name <- FieldInfo b -> Maybe Name
forall (b :: BackendType). FieldInfo b -> Maybe Name
fieldInfoGraphQLName FieldInfo b
info
[Name] -> Maybe [Name]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Name] -> Maybe [Name]) -> [Name] -> Maybe [Name]
forall a b. (a -> b) -> a -> b
$ case RelInfo b -> RelType
forall (b :: BackendType). RelInfo b -> RelType
riType RelInfo b
relationshipInfo of
RelType
ObjRel -> [Name
name]
RelType
ArrRel -> [Name
name, Name
name Name -> Name -> Name
forall a. Semigroup a => a -> a -> a
<> Name
Name.__aggregate]
FIComputedField ComputedFieldInfo b
_ -> Maybe Name -> [Name]
forall a. Maybe a -> [a]
maybeToList (Maybe Name -> [Name]) -> Maybe Name -> [Name]
forall a b. (a -> b) -> a -> b
$ FieldInfo b -> Maybe Name
forall (b :: BackendType). FieldInfo b -> Maybe Name
fieldInfoGraphQLName FieldInfo b
info
FIRemoteRelationship RemoteFieldInfo (DBJoinField b)
_ -> Maybe Name -> [Name]
forall a. Maybe a -> [a]
maybeToList (Maybe Name -> [Name]) -> Maybe Name -> [Name]
forall a b. (a -> b) -> a -> b
$ FieldInfo b -> Maybe Name
forall (b :: BackendType). FieldInfo b -> Maybe Name
fieldInfoGraphQLName FieldInfo b
info
getCols :: FieldInfoMap (FieldInfo backend) -> [ColumnInfo backend]
getCols :: FieldInfoMap (FieldInfo backend) -> [ColumnInfo backend]
getCols = (FieldInfo backend -> Maybe (ColumnInfo backend))
-> [FieldInfo backend] -> [ColumnInfo backend]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (FieldInfo backend
-> Getting
(First (ColumnInfo backend))
(FieldInfo backend)
(ColumnInfo backend)
-> Maybe (ColumnInfo backend)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
(First (ColumnInfo backend))
(FieldInfo backend)
(ColumnInfo backend)
forall (b :: BackendType). Prism' (FieldInfo b) (ColumnInfo b)
_FIColumn) ([FieldInfo backend] -> [ColumnInfo backend])
-> (FieldInfoMap (FieldInfo backend) -> [FieldInfo backend])
-> FieldInfoMap (FieldInfo backend)
-> [ColumnInfo backend]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldInfoMap (FieldInfo backend) -> [FieldInfo backend]
forall k v. HashMap k v -> [v]
M.elems
sortCols :: [ColumnInfo backend] -> [ColumnInfo backend]
sortCols :: [ColumnInfo backend] -> [ColumnInfo backend]
sortCols = (ColumnInfo backend -> ColumnInfo backend -> Ordering)
-> [ColumnInfo backend] -> [ColumnInfo backend]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (\ColumnInfo backend
l ColumnInfo backend
r -> Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (ColumnInfo backend -> Int
forall (b :: BackendType). ColumnInfo b -> Int
ciPosition ColumnInfo backend
l) (ColumnInfo backend -> Int
forall (b :: BackendType). ColumnInfo b -> Int
ciPosition ColumnInfo backend
r))
getRels :: FieldInfoMap (FieldInfo backend) -> [RelInfo backend]
getRels :: FieldInfoMap (FieldInfo backend) -> [RelInfo backend]
getRels = (FieldInfo backend -> Maybe (RelInfo backend))
-> [FieldInfo backend] -> [RelInfo backend]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (FieldInfo backend
-> Getting
(First (RelInfo backend)) (FieldInfo backend) (RelInfo backend)
-> Maybe (RelInfo backend)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
(First (RelInfo backend)) (FieldInfo backend) (RelInfo backend)
forall (b :: BackendType). Prism' (FieldInfo b) (RelInfo b)
_FIRelationship) ([FieldInfo backend] -> [RelInfo backend])
-> (FieldInfoMap (FieldInfo backend) -> [FieldInfo backend])
-> FieldInfoMap (FieldInfo backend)
-> [RelInfo backend]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldInfoMap (FieldInfo backend) -> [FieldInfo backend]
forall k v. HashMap k v -> [v]
M.elems
getComputedFieldInfos :: FieldInfoMap (FieldInfo backend) -> [ComputedFieldInfo backend]
getComputedFieldInfos :: FieldInfoMap (FieldInfo backend) -> [ComputedFieldInfo backend]
getComputedFieldInfos = (FieldInfo backend -> Maybe (ComputedFieldInfo backend))
-> [FieldInfo backend] -> [ComputedFieldInfo backend]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (FieldInfo backend
-> Getting
(First (ComputedFieldInfo backend))
(FieldInfo backend)
(ComputedFieldInfo backend)
-> Maybe (ComputedFieldInfo backend)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
(First (ComputedFieldInfo backend))
(FieldInfo backend)
(ComputedFieldInfo backend)
forall (b :: BackendType).
Prism' (FieldInfo b) (ComputedFieldInfo b)
_FIComputedField) ([FieldInfo backend] -> [ComputedFieldInfo backend])
-> (FieldInfoMap (FieldInfo backend) -> [FieldInfo backend])
-> FieldInfoMap (FieldInfo backend)
-> [ComputedFieldInfo backend]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldInfoMap (FieldInfo backend) -> [FieldInfo backend]
forall k v. HashMap k v -> [v]
M.elems
data InsPermInfo (b :: BackendType) = InsPermInfo
{ InsPermInfo b -> HashSet (Column b)
ipiCols :: HS.HashSet (Column b),
InsPermInfo b -> AnnBoolExpPartialSQL b
ipiCheck :: AnnBoolExpPartialSQL b,
InsPermInfo b -> PreSetColsPartial b
ipiSet :: PreSetColsPartial b,
InsPermInfo b -> Bool
ipiBackendOnly :: Bool,
:: HS.HashSet Text
}
deriving ((forall x. InsPermInfo b -> Rep (InsPermInfo b) x)
-> (forall x. Rep (InsPermInfo b) x -> InsPermInfo b)
-> Generic (InsPermInfo b)
forall x. Rep (InsPermInfo b) x -> InsPermInfo b
forall x. InsPermInfo b -> Rep (InsPermInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (InsPermInfo b) x -> InsPermInfo b
forall (b :: BackendType) x. InsPermInfo b -> Rep (InsPermInfo b) x
$cto :: forall (b :: BackendType) x. Rep (InsPermInfo b) x -> InsPermInfo b
$cfrom :: forall (b :: BackendType) x. InsPermInfo b -> Rep (InsPermInfo b) x
Generic)
deriving instance
( Backend b,
Eq (AnnBoolExpPartialSQL b)
) =>
Eq (InsPermInfo b)
deriving instance
( Backend b,
Show (AnnBoolExpPartialSQL b)
) =>
Show (InsPermInfo b)
instance
( Backend b,
NFData (AnnBoolExpPartialSQL b),
NFData (PreSetColsPartial b)
) =>
NFData (InsPermInfo b)
instance
( Backend b,
Cacheable (AnnBoolExpPartialSQL b),
Cacheable (PreSetColsPartial b)
) =>
Cacheable (InsPermInfo b)
instance
( Backend b,
ToJSON (AnnBoolExpPartialSQL b)
) =>
ToJSON (InsPermInfo b)
where
toJSON :: InsPermInfo b -> Value
toJSON = Options -> InsPermInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
data CombinedSelPermInfo (b :: BackendType) = CombinedSelPermInfo
{ CombinedSelPermInfo b
-> [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiCols :: [(M.HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b)))],
CombinedSelPermInfo b
-> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiComputedFields :: [(M.HashMap ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b)))],
CombinedSelPermInfo b -> [AnnBoolExpPartialSQL b]
cspiFilter :: [(AnnBoolExpPartialSQL b)],
CombinedSelPermInfo b -> Maybe (Max Int)
cspiLimit :: Maybe (Max Int),
CombinedSelPermInfo b -> Any
cspiAllowAgg :: Any,
:: HS.HashSet Text,
CombinedSelPermInfo b -> AllowedRootFields QueryRootFieldType
cspiAllowedQueryRootFieldTypes :: AllowedRootFields QueryRootFieldType,
CombinedSelPermInfo b
-> AllowedRootFields SubscriptionRootFieldType
cspiAllowedSubscriptionRootFieldTypes :: AllowedRootFields SubscriptionRootFieldType
}
instance (Backend b) => Semigroup (CombinedSelPermInfo b) where
CombinedSelPermInfo [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
colsL [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
scalarComputedFieldsL [AnnBoolExpPartialSQL b]
filterL Maybe (Max Int)
limitL Any
allowAggL HashSet Text
reqHeadersL AllowedRootFields QueryRootFieldType
allowedQueryRFTypesL AllowedRootFields SubscriptionRootFieldType
allowedSubsRFTypesL
<> :: CombinedSelPermInfo b
-> CombinedSelPermInfo b -> CombinedSelPermInfo b
<> CombinedSelPermInfo [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
colsR [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
scalarComputedFieldsR [AnnBoolExpPartialSQL b]
filterR Maybe (Max Int)
limitR Any
allowAggR HashSet Text
reqHeadersR AllowedRootFields QueryRootFieldType
allowedQueryRFTypesR AllowedRootFields SubscriptionRootFieldType
allowedSubsRFTypesR =
[HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [AnnBoolExpPartialSQL b]
-> Maybe (Max Int)
-> Any
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> CombinedSelPermInfo b
forall (b :: BackendType).
[HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [AnnBoolExpPartialSQL b]
-> Maybe (Max Int)
-> Any
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> CombinedSelPermInfo b
CombinedSelPermInfo
([HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
colsL [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
forall a. Semigroup a => a -> a -> a
<> [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
colsR)
([HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
scalarComputedFieldsL [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
forall a. Semigroup a => a -> a -> a
<> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
scalarComputedFieldsR)
([AnnBoolExpPartialSQL b]
filterL [AnnBoolExpPartialSQL b]
-> [AnnBoolExpPartialSQL b] -> [AnnBoolExpPartialSQL b]
forall a. Semigroup a => a -> a -> a
<> [AnnBoolExpPartialSQL b]
filterR)
(Maybe (Max Int)
limitL Maybe (Max Int) -> Maybe (Max Int) -> Maybe (Max Int)
forall a. Semigroup a => a -> a -> a
<> Maybe (Max Int)
limitR)
(Any
allowAggL Any -> Any -> Any
forall a. Semigroup a => a -> a -> a
<> Any
allowAggR)
(HashSet Text
reqHeadersL HashSet Text -> HashSet Text -> HashSet Text
forall a. Semigroup a => a -> a -> a
<> HashSet Text
reqHeadersR)
(AllowedRootFields QueryRootFieldType
allowedQueryRFTypesL AllowedRootFields QueryRootFieldType
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields QueryRootFieldType
forall a. Semigroup a => a -> a -> a
<> AllowedRootFields QueryRootFieldType
allowedQueryRFTypesR)
(AllowedRootFields SubscriptionRootFieldType
allowedSubsRFTypesL AllowedRootFields SubscriptionRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
forall a. Semigroup a => a -> a -> a
<> AllowedRootFields SubscriptionRootFieldType
allowedSubsRFTypesR)
combinedSelPermInfoToSelPermInfo ::
Backend b =>
Int ->
CombinedSelPermInfo b ->
SelPermInfo b
combinedSelPermInfoToSelPermInfo :: Int -> CombinedSelPermInfo b -> SelPermInfo b
combinedSelPermInfoToSelPermInfo Int
selPermsCount CombinedSelPermInfo {[HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
[HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
[AnnBoolExpPartialSQL b]
Maybe (Max Int)
Any
HashSet Text
AllowedRootFields SubscriptionRootFieldType
AllowedRootFields QueryRootFieldType
cspiAllowedSubscriptionRootFieldTypes :: AllowedRootFields SubscriptionRootFieldType
cspiAllowedQueryRootFieldTypes :: AllowedRootFields QueryRootFieldType
cspiRequiredHeaders :: HashSet Text
cspiAllowAgg :: Any
cspiLimit :: Maybe (Max Int)
cspiFilter :: [AnnBoolExpPartialSQL b]
cspiComputedFields :: [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiCols :: [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiAllowedSubscriptionRootFieldTypes :: forall (b :: BackendType).
CombinedSelPermInfo b
-> AllowedRootFields SubscriptionRootFieldType
cspiAllowedQueryRootFieldTypes :: forall (b :: BackendType).
CombinedSelPermInfo b -> AllowedRootFields QueryRootFieldType
cspiRequiredHeaders :: forall (b :: BackendType). CombinedSelPermInfo b -> HashSet Text
cspiAllowAgg :: forall (b :: BackendType). CombinedSelPermInfo b -> Any
cspiLimit :: forall (b :: BackendType). CombinedSelPermInfo b -> Maybe (Max Int)
cspiFilter :: forall (b :: BackendType).
CombinedSelPermInfo b -> [AnnBoolExpPartialSQL b]
cspiComputedFields :: forall (b :: BackendType).
CombinedSelPermInfo b
-> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiCols :: forall (b :: BackendType).
CombinedSelPermInfo b
-> [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
..} =
HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> AnnBoolExpPartialSQL b
-> Maybe Int
-> Bool
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> SelPermInfo b
forall (b :: BackendType).
HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> AnnBoolExpPartialSQL b
-> Maybe Int
-> Bool
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> SelPermInfo b
SelPermInfo
(NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
forall (b :: BackendType).
NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
mergeColumnsWithBoolExp (NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> HashMap
(Column b) (NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b)))
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> HashMap
(Column b) (NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b)))
forall k (t :: * -> *) v.
(Eq k, Hashable k, Foldable t) =>
t (HashMap k v) -> HashMap k (NonEmpty v)
M.unionsAll [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiCols)
(NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
forall (b :: BackendType).
NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
mergeColumnsWithBoolExp (NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> HashMap
ComputedFieldName
(NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b)))
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> HashMap
ComputedFieldName
(NonEmpty (Maybe (AnnColumnCaseBoolExpPartialSQL b)))
forall k (t :: * -> *) v.
(Eq k, Hashable k, Foldable t) =>
t (HashMap k v) -> HashMap k (NonEmpty v)
M.unionsAll [HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
cspiComputedFields)
([AnnBoolExpPartialSQL b] -> AnnBoolExpPartialSQL b
forall (backend :: BackendType) field.
[GBoolExp backend field] -> GBoolExp backend field
BoolOr [AnnBoolExpPartialSQL b]
cspiFilter)
(Max Int -> Int
forall a. Max a -> a
getMax (Max Int -> Int) -> Maybe (Max Int) -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Max Int)
cspiLimit)
(Any -> Bool
getAny Any
cspiAllowAgg)
HashSet Text
cspiRequiredHeaders
AllowedRootFields QueryRootFieldType
cspiAllowedQueryRootFieldTypes
AllowedRootFields SubscriptionRootFieldType
cspiAllowedSubscriptionRootFieldTypes
where
mergeColumnsWithBoolExp ::
NonEmpty (Maybe (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))) ->
Maybe (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
mergeColumnsWithBoolExp :: NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
mergeColumnsWithBoolExp NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
booleanExpressions
| Int
selPermsCount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
booleanExpressions = Maybe (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
forall a. Maybe a
Nothing
| Bool
otherwise =
let nonNothingBoolExps :: [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
nonNothingBoolExps = [Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))]
-> [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))]
-> [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))])
-> [Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))]
-> [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
forall a b. (a -> b) -> a -> b
$ NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> [Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty
(Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
booleanExpressions
in Maybe (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
-> Bool
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
forall a. a -> a -> Bool -> a
bool (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
forall a. a -> Maybe a
Just (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
forall a b. (a -> b) -> a -> b
$ [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
-> GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))
forall (backend :: BackendType) field.
[GBoolExp backend field] -> GBoolExp backend field
BoolOr [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
nonNothingBoolExps) Maybe (GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
forall a. Maybe a
Nothing (Bool
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))))
-> Bool
-> Maybe
(GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b)))
forall a b. (a -> b) -> a -> b
$ [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
-> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GBoolExp b (AnnColumnCaseBoolExpField b (PartialSQLExp b))]
nonNothingBoolExps
data SelPermInfo (b :: BackendType) = SelPermInfo
{
SelPermInfo b
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiCols :: M.HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b)),
SelPermInfo b
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiComputedFields :: M.HashMap ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b)),
SelPermInfo b -> AnnBoolExpPartialSQL b
spiFilter :: AnnBoolExpPartialSQL b,
SelPermInfo b -> Maybe Int
spiLimit :: Maybe Int,
SelPermInfo b -> Bool
spiAllowAgg :: Bool,
:: HashSet Text,
SelPermInfo b -> AllowedRootFields QueryRootFieldType
spiAllowedQueryRootFields :: AllowedRootFields QueryRootFieldType,
SelPermInfo b -> AllowedRootFields SubscriptionRootFieldType
spiAllowedSubscriptionRootFields :: AllowedRootFields SubscriptionRootFieldType
}
deriving ((forall x. SelPermInfo b -> Rep (SelPermInfo b) x)
-> (forall x. Rep (SelPermInfo b) x -> SelPermInfo b)
-> Generic (SelPermInfo b)
forall x. Rep (SelPermInfo b) x -> SelPermInfo b
forall x. SelPermInfo b -> Rep (SelPermInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (SelPermInfo b) x -> SelPermInfo b
forall (b :: BackendType) x. SelPermInfo b -> Rep (SelPermInfo b) x
$cto :: forall (b :: BackendType) x. Rep (SelPermInfo b) x -> SelPermInfo b
$cfrom :: forall (b :: BackendType) x. SelPermInfo b -> Rep (SelPermInfo b) x
Generic)
deriving instance
( Backend b,
Eq (AnnBoolExpPartialSQL b),
Eq (AnnColumnCaseBoolExpPartialSQL b)
) =>
Eq (SelPermInfo b)
deriving instance
( Backend b,
Show (AnnBoolExpPartialSQL b),
Show (AnnColumnCaseBoolExpPartialSQL b)
) =>
Show (SelPermInfo b)
instance
( Backend b,
NFData (AnnBoolExpPartialSQL b),
NFData (AnnColumnCaseBoolExpPartialSQL b)
) =>
NFData (SelPermInfo b)
instance
( Backend b,
Cacheable (AnnBoolExpPartialSQL b),
Cacheable (AnnColumnCaseBoolExpPartialSQL b)
) =>
Cacheable (SelPermInfo b)
instance
( Backend b,
ToJSON (AnnBoolExpPartialSQL b),
ToJSON (AnnColumnCaseBoolExpPartialSQL b)
) =>
ToJSON (SelPermInfo b)
where
toJSON :: SelPermInfo b -> Value
toJSON = Options -> SelPermInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
data UpdPermInfo (b :: BackendType) = UpdPermInfo
{ UpdPermInfo b -> HashSet (Column b)
upiCols :: HS.HashSet (Column b),
UpdPermInfo b -> TableName b
upiTable :: TableName b,
UpdPermInfo b -> AnnBoolExpPartialSQL b
upiFilter :: AnnBoolExpPartialSQL b,
UpdPermInfo b -> Maybe (AnnBoolExpPartialSQL b)
upiCheck :: Maybe (AnnBoolExpPartialSQL b),
UpdPermInfo b -> PreSetColsPartial b
upiSet :: PreSetColsPartial b,
UpdPermInfo b -> Bool
upiBackendOnly :: Bool,
:: HashSet Text
}
deriving ((forall x. UpdPermInfo b -> Rep (UpdPermInfo b) x)
-> (forall x. Rep (UpdPermInfo b) x -> UpdPermInfo b)
-> Generic (UpdPermInfo b)
forall x. Rep (UpdPermInfo b) x -> UpdPermInfo b
forall x. UpdPermInfo b -> Rep (UpdPermInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (UpdPermInfo b) x -> UpdPermInfo b
forall (b :: BackendType) x. UpdPermInfo b -> Rep (UpdPermInfo b) x
$cto :: forall (b :: BackendType) x. Rep (UpdPermInfo b) x -> UpdPermInfo b
$cfrom :: forall (b :: BackendType) x. UpdPermInfo b -> Rep (UpdPermInfo b) x
Generic)
deriving instance
( Backend b,
Eq (AnnBoolExpPartialSQL b)
) =>
Eq (UpdPermInfo b)
deriving instance
( Backend b,
Show (AnnBoolExpPartialSQL b)
) =>
Show (UpdPermInfo b)
instance
( Backend b,
NFData (AnnBoolExpPartialSQL b),
NFData (PreSetColsPartial b)
) =>
NFData (UpdPermInfo b)
instance
( Backend b,
Cacheable (AnnBoolExpPartialSQL b),
Cacheable (PreSetColsPartial b)
) =>
Cacheable (UpdPermInfo b)
instance
( Backend b,
ToJSON (AnnBoolExpPartialSQL b)
) =>
ToJSON (UpdPermInfo b)
where
toJSON :: UpdPermInfo b -> Value
toJSON = Options -> UpdPermInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
data DelPermInfo (b :: BackendType) = DelPermInfo
{ DelPermInfo b -> TableName b
dpiTable :: TableName b,
DelPermInfo b -> AnnBoolExpPartialSQL b
dpiFilter :: AnnBoolExpPartialSQL b,
DelPermInfo b -> Bool
dpiBackendOnly :: !Bool,
:: HashSet Text
}
deriving ((forall x. DelPermInfo b -> Rep (DelPermInfo b) x)
-> (forall x. Rep (DelPermInfo b) x -> DelPermInfo b)
-> Generic (DelPermInfo b)
forall x. Rep (DelPermInfo b) x -> DelPermInfo b
forall x. DelPermInfo b -> Rep (DelPermInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (DelPermInfo b) x -> DelPermInfo b
forall (b :: BackendType) x. DelPermInfo b -> Rep (DelPermInfo b) x
$cto :: forall (b :: BackendType) x. Rep (DelPermInfo b) x -> DelPermInfo b
$cfrom :: forall (b :: BackendType) x. DelPermInfo b -> Rep (DelPermInfo b) x
Generic)
deriving instance
( Backend b,
Eq (AnnBoolExpPartialSQL b)
) =>
Eq (DelPermInfo b)
deriving instance
( Backend b,
Show (AnnBoolExpPartialSQL b)
) =>
Show (DelPermInfo b)
instance
( Backend b,
NFData (AnnBoolExpPartialSQL b)
) =>
NFData (DelPermInfo b)
instance
( Backend b,
Cacheable (AnnBoolExpPartialSQL b)
) =>
Cacheable (DelPermInfo b)
instance
( Backend b,
ToJSON (AnnBoolExpPartialSQL b)
) =>
ToJSON (DelPermInfo b)
where
toJSON :: DelPermInfo b -> Value
toJSON = Options -> DelPermInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
data RolePermInfo (b :: BackendType) = RolePermInfo
{ RolePermInfo b -> Maybe (InsPermInfo b)
_permIns :: Maybe (InsPermInfo b),
RolePermInfo b -> Maybe (SelPermInfo b)
_permSel :: Maybe (SelPermInfo b),
RolePermInfo b -> Maybe (UpdPermInfo b)
_permUpd :: Maybe (UpdPermInfo b),
RolePermInfo b -> Maybe (DelPermInfo b)
_permDel :: Maybe (DelPermInfo b)
}
deriving ((forall x. RolePermInfo b -> Rep (RolePermInfo b) x)
-> (forall x. Rep (RolePermInfo b) x -> RolePermInfo b)
-> Generic (RolePermInfo b)
forall x. Rep (RolePermInfo b) x -> RolePermInfo b
forall x. RolePermInfo b -> Rep (RolePermInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x.
Rep (RolePermInfo b) x -> RolePermInfo b
forall (b :: BackendType) x.
RolePermInfo b -> Rep (RolePermInfo b) x
$cto :: forall (b :: BackendType) x.
Rep (RolePermInfo b) x -> RolePermInfo b
$cfrom :: forall (b :: BackendType) x.
RolePermInfo b -> Rep (RolePermInfo b) x
Generic)
instance
( Backend b,
NFData (InsPermInfo b),
NFData (SelPermInfo b),
NFData (UpdPermInfo b),
NFData (DelPermInfo b)
) =>
NFData (RolePermInfo b)
instance
( Backend b,
ToJSON (InsPermInfo b),
ToJSON (SelPermInfo b),
ToJSON (UpdPermInfo b),
ToJSON (DelPermInfo b)
) =>
ToJSON (RolePermInfo b)
where
toJSON :: RolePermInfo b -> Value
toJSON = Options -> RolePermInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
makeLenses ''RolePermInfo
type RolePermInfoMap b = M.HashMap RoleName (RolePermInfo b)
data ViewInfo = ViewInfo
{ ViewInfo -> Bool
viIsUpdatable :: Bool,
ViewInfo -> Bool
viIsDeletable :: Bool,
ViewInfo -> Bool
viIsInsertable :: Bool
}
deriving (Int -> ViewInfo -> ShowS
[ViewInfo] -> ShowS
ViewInfo -> String
(Int -> ViewInfo -> ShowS)
-> (ViewInfo -> String) -> ([ViewInfo] -> ShowS) -> Show ViewInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ViewInfo] -> ShowS
$cshowList :: [ViewInfo] -> ShowS
show :: ViewInfo -> String
$cshow :: ViewInfo -> String
showsPrec :: Int -> ViewInfo -> ShowS
$cshowsPrec :: Int -> ViewInfo -> ShowS
Show, ViewInfo -> ViewInfo -> Bool
(ViewInfo -> ViewInfo -> Bool)
-> (ViewInfo -> ViewInfo -> Bool) -> Eq ViewInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ViewInfo -> ViewInfo -> Bool
$c/= :: ViewInfo -> ViewInfo -> Bool
== :: ViewInfo -> ViewInfo -> Bool
$c== :: ViewInfo -> ViewInfo -> Bool
Eq, (forall x. ViewInfo -> Rep ViewInfo x)
-> (forall x. Rep ViewInfo x -> ViewInfo) -> Generic ViewInfo
forall x. Rep ViewInfo x -> ViewInfo
forall x. ViewInfo -> Rep ViewInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ViewInfo x -> ViewInfo
$cfrom :: forall x. ViewInfo -> Rep ViewInfo x
Generic)
instance NFData ViewInfo
instance Cacheable ViewInfo
$(deriveJSON hasuraJSON ''ViewInfo)
isMutable :: (ViewInfo -> Bool) -> Maybe ViewInfo -> Bool
isMutable :: (ViewInfo -> Bool) -> Maybe ViewInfo -> Bool
isMutable ViewInfo -> Bool
_ Maybe ViewInfo
Nothing = Bool
True
isMutable ViewInfo -> Bool
f (Just ViewInfo
vi) = ViewInfo -> Bool
f ViewInfo
vi
data ColumnConfig = ColumnConfig
{ ColumnConfig -> Maybe Name
_ccfgCustomName :: Maybe G.Name,
:: Comment
}
deriving stock (ColumnConfig -> ColumnConfig -> Bool
(ColumnConfig -> ColumnConfig -> Bool)
-> (ColumnConfig -> ColumnConfig -> Bool) -> Eq ColumnConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnConfig -> ColumnConfig -> Bool
$c/= :: ColumnConfig -> ColumnConfig -> Bool
== :: ColumnConfig -> ColumnConfig -> Bool
$c== :: ColumnConfig -> ColumnConfig -> Bool
Eq, Int -> ColumnConfig -> ShowS
[ColumnConfig] -> ShowS
ColumnConfig -> String
(Int -> ColumnConfig -> ShowS)
-> (ColumnConfig -> String)
-> ([ColumnConfig] -> ShowS)
-> Show ColumnConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnConfig] -> ShowS
$cshowList :: [ColumnConfig] -> ShowS
show :: ColumnConfig -> String
$cshow :: ColumnConfig -> String
showsPrec :: Int -> ColumnConfig -> ShowS
$cshowsPrec :: Int -> ColumnConfig -> ShowS
Show, (forall x. ColumnConfig -> Rep ColumnConfig x)
-> (forall x. Rep ColumnConfig x -> ColumnConfig)
-> Generic ColumnConfig
forall x. Rep ColumnConfig x -> ColumnConfig
forall x. ColumnConfig -> Rep ColumnConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ColumnConfig x -> ColumnConfig
$cfrom :: forall x. ColumnConfig -> Rep ColumnConfig x
Generic)
instance NFData ColumnConfig
instance Cacheable ColumnConfig
instance ToJSON ColumnConfig where
toJSON :: ColumnConfig -> Value
toJSON ColumnConfig {Maybe Name
Comment
_ccfgComment :: Comment
_ccfgCustomName :: Maybe Name
_ccfgComment :: ColumnConfig -> Comment
_ccfgCustomName :: ColumnConfig -> Maybe Name
..} =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
(Pair -> Bool) -> [Pair] -> [Pair]
forall a. (a -> Bool) -> [a] -> [a]
filter
((Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
/= Value
Null) (Value -> Bool) -> (Pair -> Value) -> Pair -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pair -> Value
forall a b. (a, b) -> b
snd)
[ Key
"custom_name" Key -> Maybe Name -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Name
_ccfgCustomName,
Key
"comment" Key -> Comment -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Comment
_ccfgComment
]
instance FromJSON ColumnConfig where
parseJSON :: Value -> Parser ColumnConfig
parseJSON = String
-> (Object -> Parser ColumnConfig) -> Value -> Parser ColumnConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ColumnConfig" ((Object -> Parser ColumnConfig) -> Value -> Parser ColumnConfig)
-> (Object -> Parser ColumnConfig) -> Value -> Parser ColumnConfig
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
Maybe Name -> Comment -> ColumnConfig
ColumnConfig
(Maybe Name -> Comment -> ColumnConfig)
-> Parser (Maybe Name) -> Parser (Comment -> ColumnConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Maybe Name)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"custom_name"
Parser (Comment -> ColumnConfig)
-> Parser Comment -> Parser ColumnConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Maybe Comment)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment" Parser (Maybe Comment) -> Comment -> Parser Comment
forall a. Parser (Maybe a) -> a -> Parser a
.!= Comment
Automatic
instance Semigroup ColumnConfig where
ColumnConfig
a <> :: ColumnConfig -> ColumnConfig -> ColumnConfig
<> ColumnConfig
b = Maybe Name -> Comment -> ColumnConfig
ColumnConfig Maybe Name
customName Comment
comment
where
customName :: Maybe Name
customName = ColumnConfig -> Maybe Name
_ccfgCustomName ColumnConfig
a Maybe Name -> Maybe Name -> Maybe Name
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ColumnConfig -> Maybe Name
_ccfgCustomName ColumnConfig
b
comment :: Comment
comment = case (ColumnConfig -> Comment
_ccfgComment ColumnConfig
a, ColumnConfig -> Comment
_ccfgComment ColumnConfig
b) of
(Comment
Automatic, Comment
explicit) -> Comment
explicit
(Comment
explicit, Comment
_) -> Comment
explicit
instance Monoid ColumnConfig where
mempty :: ColumnConfig
mempty = Maybe Name -> Comment -> ColumnConfig
ColumnConfig Maybe Name
forall a. Maybe a
Nothing Comment
Automatic
data TableConfig b = TableConfig
{ TableConfig b -> TableCustomRootFields
_tcCustomRootFields :: TableCustomRootFields,
TableConfig b -> HashMap (Column b) ColumnConfig
_tcColumnConfig :: HashMap (Column b) ColumnConfig,
TableConfig b -> Maybe Name
_tcCustomName :: Maybe G.Name,
:: Comment
}
deriving ((forall x. TableConfig b -> Rep (TableConfig b) x)
-> (forall x. Rep (TableConfig b) x -> TableConfig b)
-> Generic (TableConfig b)
forall x. Rep (TableConfig b) x -> TableConfig b
forall x. TableConfig b -> Rep (TableConfig b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (TableConfig b) x -> TableConfig b
forall (b :: BackendType) x. TableConfig b -> Rep (TableConfig b) x
$cto :: forall (b :: BackendType) x. Rep (TableConfig b) x -> TableConfig b
$cfrom :: forall (b :: BackendType) x. TableConfig b -> Rep (TableConfig b) x
Generic)
deriving instance (Backend b) => Eq (TableConfig b)
deriving instance (Backend b) => Show (TableConfig b)
instance (Backend b) => NFData (TableConfig b)
instance (Backend b) => Cacheable (TableConfig b)
$()
emptyTableConfig :: TableConfig b
emptyTableConfig :: TableConfig b
emptyTableConfig =
TableCustomRootFields
-> HashMap (Column b) ColumnConfig
-> Maybe Name
-> Comment
-> TableConfig b
forall (b :: BackendType).
TableCustomRootFields
-> HashMap (Column b) ColumnConfig
-> Maybe Name
-> Comment
-> TableConfig b
TableConfig TableCustomRootFields
emptyCustomRootFields HashMap (Column b) ColumnConfig
forall k v. HashMap k v
M.empty Maybe Name
forall a. Maybe a
Nothing Comment
Automatic
instance (Backend b) => FromJSON (TableConfig b) where
parseJSON :: Value -> Parser (TableConfig b)
parseJSON = String
-> (Object -> Parser (TableConfig b))
-> Value
-> Parser (TableConfig b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TableConfig" ((Object -> Parser (TableConfig b))
-> Value -> Parser (TableConfig b))
-> (Object -> Parser (TableConfig b))
-> Value
-> Parser (TableConfig b)
forall a b. (a -> b) -> a -> b
$ \Object
obj -> do
TableCustomRootFields
-> HashMap (Column b) ColumnConfig
-> Maybe Name
-> Comment
-> TableConfig b
forall (b :: BackendType).
TableCustomRootFields
-> HashMap (Column b) ColumnConfig
-> Maybe Name
-> Comment
-> TableConfig b
TableConfig
(TableCustomRootFields
-> HashMap (Column b) ColumnConfig
-> Maybe Name
-> Comment
-> TableConfig b)
-> Parser TableCustomRootFields
-> Parser
(HashMap (Column b) ColumnConfig
-> Maybe Name -> Comment -> TableConfig b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Maybe TableCustomRootFields)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"custom_root_fields" Parser (Maybe TableCustomRootFields)
-> TableCustomRootFields -> Parser TableCustomRootFields
forall a. Parser (Maybe a) -> a -> Parser a
.!= TableCustomRootFields
emptyCustomRootFields
Parser
(HashMap (Column b) ColumnConfig
-> Maybe Name -> Comment -> TableConfig b)
-> Parser (HashMap (Column b) ColumnConfig)
-> Parser (Maybe Name -> Comment -> TableConfig b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser (HashMap (Column b) ColumnConfig)
parseColumnConfig Object
obj
Parser (Maybe Name -> Comment -> TableConfig b)
-> Parser (Maybe Name) -> Parser (Comment -> TableConfig b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Maybe Name)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"custom_name"
Parser (Comment -> TableConfig b)
-> Parser Comment -> Parser (TableConfig b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj Object -> Key -> Parser (Maybe Comment)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment" Parser (Maybe Comment) -> Comment -> Parser Comment
forall a. Parser (Maybe a) -> a -> Parser a
.!= Comment
Automatic
where
parseColumnConfig :: Object -> Parser (HashMap (Column b) ColumnConfig)
parseColumnConfig :: Object -> Parser (HashMap (Column b) ColumnConfig)
parseColumnConfig Object
obj = do
HashMap (Column b) ColumnConfig
columnConfig <- Object
obj Object -> Key -> Parser (Maybe (HashMap (Column b) ColumnConfig))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"column_config" Parser (Maybe (HashMap (Column b) ColumnConfig))
-> HashMap (Column b) ColumnConfig
-> Parser (HashMap (Column b) ColumnConfig)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Column b) ColumnConfig
forall k v. HashMap k v
M.empty
HashMap (Column b) Name
legacyCustomColumnNames <- Object
obj Object -> Key -> Parser (Maybe (HashMap (Column b) Name))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"custom_column_names" Parser (Maybe (HashMap (Column b) Name))
-> HashMap (Column b) Name -> Parser (HashMap (Column b) Name)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HashMap (Column b) Name
forall k v. HashMap k v
M.empty
let legacyColumnConfig :: HashMap (Column b) ColumnConfig
legacyColumnConfig = (\Name
name -> Maybe Name -> Comment -> ColumnConfig
ColumnConfig (Name -> Maybe Name
forall a. a -> Maybe a
Just Name
name) Comment
Automatic) (Name -> ColumnConfig)
-> HashMap (Column b) Name -> HashMap (Column b) ColumnConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HashMap (Column b) Name
legacyCustomColumnNames
HashMap (Column b) ColumnConfig
-> Parser (HashMap (Column b) ColumnConfig)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HashMap (Column b) ColumnConfig
-> Parser (HashMap (Column b) ColumnConfig))
-> HashMap (Column b) ColumnConfig
-> Parser (HashMap (Column b) ColumnConfig)
forall a b. (a -> b) -> a -> b
$ (ColumnConfig -> ColumnConfig -> ColumnConfig)
-> HashMap (Column b) ColumnConfig
-> HashMap (Column b) ColumnConfig
-> HashMap (Column b) ColumnConfig
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
M.unionWith ColumnConfig -> ColumnConfig -> ColumnConfig
forall a. Semigroup a => a -> a -> a
(<>) HashMap (Column b) ColumnConfig
columnConfig HashMap (Column b) ColumnConfig
legacyColumnConfig
instance (Backend b) => ToJSON (TableConfig b) where
toJSON :: TableConfig b -> Value
toJSON TableConfig {Maybe Name
HashMap (Column b) ColumnConfig
Comment
TableCustomRootFields
_tcComment :: Comment
_tcCustomName :: Maybe Name
_tcColumnConfig :: HashMap (Column b) ColumnConfig
_tcCustomRootFields :: TableCustomRootFields
_tcComment :: forall (b :: BackendType). TableConfig b -> Comment
_tcCustomName :: forall (b :: BackendType). TableConfig b -> Maybe Name
_tcColumnConfig :: forall (b :: BackendType).
TableConfig b -> HashMap (Column b) ColumnConfig
_tcCustomRootFields :: forall (b :: BackendType). TableConfig b -> TableCustomRootFields
..} =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
(Pair -> Bool) -> [Pair] -> [Pair]
forall a. (a -> Bool) -> [a] -> [a]
filter
((Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
/= Value
Null) (Value -> Bool) -> (Pair -> Value) -> Pair -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pair -> Value
forall a b. (a, b) -> b
snd)
[ Key
"custom_root_fields" Key -> TableCustomRootFields -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TableCustomRootFields
_tcCustomRootFields,
Key
"custom_column_names" Key -> HashMap (Column b) Name -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (ColumnConfig -> Maybe Name)
-> HashMap (Column b) ColumnConfig -> HashMap (Column b) Name
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe ColumnConfig -> Maybe Name
_ccfgCustomName HashMap (Column b) ColumnConfig
_tcColumnConfig,
Key
"column_config" Key -> HashMap (Column b) ColumnConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (ColumnConfig -> Bool)
-> HashMap (Column b) ColumnConfig
-> HashMap (Column b) ColumnConfig
forall v k. (v -> Bool) -> HashMap k v -> HashMap k v
M.filter (ColumnConfig -> ColumnConfig -> Bool
forall a. Eq a => a -> a -> Bool
/= ColumnConfig
forall a. Monoid a => a
mempty) HashMap (Column b) ColumnConfig
_tcColumnConfig,
Key
"custom_name" Key -> Maybe Name -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Name
_tcCustomName,
Key
"comment" Key -> Comment -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Comment
_tcComment
]
data Constraint (b :: BackendType) = Constraint
{ Constraint b -> ConstraintName b
_cName :: ConstraintName b,
Constraint b -> OID
_cOid :: OID
}
deriving ((forall x. Constraint b -> Rep (Constraint b) x)
-> (forall x. Rep (Constraint b) x -> Constraint b)
-> Generic (Constraint b)
forall x. Rep (Constraint b) x -> Constraint b
forall x. Constraint b -> Rep (Constraint b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (Constraint b) x -> Constraint b
forall (b :: BackendType) x. Constraint b -> Rep (Constraint b) x
$cto :: forall (b :: BackendType) x. Rep (Constraint b) x -> Constraint b
$cfrom :: forall (b :: BackendType) x. Constraint b -> Rep (Constraint b) x
Generic)
deriving instance Backend b => Eq (Constraint b)
deriving instance Backend b => Show (Constraint b)
instance Backend b => NFData (Constraint b)
instance Backend b => Hashable (Constraint b)
instance Backend b => Cacheable (Constraint b)
instance Backend b => ToJSON (Constraint b) where
toJSON :: Constraint b -> Value
toJSON = Options -> Constraint b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
instance Backend b => FromJSON (Constraint b) where
parseJSON :: Value -> Parser (Constraint b)
parseJSON = Options -> Value -> Parser (Constraint b)
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
hasuraJSON
data PrimaryKey (b :: BackendType) a = PrimaryKey
{ PrimaryKey b a -> Constraint b
_pkConstraint :: Constraint b,
PrimaryKey b a -> NESeq a
_pkColumns :: NESeq a
}
deriving ((forall x. PrimaryKey b a -> Rep (PrimaryKey b a) x)
-> (forall x. Rep (PrimaryKey b a) x -> PrimaryKey b a)
-> Generic (PrimaryKey b a)
forall x. Rep (PrimaryKey b a) x -> PrimaryKey b a
forall x. PrimaryKey b a -> Rep (PrimaryKey b a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) a x.
Rep (PrimaryKey b a) x -> PrimaryKey b a
forall (b :: BackendType) a x.
PrimaryKey b a -> Rep (PrimaryKey b a) x
$cto :: forall (b :: BackendType) a x.
Rep (PrimaryKey b a) x -> PrimaryKey b a
$cfrom :: forall (b :: BackendType) a x.
PrimaryKey b a -> Rep (PrimaryKey b a) x
Generic, PrimaryKey b a -> Bool
(a -> m) -> PrimaryKey b a -> m
(a -> b -> b) -> b -> PrimaryKey b a -> b
(forall m. Monoid m => PrimaryKey b m -> m)
-> (forall m a. Monoid m => (a -> m) -> PrimaryKey b a -> m)
-> (forall m a. Monoid m => (a -> m) -> PrimaryKey b a -> m)
-> (forall a b. (a -> b -> b) -> b -> PrimaryKey b a -> b)
-> (forall a b. (a -> b -> b) -> b -> PrimaryKey b a -> b)
-> (forall b a. (b -> a -> b) -> b -> PrimaryKey b a -> b)
-> (forall b a. (b -> a -> b) -> b -> PrimaryKey b a -> b)
-> (forall a. (a -> a -> a) -> PrimaryKey b a -> a)
-> (forall a. (a -> a -> a) -> PrimaryKey b a -> a)
-> (forall a. PrimaryKey b a -> [a])
-> (forall a. PrimaryKey b a -> Bool)
-> (forall a. PrimaryKey b a -> Int)
-> (forall a. Eq a => a -> PrimaryKey b a -> Bool)
-> (forall a. Ord a => PrimaryKey b a -> a)
-> (forall a. Ord a => PrimaryKey b a -> a)
-> (forall a. Num a => PrimaryKey b a -> a)
-> (forall a. Num a => PrimaryKey b a -> a)
-> Foldable (PrimaryKey b)
forall a. Eq a => a -> PrimaryKey b a -> Bool
forall a. Num a => PrimaryKey b a -> a
forall a. Ord a => PrimaryKey b a -> a
forall m. Monoid m => PrimaryKey b m -> m
forall a. PrimaryKey b a -> Bool
forall a. PrimaryKey b a -> Int
forall a. PrimaryKey b a -> [a]
forall a. (a -> a -> a) -> PrimaryKey b a -> a
forall m a. Monoid m => (a -> m) -> PrimaryKey b a -> m
forall b a. (b -> a -> b) -> b -> PrimaryKey b a -> b
forall a b. (a -> b -> b) -> b -> PrimaryKey b a -> b
forall (b :: BackendType) a. Eq a => a -> PrimaryKey b a -> Bool
forall (b :: BackendType) a. Num a => PrimaryKey b a -> a
forall (b :: BackendType) a. Ord a => PrimaryKey b a -> a
forall (b :: BackendType) m. Monoid m => PrimaryKey b m -> m
forall (b :: BackendType) a. PrimaryKey b a -> Bool
forall (b :: BackendType) a. PrimaryKey b a -> Int
forall (b :: BackendType) a. PrimaryKey b a -> [a]
forall (b :: BackendType) a. (a -> a -> a) -> PrimaryKey b a -> a
forall (b :: BackendType) m a.
Monoid m =>
(a -> m) -> PrimaryKey b a -> m
forall (b :: BackendType) b a.
(b -> a -> b) -> b -> PrimaryKey b a -> b
forall (b :: BackendType) a b.
(a -> b -> b) -> b -> PrimaryKey b a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: PrimaryKey b a -> a
$cproduct :: forall (b :: BackendType) a. Num a => PrimaryKey b a -> a
sum :: PrimaryKey b a -> a
$csum :: forall (b :: BackendType) a. Num a => PrimaryKey b a -> a
minimum :: PrimaryKey b a -> a
$cminimum :: forall (b :: BackendType) a. Ord a => PrimaryKey b a -> a
maximum :: PrimaryKey b a -> a
$cmaximum :: forall (b :: BackendType) a. Ord a => PrimaryKey b a -> a
elem :: a -> PrimaryKey b a -> Bool
$celem :: forall (b :: BackendType) a. Eq a => a -> PrimaryKey b a -> Bool
length :: PrimaryKey b a -> Int
$clength :: forall (b :: BackendType) a. PrimaryKey b a -> Int
null :: PrimaryKey b a -> Bool
$cnull :: forall (b :: BackendType) a. PrimaryKey b a -> Bool
toList :: PrimaryKey b a -> [a]
$ctoList :: forall (b :: BackendType) a. PrimaryKey b a -> [a]
foldl1 :: (a -> a -> a) -> PrimaryKey b a -> a
$cfoldl1 :: forall (b :: BackendType) a. (a -> a -> a) -> PrimaryKey b a -> a
foldr1 :: (a -> a -> a) -> PrimaryKey b a -> a
$cfoldr1 :: forall (b :: BackendType) a. (a -> a -> a) -> PrimaryKey b a -> a
foldl' :: (b -> a -> b) -> b -> PrimaryKey b a -> b
$cfoldl' :: forall (b :: BackendType) b a.
(b -> a -> b) -> b -> PrimaryKey b a -> b
foldl :: (b -> a -> b) -> b -> PrimaryKey b a -> b
$cfoldl :: forall (b :: BackendType) b a.
(b -> a -> b) -> b -> PrimaryKey b a -> b
foldr' :: (a -> b -> b) -> b -> PrimaryKey b a -> b
$cfoldr' :: forall (b :: BackendType) a b.
(a -> b -> b) -> b -> PrimaryKey b a -> b
foldr :: (a -> b -> b) -> b -> PrimaryKey b a -> b
$cfoldr :: forall (b :: BackendType) a b.
(a -> b -> b) -> b -> PrimaryKey b a -> b
foldMap' :: (a -> m) -> PrimaryKey b a -> m
$cfoldMap' :: forall (b :: BackendType) m a.
Monoid m =>
(a -> m) -> PrimaryKey b a -> m
foldMap :: (a -> m) -> PrimaryKey b a -> m
$cfoldMap :: forall (b :: BackendType) m a.
Monoid m =>
(a -> m) -> PrimaryKey b a -> m
fold :: PrimaryKey b m -> m
$cfold :: forall (b :: BackendType) m. Monoid m => PrimaryKey b m -> m
Foldable)
deriving instance (Backend b, Eq a) => Eq (PrimaryKey b a)
deriving instance (Backend b, Show a) => Show (PrimaryKey b a)
instance (Backend b, NFData a) => NFData (PrimaryKey b a)
instance (Backend b, Hashable (NESeq a)) => Hashable (PrimaryKey b a)
instance (Backend b, Cacheable a) => Cacheable (PrimaryKey b a)
instance (Backend b, ToJSON a) => ToJSON (PrimaryKey b a) where
toJSON :: PrimaryKey b a -> Value
toJSON = Options -> PrimaryKey b a -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
instance (Backend b, FromJSON a) => FromJSON (PrimaryKey b a) where
parseJSON :: Value -> Parser (PrimaryKey b a)
parseJSON = Options -> Value -> Parser (PrimaryKey b a)
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
hasuraJSON
$(makeLenses ''PrimaryKey)
data UniqueConstraint (b :: BackendType) = UniqueConstraint
{
UniqueConstraint b -> Constraint b
_ucConstraint :: Constraint b,
UniqueConstraint b -> HashSet (Column b)
_ucColumns :: HashSet (Column b)
}
deriving ((forall x. UniqueConstraint b -> Rep (UniqueConstraint b) x)
-> (forall x. Rep (UniqueConstraint b) x -> UniqueConstraint b)
-> Generic (UniqueConstraint b)
forall x. Rep (UniqueConstraint b) x -> UniqueConstraint b
forall x. UniqueConstraint b -> Rep (UniqueConstraint b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x.
Rep (UniqueConstraint b) x -> UniqueConstraint b
forall (b :: BackendType) x.
UniqueConstraint b -> Rep (UniqueConstraint b) x
$cto :: forall (b :: BackendType) x.
Rep (UniqueConstraint b) x -> UniqueConstraint b
$cfrom :: forall (b :: BackendType) x.
UniqueConstraint b -> Rep (UniqueConstraint b) x
Generic)
deriving instance Backend b => Eq (UniqueConstraint b)
deriving instance Backend b => Show (UniqueConstraint b)
instance Backend b => NFData (UniqueConstraint b)
instance Backend b => Hashable (UniqueConstraint b)
instance Backend b => Cacheable (UniqueConstraint b)
instance Backend b => ToJSON (UniqueConstraint b) where
toJSON :: UniqueConstraint b -> Value
toJSON = Options -> UniqueConstraint b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
instance Backend b => FromJSON (UniqueConstraint b) where
parseJSON :: Value -> Parser (UniqueConstraint b)
parseJSON = Options -> Value -> Parser (UniqueConstraint b)
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
hasuraJSON
data ForeignKey (b :: BackendType) = ForeignKey
{ ForeignKey b -> Constraint b
_fkConstraint :: Constraint b,
ForeignKey b -> TableName b
_fkForeignTable :: TableName b,
ForeignKey b -> NEHashMap (Column b) (Column b)
_fkColumnMapping :: NEHashMap (Column b) (Column b)
}
deriving ((forall x. ForeignKey b -> Rep (ForeignKey b) x)
-> (forall x. Rep (ForeignKey b) x -> ForeignKey b)
-> Generic (ForeignKey b)
forall x. Rep (ForeignKey b) x -> ForeignKey b
forall x. ForeignKey b -> Rep (ForeignKey b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (ForeignKey b) x -> ForeignKey b
forall (b :: BackendType) x. ForeignKey b -> Rep (ForeignKey b) x
$cto :: forall (b :: BackendType) x. Rep (ForeignKey b) x -> ForeignKey b
$cfrom :: forall (b :: BackendType) x. ForeignKey b -> Rep (ForeignKey b) x
Generic)
deriving instance Backend b => Eq (ForeignKey b)
deriving instance Backend b => Show (ForeignKey b)
instance Backend b => NFData (ForeignKey b)
instance Backend b => Hashable (ForeignKey b)
instance Backend b => Cacheable (ForeignKey b)
instance Backend b => ToJSON (ForeignKey b) where
toJSON :: ForeignKey b -> Value
toJSON = Options -> ForeignKey b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
instance Backend b => FromJSON (ForeignKey b) where
parseJSON :: Value -> Parser (ForeignKey b)
parseJSON = Options -> Value -> Parser (ForeignKey b)
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
hasuraJSON
data TableCoreInfoG (b :: BackendType) field primaryKeyColumn = TableCoreInfo
{ TableCoreInfoG b field primaryKeyColumn -> TableName b
_tciName :: TableName b,
TableCoreInfoG b field primaryKeyColumn -> Maybe PGDescription
_tciDescription :: Maybe PG.PGDescription,
TableCoreInfoG b field primaryKeyColumn -> FieldInfoMap field
_tciFieldInfoMap :: FieldInfoMap field,
TableCoreInfoG b field primaryKeyColumn
-> Maybe (PrimaryKey b primaryKeyColumn)
_tciPrimaryKey :: Maybe (PrimaryKey b primaryKeyColumn),
TableCoreInfoG b field primaryKeyColumn
-> HashSet (UniqueConstraint b)
_tciUniqueConstraints :: HashSet (UniqueConstraint b),
TableCoreInfoG b field primaryKeyColumn -> HashSet (ForeignKey b)
_tciForeignKeys :: HashSet (ForeignKey b),
TableCoreInfoG b field primaryKeyColumn -> Maybe ViewInfo
_tciViewInfo :: Maybe ViewInfo,
TableCoreInfoG b field primaryKeyColumn -> Maybe EnumValues
_tciEnumValues :: Maybe EnumValues,
TableCoreInfoG b field primaryKeyColumn -> TableConfig b
_tciCustomConfig :: TableConfig b,
:: ExtraTableMetadata b,
TableCoreInfoG b field primaryKeyColumn
-> Maybe ApolloFederationConfig
_tciApolloFederationConfig :: Maybe ApolloFederationConfig
}
deriving ((forall x.
TableCoreInfoG b field primaryKeyColumn
-> Rep (TableCoreInfoG b field primaryKeyColumn) x)
-> (forall x.
Rep (TableCoreInfoG b field primaryKeyColumn) x
-> TableCoreInfoG b field primaryKeyColumn)
-> Generic (TableCoreInfoG b field primaryKeyColumn)
forall x.
Rep (TableCoreInfoG b field primaryKeyColumn) x
-> TableCoreInfoG b field primaryKeyColumn
forall x.
TableCoreInfoG b field primaryKeyColumn
-> Rep (TableCoreInfoG b field primaryKeyColumn) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) field primaryKeyColumn x.
Rep (TableCoreInfoG b field primaryKeyColumn) x
-> TableCoreInfoG b field primaryKeyColumn
forall (b :: BackendType) field primaryKeyColumn x.
TableCoreInfoG b field primaryKeyColumn
-> Rep (TableCoreInfoG b field primaryKeyColumn) x
$cto :: forall (b :: BackendType) field primaryKeyColumn x.
Rep (TableCoreInfoG b field primaryKeyColumn) x
-> TableCoreInfoG b field primaryKeyColumn
$cfrom :: forall (b :: BackendType) field primaryKeyColumn x.
TableCoreInfoG b field primaryKeyColumn
-> Rep (TableCoreInfoG b field primaryKeyColumn) x
Generic)
deriving instance (Eq field, Eq pkCol, Backend b) => Eq (TableCoreInfoG b field pkCol)
instance (Cacheable field, Cacheable pkCol, Backend b) => Cacheable (TableCoreInfoG b field pkCol)
instance (Backend b, Generic pkCol, ToJSON field, ToJSON pkCol) => ToJSON (TableCoreInfoG b field pkCol) where
toJSON :: TableCoreInfoG b field pkCol -> Value
toJSON = Options -> TableCoreInfoG b field pkCol -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
$()
type TableCoreInfo b = TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
tciUniqueOrPrimaryKeyConstraints ::
forall b f.
(Eq (Column b), Hashable (Column b)) =>
TableCoreInfoG b f (ColumnInfo b) ->
Maybe (NonEmpty (UniqueConstraint b))
tciUniqueOrPrimaryKeyConstraints :: TableCoreInfoG b f (ColumnInfo b)
-> Maybe (NonEmpty (UniqueConstraint b))
tciUniqueOrPrimaryKeyConstraints TableCoreInfoG b f (ColumnInfo b)
info =
[UniqueConstraint b] -> Maybe (NonEmpty (UniqueConstraint b))
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty ([UniqueConstraint b] -> Maybe (NonEmpty (UniqueConstraint b)))
-> [UniqueConstraint b] -> Maybe (NonEmpty (UniqueConstraint b))
forall a b. (a -> b) -> a -> b
$
Maybe (UniqueConstraint b) -> [UniqueConstraint b]
forall a. Maybe a -> [a]
maybeToList (PrimaryKey b (ColumnInfo b) -> UniqueConstraint b
primaryToUnique (PrimaryKey b (ColumnInfo b) -> UniqueConstraint b)
-> Maybe (PrimaryKey b (ColumnInfo b))
-> Maybe (UniqueConstraint b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TableCoreInfoG b f (ColumnInfo b)
-> Maybe (PrimaryKey b (ColumnInfo b))
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn
-> Maybe (PrimaryKey b primaryKeyColumn)
_tciPrimaryKey TableCoreInfoG b f (ColumnInfo b)
info)
[UniqueConstraint b]
-> [UniqueConstraint b] -> [UniqueConstraint b]
forall a. Semigroup a => a -> a -> a
<> (HashSet (UniqueConstraint b) -> [UniqueConstraint b]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (TableCoreInfoG b f (ColumnInfo b) -> HashSet (UniqueConstraint b)
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn
-> HashSet (UniqueConstraint b)
_tciUniqueConstraints TableCoreInfoG b f (ColumnInfo b)
info))
where
primaryToUnique :: PrimaryKey b (ColumnInfo b) -> UniqueConstraint b
primaryToUnique :: PrimaryKey b (ColumnInfo b) -> UniqueConstraint b
primaryToUnique PrimaryKey b (ColumnInfo b)
pk = Constraint b -> HashSet (Column b) -> UniqueConstraint b
forall (b :: BackendType).
Constraint b -> HashSet (Column b) -> UniqueConstraint b
UniqueConstraint (PrimaryKey b (ColumnInfo b) -> Constraint b
forall (b :: BackendType) a. PrimaryKey b a -> Constraint b
_pkConstraint PrimaryKey b (ColumnInfo b)
pk) ([Column b] -> HashSet (Column b)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HS.fromList ([Column b] -> HashSet (Column b))
-> (NESeq (ColumnInfo b) -> [Column b])
-> NESeq (ColumnInfo b)
-> HashSet (Column b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ColumnInfo b -> Column b) -> [ColumnInfo b] -> [Column b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ([ColumnInfo b] -> [Column b])
-> (NESeq (ColumnInfo b) -> [ColumnInfo b])
-> NESeq (ColumnInfo b)
-> [Column b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NESeq (ColumnInfo b) -> [ColumnInfo b]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (NESeq (ColumnInfo b) -> HashSet (Column b))
-> NESeq (ColumnInfo b) -> HashSet (Column b)
forall a b. (a -> b) -> a -> b
$ PrimaryKey b (ColumnInfo b) -> NESeq (ColumnInfo b)
forall (b :: BackendType) a. PrimaryKey b a -> NESeq a
_pkColumns PrimaryKey b (ColumnInfo b)
pk)
data TableInfo (b :: BackendType) = TableInfo
{ TableInfo b -> TableCoreInfo b
_tiCoreInfo :: TableCoreInfo b,
TableInfo b -> RolePermInfoMap b
_tiRolePermInfoMap :: RolePermInfoMap b,
TableInfo b -> EventTriggerInfoMap b
_tiEventTriggerInfoMap :: EventTriggerInfoMap b,
TableInfo b -> RolePermInfo b
_tiAdminRolePermInfo :: RolePermInfo b
}
deriving ((forall x. TableInfo b -> Rep (TableInfo b) x)
-> (forall x. Rep (TableInfo b) x -> TableInfo b)
-> Generic (TableInfo b)
forall x. Rep (TableInfo b) x -> TableInfo b
forall x. TableInfo b -> Rep (TableInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x. Rep (TableInfo b) x -> TableInfo b
forall (b :: BackendType) x. TableInfo b -> Rep (TableInfo b) x
$cto :: forall (b :: BackendType) x. Rep (TableInfo b) x -> TableInfo b
$cfrom :: forall (b :: BackendType) x. TableInfo b -> Rep (TableInfo b) x
Generic)
instance
( Backend b,
ToJSON (EventTriggerInfoMap b),
ToJSON (RolePermInfo b),
ToJSON (RolePermInfoMap b),
ToJSON (TableCoreInfo b)
) =>
ToJSON (TableInfo b)
where
toJSON :: TableInfo b -> Value
toJSON = Options -> TableInfo b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON
$(makeLenses ''TableInfo)
tiName :: Lens' (TableInfo b) (TableName b)
tiName :: (TableName b -> f (TableName b)) -> TableInfo b -> f (TableInfo b)
tiName = (TableCoreInfo b -> f (TableCoreInfo b))
-> TableInfo b -> f (TableInfo b)
forall (b :: BackendType). Lens' (TableInfo b) (TableCoreInfo b)
tiCoreInfo ((TableCoreInfo b -> f (TableCoreInfo b))
-> TableInfo b -> f (TableInfo b))
-> ((TableName b -> f (TableName b))
-> TableCoreInfo b -> f (TableCoreInfo b))
-> (TableName b -> f (TableName b))
-> TableInfo b
-> f (TableInfo b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TableName b -> f (TableName b))
-> TableCoreInfo b -> f (TableCoreInfo b)
forall (b :: BackendType) field primaryKeyColumn.
Lens' (TableCoreInfoG b field primaryKeyColumn) (TableName b)
tciName
tableInfoName :: TableInfo b -> TableName b
tableInfoName :: TableInfo b -> TableName b
tableInfoName = Getting (TableName b) (TableInfo b) (TableName b)
-> TableInfo b -> TableName b
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (TableName b) (TableInfo b) (TableName b)
forall (b :: BackendType). Lens' (TableInfo b) (TableName b)
tiName
tableArrayRelationships :: TableInfo b -> [RelInfo b]
tableArrayRelationships :: TableInfo b -> [RelInfo b]
tableArrayRelationships TableInfo b
ti = [RelInfo b
rel | RelInfo b
rel <- FieldInfoMap (FieldInfo b) -> [RelInfo b]
forall (backend :: BackendType).
FieldInfoMap (FieldInfo backend) -> [RelInfo backend]
getRels (FieldInfoMap (FieldInfo b) -> [RelInfo b])
-> (TableInfo b -> FieldInfoMap (FieldInfo b))
-> TableInfo b
-> [RelInfo b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
-> FieldInfoMap (FieldInfo b)
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> FieldInfoMap field
_tciFieldInfoMap (TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
-> FieldInfoMap (FieldInfo b))
-> (TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b))
-> TableInfo b
-> FieldInfoMap (FieldInfo b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo (TableInfo b -> [RelInfo b]) -> TableInfo b -> [RelInfo b]
forall a b. (a -> b) -> a -> b
$ TableInfo b
ti, RelInfo b -> RelType
forall (b :: BackendType). RelInfo b -> RelType
riType RelInfo b
rel RelType -> RelType -> Bool
forall a. Eq a => a -> a -> Bool
== RelType
ArrRel]
getRolePermInfo :: RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo :: RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
role TableInfo b
tableInfo
| RoleName
role RoleName -> RoleName -> Bool
forall a. Eq a => a -> a -> Bool
== RoleName
adminRoleName = TableInfo b -> RolePermInfo b
forall (b :: BackendType). TableInfo b -> RolePermInfo b
_tiAdminRolePermInfo TableInfo b
tableInfo
| Bool
otherwise =
RolePermInfo b -> Maybe (RolePermInfo b) -> RolePermInfo b
forall a. a -> Maybe a -> a
fromMaybe
(Maybe (InsPermInfo b)
-> Maybe (SelPermInfo b)
-> Maybe (UpdPermInfo b)
-> Maybe (DelPermInfo b)
-> RolePermInfo b
forall (b :: BackendType).
Maybe (InsPermInfo b)
-> Maybe (SelPermInfo b)
-> Maybe (UpdPermInfo b)
-> Maybe (DelPermInfo b)
-> RolePermInfo b
RolePermInfo Maybe (InsPermInfo b)
forall a. Maybe a
Nothing Maybe (SelPermInfo b)
forall a. Maybe a
Nothing Maybe (UpdPermInfo b)
forall a. Maybe a
Nothing Maybe (DelPermInfo b)
forall a. Maybe a
Nothing)
(RoleName
-> HashMap RoleName (RolePermInfo b) -> Maybe (RolePermInfo b)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup RoleName
role (HashMap RoleName (RolePermInfo b) -> Maybe (RolePermInfo b))
-> HashMap RoleName (RolePermInfo b) -> Maybe (RolePermInfo b)
forall a b. (a -> b) -> a -> b
$ TableInfo b -> HashMap RoleName (RolePermInfo b)
forall (b :: BackendType). TableInfo b -> RolePermInfoMap b
_tiRolePermInfoMap TableInfo b
tableInfo)
type TableCoreCache b = M.HashMap (TableName b) (TableCoreInfo b)
type TableCache b = M.HashMap (TableName b) (TableInfo b)
type TableEventTriggers b = M.HashMap (TableName b) [TriggerName]
newtype ForeignKeyMetadata (b :: BackendType) = ForeignKeyMetadata
{ ForeignKeyMetadata b -> ForeignKey b
unForeignKeyMetadata :: ForeignKey b
}
deriving (Int -> ForeignKeyMetadata b -> ShowS
[ForeignKeyMetadata b] -> ShowS
ForeignKeyMetadata b -> String
(Int -> ForeignKeyMetadata b -> ShowS)
-> (ForeignKeyMetadata b -> String)
-> ([ForeignKeyMetadata b] -> ShowS)
-> Show (ForeignKeyMetadata b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (b :: BackendType).
Backend b =>
Int -> ForeignKeyMetadata b -> ShowS
forall (b :: BackendType).
Backend b =>
[ForeignKeyMetadata b] -> ShowS
forall (b :: BackendType).
Backend b =>
ForeignKeyMetadata b -> String
showList :: [ForeignKeyMetadata b] -> ShowS
$cshowList :: forall (b :: BackendType).
Backend b =>
[ForeignKeyMetadata b] -> ShowS
show :: ForeignKeyMetadata b -> String
$cshow :: forall (b :: BackendType).
Backend b =>
ForeignKeyMetadata b -> String
showsPrec :: Int -> ForeignKeyMetadata b -> ShowS
$cshowsPrec :: forall (b :: BackendType).
Backend b =>
Int -> ForeignKeyMetadata b -> ShowS
Show, ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
(ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool)
-> (ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool)
-> Eq (ForeignKeyMetadata b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (b :: BackendType).
Backend b =>
ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
/= :: ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
$c/= :: forall (b :: BackendType).
Backend b =>
ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
== :: ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
$c== :: forall (b :: BackendType).
Backend b =>
ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
Eq, ForeignKeyMetadata b -> ()
(ForeignKeyMetadata b -> ()) -> NFData (ForeignKeyMetadata b)
forall a. (a -> ()) -> NFData a
forall (b :: BackendType). Backend b => ForeignKeyMetadata b -> ()
rnf :: ForeignKeyMetadata b -> ()
$crnf :: forall (b :: BackendType). Backend b => ForeignKeyMetadata b -> ()
NFData, Int -> ForeignKeyMetadata b -> Int
ForeignKeyMetadata b -> Int
(Int -> ForeignKeyMetadata b -> Int)
-> (ForeignKeyMetadata b -> Int) -> Hashable (ForeignKeyMetadata b)
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
forall (b :: BackendType).
Backend b =>
Int -> ForeignKeyMetadata b -> Int
forall (b :: BackendType). Backend b => ForeignKeyMetadata b -> Int
hash :: ForeignKeyMetadata b -> Int
$chash :: forall (b :: BackendType). Backend b => ForeignKeyMetadata b -> Int
hashWithSalt :: Int -> ForeignKeyMetadata b -> Int
$chashWithSalt :: forall (b :: BackendType).
Backend b =>
Int -> ForeignKeyMetadata b -> Int
Hashable, Eq (ForeignKeyMetadata b)
Eq (ForeignKeyMetadata b)
-> (Accesses
-> ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool)
-> Cacheable (ForeignKeyMetadata b)
Accesses -> ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
forall a. Eq a -> (Accesses -> a -> a -> Bool) -> Cacheable a
forall (b :: BackendType). Backend b => Eq (ForeignKeyMetadata b)
forall (b :: BackendType).
Backend b =>
Accesses -> ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
unchanged :: Accesses -> ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
$cunchanged :: forall (b :: BackendType).
Backend b =>
Accesses -> ForeignKeyMetadata b -> ForeignKeyMetadata b -> Bool
$cp1Cacheable :: forall (b :: BackendType). Backend b => Eq (ForeignKeyMetadata b)
Cacheable)
instance Backend b => FromJSON (ForeignKeyMetadata b) where
parseJSON :: Value -> Parser (ForeignKeyMetadata b)
parseJSON = String
-> (Object -> Parser (ForeignKeyMetadata b))
-> Value
-> Parser (ForeignKeyMetadata b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ForeignKeyMetadata" \Object
o -> do
Constraint b
constraint <- Object
o Object -> Key -> Parser (Constraint b)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"constraint"
TableName b
foreignTable <- Object
o Object -> Key -> Parser (TableName b)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"foreign_table"
NonEmpty (Column b)
columns <-
Object
o Object -> Key -> Parser [Column b]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"columns" Parser [Column b]
-> ([Column b] -> Parser (NonEmpty (Column b)))
-> Parser (NonEmpty (Column b))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Column b
x : [Column b]
xs -> NonEmpty (Column b) -> Parser (NonEmpty (Column b))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Column b
x Column b -> [Column b] -> NonEmpty (Column b)
forall a. a -> [a] -> NonEmpty a
:| [Column b]
xs)
[] -> String -> Parser (NonEmpty (Column b))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"columns must be non-empty"
NonEmpty (Column b)
foreignColumns <-
Object
o Object -> Key -> Parser [Column b]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"foreign_columns" Parser [Column b]
-> ([Column b] -> Parser (NonEmpty (Column b)))
-> Parser (NonEmpty (Column b))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Column b
x : [Column b]
xs -> NonEmpty (Column b) -> Parser (NonEmpty (Column b))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Column b
x Column b -> [Column b] -> NonEmpty (Column b)
forall a. a -> [a] -> NonEmpty a
:| [Column b]
xs)
[] -> String -> Parser (NonEmpty (Column b))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"foreign_columns must be non-empty"
Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (NonEmpty (Column b) -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length NonEmpty (Column b)
columns Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== NonEmpty (Column b) -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length NonEmpty (Column b)
foreignColumns) do
String -> Parser ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"columns and foreign_columns differ in length"
ForeignKeyMetadata b -> Parser (ForeignKeyMetadata b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ForeignKeyMetadata b -> Parser (ForeignKeyMetadata b))
-> ForeignKeyMetadata b -> Parser (ForeignKeyMetadata b)
forall a b. (a -> b) -> a -> b
$
ForeignKey b -> ForeignKeyMetadata b
forall (b :: BackendType). ForeignKey b -> ForeignKeyMetadata b
ForeignKeyMetadata
ForeignKey :: forall (b :: BackendType).
Constraint b
-> TableName b -> NEHashMap (Column b) (Column b) -> ForeignKey b
ForeignKey
{ _fkConstraint :: Constraint b
_fkConstraint = Constraint b
constraint,
_fkForeignTable :: TableName b
_fkForeignTable = TableName b
foreignTable,
_fkColumnMapping :: NEHashMap (Column b) (Column b)
_fkColumnMapping =
NonEmpty (Column b, Column b) -> NEHashMap (Column b) (Column b)
forall k v. (Eq k, Hashable k) => NonEmpty (k, v) -> NEHashMap k v
NEHashMap.fromNonEmpty (NonEmpty (Column b, Column b) -> NEHashMap (Column b) (Column b))
-> NonEmpty (Column b, Column b) -> NEHashMap (Column b) (Column b)
forall a b. (a -> b) -> a -> b
$
NonEmpty (Column b)
-> NonEmpty (Column b) -> NonEmpty (Column b, Column b)
forall a b. NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
NE.zip NonEmpty (Column b)
columns NonEmpty (Column b)
foreignColumns
}
data DBTableMetadata (b :: BackendType) = DBTableMetadata
{ DBTableMetadata b -> OID
_ptmiOid :: OID,
DBTableMetadata b -> [RawColumnInfo b]
_ptmiColumns :: [RawColumnInfo b],
DBTableMetadata b -> Maybe (PrimaryKey b (Column b))
_ptmiPrimaryKey :: Maybe (PrimaryKey b (Column b)),
DBTableMetadata b -> HashSet (UniqueConstraint b)
_ptmiUniqueConstraints :: HashSet (UniqueConstraint b),
DBTableMetadata b -> HashSet (ForeignKeyMetadata b)
_ptmiForeignKeys :: HashSet (ForeignKeyMetadata b),
DBTableMetadata b -> Maybe ViewInfo
_ptmiViewInfo :: Maybe ViewInfo,
DBTableMetadata b -> Maybe PGDescription
_ptmiDescription :: Maybe PG.PGDescription,
:: ExtraTableMetadata b
}
deriving ((forall x. DBTableMetadata b -> Rep (DBTableMetadata b) x)
-> (forall x. Rep (DBTableMetadata b) x -> DBTableMetadata b)
-> Generic (DBTableMetadata b)
forall x. Rep (DBTableMetadata b) x -> DBTableMetadata b
forall x. DBTableMetadata b -> Rep (DBTableMetadata b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x.
Rep (DBTableMetadata b) x -> DBTableMetadata b
forall (b :: BackendType) x.
DBTableMetadata b -> Rep (DBTableMetadata b) x
$cto :: forall (b :: BackendType) x.
Rep (DBTableMetadata b) x -> DBTableMetadata b
$cfrom :: forall (b :: BackendType) x.
DBTableMetadata b -> Rep (DBTableMetadata b) x
Generic)
deriving instance Backend b => Eq (DBTableMetadata b)
deriving instance Backend b => Show (DBTableMetadata b)
instance Backend b => NFData (DBTableMetadata b)
instance Backend b => Cacheable (DBTableMetadata b)
instance Backend b => FromJSON (DBTableMetadata b) where
parseJSON :: Value -> Parser (DBTableMetadata b)
parseJSON = Options -> Value -> Parser (DBTableMetadata b)
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
hasuraJSON
type DBTablesMetadata b = HashMap (TableName b) (DBTableMetadata b)
getFieldInfoM ::
TableInfo b -> FieldName -> Maybe (FieldInfo b)
getFieldInfoM :: TableInfo b -> FieldName -> Maybe (FieldInfo b)
getFieldInfoM TableInfo b
tableInfo FieldName
fieldName =
TableInfo b
tableInfo TableInfo b
-> Getting
(Maybe (FieldInfo b)) (TableInfo b) (Maybe (FieldInfo b))
-> Maybe (FieldInfo b)
forall s a. s -> Getting a s a -> a
^. (TableCoreInfo b -> Const (Maybe (FieldInfo b)) (TableCoreInfo b))
-> TableInfo b -> Const (Maybe (FieldInfo b)) (TableInfo b)
forall (b :: BackendType). Lens' (TableInfo b) (TableCoreInfo b)
tiCoreInfo ((TableCoreInfo b -> Const (Maybe (FieldInfo b)) (TableCoreInfo b))
-> TableInfo b -> Const (Maybe (FieldInfo b)) (TableInfo b))
-> ((Maybe (FieldInfo b)
-> Const (Maybe (FieldInfo b)) (Maybe (FieldInfo b)))
-> TableCoreInfo b
-> Const (Maybe (FieldInfo b)) (TableCoreInfo b))
-> Getting
(Maybe (FieldInfo b)) (TableInfo b) (Maybe (FieldInfo b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FieldInfoMap (FieldInfo b)
-> Const (Maybe (FieldInfo b)) (FieldInfoMap (FieldInfo b)))
-> TableCoreInfo b -> Const (Maybe (FieldInfo b)) (TableCoreInfo b)
forall (b :: BackendType) field primaryKeyColumn field.
Lens
(TableCoreInfoG b field primaryKeyColumn)
(TableCoreInfoG b field primaryKeyColumn)
(FieldInfoMap field)
(FieldInfoMap field)
tciFieldInfoMap ((FieldInfoMap (FieldInfo b)
-> Const (Maybe (FieldInfo b)) (FieldInfoMap (FieldInfo b)))
-> TableCoreInfo b
-> Const (Maybe (FieldInfo b)) (TableCoreInfo b))
-> ((Maybe (FieldInfo b)
-> Const (Maybe (FieldInfo b)) (Maybe (FieldInfo b)))
-> FieldInfoMap (FieldInfo b)
-> Const (Maybe (FieldInfo b)) (FieldInfoMap (FieldInfo b)))
-> (Maybe (FieldInfo b)
-> Const (Maybe (FieldInfo b)) (Maybe (FieldInfo b)))
-> TableCoreInfo b
-> Const (Maybe (FieldInfo b)) (TableCoreInfo b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (FieldInfoMap (FieldInfo b))
-> Lens'
(FieldInfoMap (FieldInfo b))
(Maybe (IxValue (FieldInfoMap (FieldInfo b))))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index (FieldInfoMap (FieldInfo b))
FieldName
fieldName
getColumnInfoM ::
TableInfo b -> FieldName -> Maybe (ColumnInfo b)
getColumnInfoM :: TableInfo b -> FieldName -> Maybe (ColumnInfo b)
getColumnInfoM TableInfo b
tableInfo FieldName
fieldName =
(FieldInfo b
-> Getting (First (ColumnInfo b)) (FieldInfo b) (ColumnInfo b)
-> Maybe (ColumnInfo b)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting (First (ColumnInfo b)) (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). Prism' (FieldInfo b) (ColumnInfo b)
_FIColumn) (FieldInfo b -> Maybe (ColumnInfo b))
-> Maybe (FieldInfo b) -> Maybe (ColumnInfo b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TableInfo b -> FieldName -> Maybe (FieldInfo b)
forall (b :: BackendType).
TableInfo b -> FieldName -> Maybe (FieldInfo b)
getFieldInfoM TableInfo b
tableInfo FieldName
fieldName
askFieldInfo ::
(MonadError QErr m) =>
FieldInfoMap fieldInfo ->
FieldName ->
m fieldInfo
askFieldInfo :: FieldInfoMap fieldInfo -> FieldName -> m fieldInfo
askFieldInfo FieldInfoMap fieldInfo
m FieldName
f =
Maybe fieldInfo -> m fieldInfo -> m fieldInfo
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
onNothing (FieldName -> FieldInfoMap fieldInfo -> Maybe fieldInfo
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup FieldName
f FieldInfoMap fieldInfo
m) (m fieldInfo -> m fieldInfo) -> m fieldInfo -> m fieldInfo
forall a b. (a -> b) -> a -> b
$ Code -> Text -> m fieldInfo
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotExists (FieldName
f FieldName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" does not exist")
askColumnType ::
(MonadError QErr m, Backend backend) =>
FieldInfoMap (FieldInfo backend) ->
Column backend ->
Text ->
m (ColumnType backend)
askColumnType :: FieldInfoMap (FieldInfo backend)
-> Column backend -> Text -> m (ColumnType backend)
askColumnType FieldInfoMap (FieldInfo backend)
m Column backend
c Text
msg =
ColumnInfo backend -> ColumnType backend
forall (b :: BackendType). ColumnInfo b -> ColumnType b
ciType (ColumnInfo backend -> ColumnType backend)
-> m (ColumnInfo backend) -> m (ColumnType backend)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldInfoMap (FieldInfo backend)
-> Column backend -> Text -> m (ColumnInfo backend)
forall (m :: * -> *) (backend :: BackendType).
(MonadError QErr m, Backend backend) =>
FieldInfoMap (FieldInfo backend)
-> Column backend -> Text -> m (ColumnInfo backend)
askColInfo FieldInfoMap (FieldInfo backend)
m Column backend
c Text
msg
askColInfo ::
forall m backend.
(MonadError QErr m, Backend backend) =>
FieldInfoMap (FieldInfo backend) ->
Column backend ->
Text ->
m (ColumnInfo backend)
askColInfo :: FieldInfoMap (FieldInfo backend)
-> Column backend -> Text -> m (ColumnInfo backend)
askColInfo FieldInfoMap (FieldInfo backend)
m Column backend
c Text
msg = do
FieldInfo backend
fieldInfo <-
(Text -> Text) -> m (FieldInfo backend) -> m (FieldInfo backend)
forall (m :: * -> *) a. QErrM m => (Text -> Text) -> m a -> m a
modifyErr (Text
"column " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (m (FieldInfo backend) -> m (FieldInfo backend))
-> m (FieldInfo backend) -> m (FieldInfo backend)
forall a b. (a -> b) -> a -> b
$
FieldInfoMap (FieldInfo backend)
-> FieldName -> m (FieldInfo backend)
forall (m :: * -> *) fieldInfo.
MonadError QErr m =>
FieldInfoMap fieldInfo -> FieldName -> m fieldInfo
askFieldInfo FieldInfoMap (FieldInfo backend)
m (Column backend -> FieldName
forall (b :: BackendType). Backend b => Column b -> FieldName
fromCol @backend Column backend
c)
case FieldInfo backend
fieldInfo of
(FIColumn ColumnInfo backend
colInfo) -> ColumnInfo backend -> m (ColumnInfo backend)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ColumnInfo backend
colInfo
(FIRelationship RelInfo backend
_) -> Text -> m (ColumnInfo backend)
throwErr Text
"relationship"
(FIComputedField ComputedFieldInfo backend
_) -> Text -> m (ColumnInfo backend)
throwErr Text
"computed field"
(FIRemoteRelationship RemoteFieldInfo (DBJoinField backend)
_) -> Text -> m (ColumnInfo backend)
throwErr Text
"remote relationship"
where
throwErr :: Text -> m (ColumnInfo backend)
throwErr Text
fieldType =
QErr -> m (ColumnInfo backend)
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (QErr -> m (ColumnInfo backend)) -> QErr -> m (ColumnInfo backend)
forall a b. (a -> b) -> a -> b
$
Code -> Text -> QErr
err400 Code
UnexpectedPayload (Text -> QErr) -> Text -> QErr
forall a b. (a -> b) -> a -> b
$
Text
"expecting a database column; but, "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Column backend
c Column backend -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" is a "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
fieldType
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"; "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
msg
askComputedFieldInfo ::
(MonadError QErr m) =>
FieldInfoMap (FieldInfo backend) ->
ComputedFieldName ->
m (ComputedFieldInfo backend)
askComputedFieldInfo :: FieldInfoMap (FieldInfo backend)
-> ComputedFieldName -> m (ComputedFieldInfo backend)
askComputedFieldInfo FieldInfoMap (FieldInfo backend)
fields ComputedFieldName
computedField = do
FieldInfo backend
fieldInfo <-
(Text -> Text) -> m (FieldInfo backend) -> m (FieldInfo backend)
forall (m :: * -> *) a. QErrM m => (Text -> Text) -> m a -> m a
modifyErr (Text
"computed field " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (m (FieldInfo backend) -> m (FieldInfo backend))
-> m (FieldInfo backend) -> m (FieldInfo backend)
forall a b. (a -> b) -> a -> b
$
FieldInfoMap (FieldInfo backend)
-> FieldName -> m (FieldInfo backend)
forall (m :: * -> *) fieldInfo.
MonadError QErr m =>
FieldInfoMap fieldInfo -> FieldName -> m fieldInfo
askFieldInfo FieldInfoMap (FieldInfo backend)
fields (FieldName -> m (FieldInfo backend))
-> FieldName -> m (FieldInfo backend)
forall a b. (a -> b) -> a -> b
$ ComputedFieldName -> FieldName
fromComputedField ComputedFieldName
computedField
case FieldInfo backend
fieldInfo of
(FIColumn ColumnInfo backend
_) -> Text -> m (ComputedFieldInfo backend)
throwErr Text
"column"
(FIRelationship RelInfo backend
_) -> Text -> m (ComputedFieldInfo backend)
throwErr Text
"relationship"
(FIRemoteRelationship RemoteFieldInfo (DBJoinField backend)
_) -> Text -> m (ComputedFieldInfo backend)
throwErr Text
"remote relationship"
(FIComputedField ComputedFieldInfo backend
cci) -> ComputedFieldInfo backend -> m (ComputedFieldInfo backend)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ComputedFieldInfo backend
cci
where
throwErr :: Text -> m (ComputedFieldInfo backend)
throwErr Text
fieldType =
QErr -> m (ComputedFieldInfo backend)
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (QErr -> m (ComputedFieldInfo backend))
-> QErr -> m (ComputedFieldInfo backend)
forall a b. (a -> b) -> a -> b
$
Code -> Text -> QErr
err400 Code
UnexpectedPayload (Text -> QErr) -> Text -> QErr
forall a b. (a -> b) -> a -> b
$
Text
"expecting a computed field; but, "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ComputedFieldName
computedField ComputedFieldName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" is a "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
fieldType
assertColumnExists ::
forall backend m.
(MonadError QErr m, Backend backend) =>
FieldInfoMap (FieldInfo backend) ->
Text ->
Column backend ->
m ()
assertColumnExists :: FieldInfoMap (FieldInfo backend) -> Text -> Column backend -> m ()
assertColumnExists FieldInfoMap (FieldInfo backend)
m Text
msg Column backend
c = do
m (ColumnInfo backend) -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m (ColumnInfo backend) -> m ()) -> m (ColumnInfo backend) -> m ()
forall a b. (a -> b) -> a -> b
$ FieldInfoMap (FieldInfo backend)
-> Column backend -> Text -> m (ColumnInfo backend)
forall (m :: * -> *) (backend :: BackendType).
(MonadError QErr m, Backend backend) =>
FieldInfoMap (FieldInfo backend)
-> Column backend -> Text -> m (ColumnInfo backend)
askColInfo FieldInfoMap (FieldInfo backend)
m Column backend
c Text
msg
askRelType ::
(MonadError QErr m) =>
FieldInfoMap (FieldInfo backend) ->
RelName ->
Text ->
m (RelInfo backend)
askRelType :: FieldInfoMap (FieldInfo backend)
-> RelName -> Text -> m (RelInfo backend)
askRelType FieldInfoMap (FieldInfo backend)
m RelName
r Text
msg = do
FieldInfo backend
colInfo <-
(Text -> Text) -> m (FieldInfo backend) -> m (FieldInfo backend)
forall (m :: * -> *) a. QErrM m => (Text -> Text) -> m a -> m a
modifyErr (Text
"relationship " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (m (FieldInfo backend) -> m (FieldInfo backend))
-> m (FieldInfo backend) -> m (FieldInfo backend)
forall a b. (a -> b) -> a -> b
$
FieldInfoMap (FieldInfo backend)
-> FieldName -> m (FieldInfo backend)
forall (m :: * -> *) fieldInfo.
MonadError QErr m =>
FieldInfoMap fieldInfo -> FieldName -> m fieldInfo
askFieldInfo FieldInfoMap (FieldInfo backend)
m (RelName -> FieldName
fromRel RelName
r)
case FieldInfo backend
colInfo of
(FIRelationship RelInfo backend
relInfo) -> RelInfo backend -> m (RelInfo backend)
forall (m :: * -> *) a. Monad m => a -> m a
return RelInfo backend
relInfo
FieldInfo backend
_ ->
QErr -> m (RelInfo backend)
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (QErr -> m (RelInfo backend)) -> QErr -> m (RelInfo backend)
forall a b. (a -> b) -> a -> b
$
Code -> Text -> QErr
err400 Code
UnexpectedPayload (Text -> QErr) -> Text -> QErr
forall a b. (a -> b) -> a -> b
$
Text
"expecting a relationship; but, "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> RelName
r RelName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" is a postgres column; "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
msg
askRemoteRel ::
(MonadError QErr m) =>
FieldInfoMap (FieldInfo backend) ->
RelName ->
m (RemoteFieldInfo (DBJoinField backend))
askRemoteRel :: FieldInfoMap (FieldInfo backend)
-> RelName -> m (RemoteFieldInfo (DBJoinField backend))
askRemoteRel FieldInfoMap (FieldInfo backend)
fieldInfoMap RelName
relName = do
FieldInfo backend
fieldInfo <- FieldInfoMap (FieldInfo backend)
-> FieldName -> m (FieldInfo backend)
forall (m :: * -> *) fieldInfo.
MonadError QErr m =>
FieldInfoMap fieldInfo -> FieldName -> m fieldInfo
askFieldInfo FieldInfoMap (FieldInfo backend)
fieldInfoMap (RelName -> FieldName
fromRemoteRelationship RelName
relName)
case FieldInfo backend
fieldInfo of
(FIRemoteRelationship RemoteFieldInfo (DBJoinField backend)
remoteFieldInfo) -> RemoteFieldInfo (DBJoinField backend)
-> m (RemoteFieldInfo (DBJoinField backend))
forall (m :: * -> *) a. Monad m => a -> m a
return RemoteFieldInfo (DBJoinField backend)
remoteFieldInfo
FieldInfo backend
_ ->
Code -> Text -> m (RemoteFieldInfo (DBJoinField backend))
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
UnexpectedPayload Text
"expecting a remote relationship"
mkAdminRolePermInfo :: Backend b => TableCoreInfo b -> RolePermInfo b
mkAdminRolePermInfo :: TableCoreInfo b -> RolePermInfo b
mkAdminRolePermInfo TableCoreInfo b
tableInfo =
Maybe (InsPermInfo b)
-> Maybe (SelPermInfo b)
-> Maybe (UpdPermInfo b)
-> Maybe (DelPermInfo b)
-> RolePermInfo b
forall (b :: BackendType).
Maybe (InsPermInfo b)
-> Maybe (SelPermInfo b)
-> Maybe (UpdPermInfo b)
-> Maybe (DelPermInfo b)
-> RolePermInfo b
RolePermInfo (InsPermInfo b -> Maybe (InsPermInfo b)
forall a. a -> Maybe a
Just InsPermInfo b
i) (SelPermInfo b -> Maybe (SelPermInfo b)
forall a. a -> Maybe a
Just SelPermInfo b
s) (UpdPermInfo b -> Maybe (UpdPermInfo b)
forall a. a -> Maybe a
Just UpdPermInfo b
u) (DelPermInfo b -> Maybe (DelPermInfo b)
forall a. a -> Maybe a
Just DelPermInfo b
d)
where
fields :: FieldInfoMap (FieldInfo b)
fields = TableCoreInfo b -> FieldInfoMap (FieldInfo b)
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> FieldInfoMap field
_tciFieldInfoMap TableCoreInfo b
tableInfo
pgCols :: [Column b]
pgCols = (ColumnInfo b -> Column b) -> [ColumnInfo b] -> [Column b]
forall a b. (a -> b) -> [a] -> [b]
map ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ([ColumnInfo b] -> [Column b]) -> [ColumnInfo b] -> [Column b]
forall a b. (a -> b) -> a -> b
$ FieldInfoMap (FieldInfo b) -> [ColumnInfo b]
forall (backend :: BackendType).
FieldInfoMap (FieldInfo backend) -> [ColumnInfo backend]
getCols FieldInfoMap (FieldInfo b)
fields
pgColsWithFilter :: HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
pgColsWithFilter = [(Column b, Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList ([(Column b, Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b)))
-> [(Column b, Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall a b. (a -> b) -> a -> b
$ (Column b -> (Column b, Maybe (AnnColumnCaseBoolExpPartialSQL b)))
-> [Column b]
-> [(Column b, Maybe (AnnColumnCaseBoolExpPartialSQL b))]
forall a b. (a -> b) -> [a] -> [b]
map (,Maybe (AnnColumnCaseBoolExpPartialSQL b)
forall a. Maybe a
Nothing) [Column b]
pgCols
computedFields :: HashSet ComputedFieldName
computedFields =
[ComputedFieldName] -> HashSet ComputedFieldName
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HS.fromList ([ComputedFieldName] -> HashSet ComputedFieldName)
-> [ComputedFieldName] -> HashSet ComputedFieldName
forall a b. (a -> b) -> a -> b
$ (ComputedFieldInfo b -> ComputedFieldName)
-> [ComputedFieldInfo b] -> [ComputedFieldName]
forall a b. (a -> b) -> [a] -> [b]
map ComputedFieldInfo b -> ComputedFieldName
forall (b :: BackendType). ComputedFieldInfo b -> ComputedFieldName
_cfiName ([ComputedFieldInfo b] -> [ComputedFieldName])
-> [ComputedFieldInfo b] -> [ComputedFieldName]
forall a b. (a -> b) -> a -> b
$ [ComputedFieldInfo b] -> [ComputedFieldInfo b]
forall (backend :: BackendType).
Backend backend =>
[ComputedFieldInfo backend] -> [ComputedFieldInfo backend]
removeComputedFieldsReturningExistingTable ([ComputedFieldInfo b] -> [ComputedFieldInfo b])
-> [ComputedFieldInfo b] -> [ComputedFieldInfo b]
forall a b. (a -> b) -> a -> b
$ FieldInfoMap (FieldInfo b) -> [ComputedFieldInfo b]
forall (backend :: BackendType).
FieldInfoMap (FieldInfo backend) -> [ComputedFieldInfo backend]
getComputedFieldInfos FieldInfoMap (FieldInfo b)
fields
computedFields' :: HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
computedFields' = HashSet ComputedFieldName -> HashMap ComputedFieldName ()
forall a. HashSet a -> HashMap a ()
HS.toMap HashSet ComputedFieldName
computedFields HashMap ComputedFieldName ()
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Maybe (AnnColumnCaseBoolExpPartialSQL b)
forall a. Maybe a
Nothing
tableName :: TableName b
tableName = TableCoreInfo b -> TableName b
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> TableName b
_tciName TableCoreInfo b
tableInfo
i :: InsPermInfo b
i = HashSet (Column b)
-> AnnBoolExpPartialSQL b
-> PreSetColsPartial b
-> Bool
-> HashSet Text
-> InsPermInfo b
forall (b :: BackendType).
HashSet (Column b)
-> AnnBoolExpPartialSQL b
-> PreSetColsPartial b
-> Bool
-> HashSet Text
-> InsPermInfo b
InsPermInfo ([Column b] -> HashSet (Column b)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HS.fromList [Column b]
pgCols) AnnBoolExpPartialSQL b
forall (backend :: BackendType) scalar. AnnBoolExp backend scalar
annBoolExpTrue PreSetColsPartial b
forall k v. HashMap k v
M.empty Bool
False HashSet Text
forall a. Monoid a => a
mempty
s :: SelPermInfo b
s = HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> AnnBoolExpPartialSQL b
-> Maybe Int
-> Bool
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> SelPermInfo b
forall (b :: BackendType).
HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> AnnBoolExpPartialSQL b
-> Maybe Int
-> Bool
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> SelPermInfo b
SelPermInfo HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
pgColsWithFilter HashMap
ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
computedFields' AnnBoolExpPartialSQL b
forall (backend :: BackendType) scalar. AnnBoolExp backend scalar
annBoolExpTrue Maybe Int
forall a. Maybe a
Nothing Bool
True HashSet Text
forall a. Monoid a => a
mempty AllowedRootFields QueryRootFieldType
forall rootFieldType. AllowedRootFields rootFieldType
ARFAllowAllRootFields AllowedRootFields SubscriptionRootFieldType
forall rootFieldType. AllowedRootFields rootFieldType
ARFAllowAllRootFields
u :: UpdPermInfo b
u = HashSet (Column b)
-> TableName b
-> AnnBoolExpPartialSQL b
-> Maybe (AnnBoolExpPartialSQL b)
-> PreSetColsPartial b
-> Bool
-> HashSet Text
-> UpdPermInfo b
forall (b :: BackendType).
HashSet (Column b)
-> TableName b
-> AnnBoolExpPartialSQL b
-> Maybe (AnnBoolExpPartialSQL b)
-> PreSetColsPartial b
-> Bool
-> HashSet Text
-> UpdPermInfo b
UpdPermInfo ([Column b] -> HashSet (Column b)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HS.fromList [Column b]
pgCols) TableName b
tableName AnnBoolExpPartialSQL b
forall (backend :: BackendType) scalar. AnnBoolExp backend scalar
annBoolExpTrue Maybe (AnnBoolExpPartialSQL b)
forall a. Maybe a
Nothing PreSetColsPartial b
forall k v. HashMap k v
M.empty Bool
False HashSet Text
forall a. Monoid a => a
mempty
d :: DelPermInfo b
d = TableName b
-> AnnBoolExpPartialSQL b -> Bool -> HashSet Text -> DelPermInfo b
forall (b :: BackendType).
TableName b
-> AnnBoolExpPartialSQL b -> Bool -> HashSet Text -> DelPermInfo b
DelPermInfo TableName b
tableName AnnBoolExpPartialSQL b
forall (backend :: BackendType) scalar. AnnBoolExp backend scalar
annBoolExpTrue Bool
False HashSet Text
forall a. Monoid a => a
mempty