2019-08-28 15:19:21 +03:00
|
|
|
module Hasura.GraphQL.Execute.LiveQuery.Options
|
|
|
|
( LiveQueriesOptions(..)
|
|
|
|
, BatchSize(..)
|
|
|
|
, RefetchInterval(..)
|
|
|
|
, mkLiveQueriesOptions
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
|
|
|
import qualified Data.Aeson as J
|
|
|
|
|
|
|
|
data LiveQueriesOptions
|
|
|
|
= LiveQueriesOptions
|
|
|
|
{ _lqoBatchSize :: !BatchSize
|
|
|
|
, _lqoRefetchInterval :: !RefetchInterval
|
|
|
|
} deriving (Show, Eq)
|
|
|
|
|
|
|
|
mkLiveQueriesOptions :: Maybe BatchSize -> Maybe RefetchInterval -> LiveQueriesOptions
|
|
|
|
mkLiveQueriesOptions batchSize refetchInterval = LiveQueriesOptions
|
|
|
|
{ _lqoBatchSize = fromMaybe (BatchSize 100) batchSize
|
2020-01-16 04:56:57 +03:00
|
|
|
, _lqoRefetchInterval = fromMaybe (RefetchInterval 1) refetchInterval
|
2019-08-28 15:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
instance J.ToJSON LiveQueriesOptions where
|
|
|
|
toJSON (LiveQueriesOptions batchSize refetchInterval) =
|
|
|
|
J.object [ "batch_size" J..= batchSize
|
|
|
|
, "refetch_delay" J..= refetchInterval
|
|
|
|
]
|
|
|
|
|
|
|
|
newtype BatchSize = BatchSize { unBatchSize :: Int }
|
|
|
|
deriving (Show, Eq, J.ToJSON)
|
|
|
|
|
2020-01-16 04:56:57 +03:00
|
|
|
-- TODO this is treated as milliseconds in fromEnv and as seconds in ToJSON.
|
|
|
|
-- ideally this would have e.g. ... unRefetchInterval :: Milliseconds
|
2019-08-28 15:19:21 +03:00
|
|
|
newtype RefetchInterval = RefetchInterval { unRefetchInterval :: DiffTime }
|
|
|
|
deriving (Show, Eq, J.ToJSON)
|