2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.RQLGenerator.GenCommon
|
2022-04-08 09:48:37 +03:00
|
|
|
( genAnnBoolExpFld,
|
|
|
|
genAnnotatedOrderByElement,
|
|
|
|
|
|
|
|
-- * Associated Types
|
|
|
|
genColumn,
|
|
|
|
genTableName,
|
|
|
|
genScalarType,
|
|
|
|
genFunctionName,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.IR.Name qualified as Name
|
|
|
|
import Hasura.Backends.DataConnector.IR.Scalar.Type qualified as ScalarType
|
2022-04-08 09:48:37 +03:00
|
|
|
import Hasura.Generator.Common (defaultRange, genArbitraryUnicodeText, genHashMap)
|
|
|
|
import Hasura.Prelude (coerce, fmap, pure, ($), (<$>), (<*>))
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.IR
|
2022-04-08 09:48:37 +03:00
|
|
|
import Hasura.RQL.IR.Generator (genAnnBoolExp, genAnnotatedAggregateOrderBy, genColumnInfo, genInsertOrder, genRelName, genRelType)
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Backend
|
|
|
|
import Hasura.RQL.Types.Relationships.Local
|
|
|
|
import Hasura.SQL.Backend
|
2022-04-08 09:48:37 +03:00
|
|
|
import Hedgehog (MonadGen)
|
|
|
|
import Hedgehog.Gen (bool_, choice, element, list)
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
genAnnBoolExpFld ::
|
|
|
|
MonadGen m =>
|
|
|
|
m a ->
|
2022-05-02 08:03:12 +03:00
|
|
|
m (AnnBoolExpFld 'DataConnector a)
|
2022-04-08 09:48:37 +03:00
|
|
|
genAnnBoolExpFld genA = choice [column, relationship]
|
|
|
|
where
|
|
|
|
column =
|
|
|
|
AVColumn
|
2022-05-02 08:03:12 +03:00
|
|
|
<$> genColumnInfo @_ @('DataConnector)
|
2022-04-08 09:48:37 +03:00
|
|
|
genColumn
|
|
|
|
genTableName
|
|
|
|
genScalarType
|
|
|
|
<*> list defaultRange (genOpExpG genA)
|
|
|
|
relationship =
|
|
|
|
AVRelationship
|
|
|
|
<$> genRelInfo
|
|
|
|
<*> genAnnBoolExp (genAnnBoolExpFld genA) genTableName
|
|
|
|
|
|
|
|
genAnnotatedOrderByElement ::
|
|
|
|
MonadGen m =>
|
|
|
|
m a ->
|
2022-05-02 08:03:12 +03:00
|
|
|
m (AnnotatedOrderByElement 'DataConnector a)
|
2022-04-08 09:48:37 +03:00
|
|
|
genAnnotatedOrderByElement genA =
|
|
|
|
choice
|
|
|
|
[ column,
|
|
|
|
objectRelation,
|
|
|
|
arrayAggregation
|
|
|
|
]
|
|
|
|
where
|
|
|
|
column =
|
|
|
|
AOCColumn
|
|
|
|
<$> genColumnInfo
|
|
|
|
genColumn
|
|
|
|
genTableName
|
|
|
|
genScalarType
|
|
|
|
objectRelation =
|
|
|
|
AOCObjectRelation
|
|
|
|
<$> genRelInfo
|
|
|
|
<*> genAnnBoolExp
|
|
|
|
(genAnnBoolExpFld genA)
|
|
|
|
genTableName
|
|
|
|
<*> genAnnotatedOrderByElement genA
|
|
|
|
arrayAggregation =
|
|
|
|
AOCArrayAggregation
|
|
|
|
<$> genRelInfo
|
|
|
|
<*> genAnnBoolExp
|
|
|
|
(genAnnBoolExpFld genA)
|
|
|
|
genTableName
|
|
|
|
<*> genAnnotatedAggregateOrderBy
|
|
|
|
genColumn
|
|
|
|
genTableName
|
|
|
|
genScalarType
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
genColumn :: MonadGen m => m (Column 'DataConnector)
|
2022-04-08 09:48:37 +03:00
|
|
|
genColumn = coerce <$> genArbitraryUnicodeText defaultRange
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
genTableName :: MonadGen m => m (TableName 'DataConnector)
|
2022-04-08 09:48:37 +03:00
|
|
|
genTableName = coerce <$> genArbitraryUnicodeText defaultRange
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
genScalarType :: MonadGen m => m (ScalarType 'DataConnector)
|
2022-04-08 09:48:37 +03:00
|
|
|
genScalarType =
|
|
|
|
choice
|
|
|
|
[ pure ScalarType.String,
|
|
|
|
pure ScalarType.Number,
|
|
|
|
pure ScalarType.Bool
|
|
|
|
]
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
genFunctionName :: MonadGen m => m (FunctionName 'DataConnector)
|
2022-04-08 09:48:37 +03:00
|
|
|
genFunctionName = coerce <$> genArbitraryUnicodeText defaultRange
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Unexported
|
|
|
|
|
|
|
|
genOpExpG ::
|
|
|
|
MonadGen m =>
|
|
|
|
m a ->
|
2022-05-02 08:03:12 +03:00
|
|
|
m (OpExpG 'DataConnector a)
|
2022-04-08 09:48:37 +03:00
|
|
|
genOpExpG genA =
|
|
|
|
choice
|
|
|
|
[ acast,
|
|
|
|
aeq,
|
|
|
|
ane,
|
|
|
|
ain,
|
|
|
|
anin,
|
|
|
|
agt,
|
|
|
|
alt,
|
|
|
|
agte,
|
|
|
|
alte,
|
|
|
|
alike,
|
|
|
|
anlike,
|
|
|
|
ceq,
|
|
|
|
cne,
|
|
|
|
cgt,
|
|
|
|
clt,
|
|
|
|
cgte,
|
|
|
|
clte,
|
|
|
|
anIsNull,
|
|
|
|
anIsNotNull
|
|
|
|
]
|
|
|
|
where
|
|
|
|
acast =
|
|
|
|
ACast
|
|
|
|
<$> genHashMap
|
|
|
|
genScalarType
|
|
|
|
(list defaultRange $ genOpExpG genA)
|
|
|
|
defaultRange
|
|
|
|
aeq = AEQ <$> bool_ <*> genA
|
|
|
|
ane = ANE <$> bool_ <*> genA
|
|
|
|
ain = AIN <$> genA
|
|
|
|
anin = ANIN <$> genA
|
|
|
|
agt = AGT <$> genA
|
|
|
|
alt = ALT <$> genA
|
|
|
|
agte = AGTE <$> genA
|
|
|
|
alte = ALTE <$> genA
|
|
|
|
alike = ALIKE <$> genA
|
|
|
|
anlike = ANLIKE <$> genA
|
|
|
|
ceq = fmap CEQ $ RootOrCurrentColumn <$> genRootOrCurrent <*> genColumn
|
|
|
|
cne = fmap CNE $ RootOrCurrentColumn <$> genRootOrCurrent <*> genColumn
|
|
|
|
cgt = fmap CGT $ RootOrCurrentColumn <$> genRootOrCurrent <*> genColumn
|
|
|
|
clt = fmap CLT $ RootOrCurrentColumn <$> genRootOrCurrent <*> genColumn
|
|
|
|
cgte = fmap CGTE $ RootOrCurrentColumn <$> genRootOrCurrent <*> genColumn
|
|
|
|
clte = fmap CLTE $ RootOrCurrentColumn <$> genRootOrCurrent <*> genColumn
|
|
|
|
anIsNull = pure ANISNULL
|
|
|
|
anIsNotNull = pure ANISNOTNULL
|
|
|
|
genRootOrCurrent = element [IsRoot, IsCurrent]
|
|
|
|
|
|
|
|
genRelInfo ::
|
|
|
|
MonadGen m =>
|
2022-05-02 08:03:12 +03:00
|
|
|
m (RelInfo 'DataConnector)
|
2022-04-08 09:48:37 +03:00
|
|
|
genRelInfo =
|
|
|
|
RelInfo
|
|
|
|
<$> genRelName
|
|
|
|
<*> genRelType
|
|
|
|
<*> genHashMap genColumn genColumn defaultRange
|
|
|
|
<*> genTableName
|
|
|
|
<*> bool_
|
|
|
|
<*> genInsertOrder
|