mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-25 00:13:11 +03:00
acde210fdc
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4460 GitOrigin-RevId: 7b772cd9fba6b612ad05eb1aca1fa13e6ae8556d
30 lines
1.2 KiB
Haskell
30 lines
1.2 KiB
Haskell
module Hasura.Backends.Postgres.RQLGenerator.GenSelectFromG
|
|
( genSelectFromG,
|
|
)
|
|
where
|
|
|
|
import Hasura.Backends.Postgres.RQLGenerator.GenAssociatedTypes
|
|
import Hasura.Generator.Common (defaultRange)
|
|
import Hasura.Prelude hiding (choice, maybe)
|
|
import Hasura.RQL.IR.Generator (genFunctionArgsExpG, genIdentifier)
|
|
import Hasura.RQL.IR.Select (SelectFromG (..))
|
|
import Hasura.SQL.Backend (BackendType (..), PostgresKind (..))
|
|
import Hedgehog (MonadGen)
|
|
import Hedgehog.Gen qualified as Gen
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | @genA@ is a generator for some type @a@ which is threaded through
|
|
-- the 'SelectFromG' AST. At the leaf nodes this is in an 'ArgumentExp
|
|
-- a' term.
|
|
genSelectFromG :: MonadGen m => m a -> m (SelectFromG ('Postgres 'Vanilla) a)
|
|
genSelectFromG genA = Gen.choice [fromTable, fromIdentifier, fromFunction]
|
|
where
|
|
fromTable = FromTable <$> genTableName
|
|
fromIdentifier = FromIdentifier <$> genIdentifier
|
|
fromFunction = do
|
|
funcName <- genFunctionName
|
|
funcArgsExp <- genFunctionArgsExpG $ genFunctionArgumentExp genA
|
|
defList <- Gen.maybe . Gen.list defaultRange $ liftA2 (,) genColumn genScalarType
|
|
pure $ FromFunction funcName funcArgsExp defList
|