1
0
mirror of https://github.com/hasura/graphql-engine.git synced 2024-12-26 08:52:12 +03:00
graphql-engine/server/src-lib/Hasura/Backends/DataWrapper/API/V0/Query.hs
Solomon 94331e23f5 GDW-15 Serializable Types
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3924
GitOrigin-RevId: 75b276edcd2d1f88bbdbed1b96b08708f9c68450
2022-03-16 04:13:08 +00:00

53 lines
1.7 KiB
Haskell

--
module Hasura.Backends.DataWrapper.API.V0.Query
( Query (..),
Field (..),
ForeignKey (..),
PrimaryKey (..),
)
where
--------------------------------------------------------------------------------
import Data.Aeson (FromJSON, ToJSON)
import Data.HashMap.Strict qualified as M
import Hasura.Backends.DataWrapper.API.V0.Column qualified as API.V0
import Hasura.Backends.DataWrapper.API.V0.Expression qualified as API.V0
import Hasura.Backends.DataWrapper.API.V0.OrderBy qualified as API.V0
import Hasura.Backends.DataWrapper.API.V0.Table qualified as API.V0
import Hasura.Prelude
--------------------------------------------------------------------------------
-- | A serializable request to retrieve strutured data from some
-- source.
data Query = Query
{ fields :: M.HashMap Text Field,
from :: API.V0.TableName,
limit :: Maybe Int,
offset :: Maybe Int,
where_ :: Maybe API.V0.Expression,
orderBy :: [API.V0.OrderBy]
}
deriving stock (Eq, Ord, Show, Generic, Data)
--------------------------------------------------------------------------------
-- | A serializable field targeted by a 'Query'.
data Field
= ColumnField API.V0.ColumnName
| RelationshipField (M.HashMap PrimaryKey ForeignKey) Query
deriving stock (Eq, Ord, Show, Generic, Data)
--------------------------------------------------------------------------------
newtype PrimaryKey = PrimaryKey API.V0.ColumnName
deriving stock (Data, Generic)
deriving newtype (Eq, Hashable, Ord, Show, FromJSON, ToJSON)
--------------------------------------------------------------------------------
newtype ForeignKey = ForeignKey API.V0.ColumnName
deriving stock (Data, Generic)
deriving newtype (Eq, Hashable, Ord, Show, FromJSON, ToJSON)