mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
55 lines
1.7 KiB
Haskell
55 lines
1.7 KiB
Haskell
module Hasura.GraphQL.Execute.LiveQuery.Options
|
|
( LiveQueriesOptions (..),
|
|
BatchSize,
|
|
unBatchSize,
|
|
RefetchInterval,
|
|
unRefetchInterval,
|
|
mkLiveQueriesOptions,
|
|
mkBatchSize,
|
|
mkRefetchInterval,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson qualified as J
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Common
|
|
|
|
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,
|
|
_lqoRefetchInterval = fromMaybe (RefetchInterval 1) refetchInterval
|
|
}
|
|
|
|
instance J.ToJSON LiveQueriesOptions where
|
|
toJSON (LiveQueriesOptions batchSize refetchInterval) =
|
|
J.object
|
|
[ "batch_size" J..= batchSize,
|
|
"refetch_delay" J..= refetchInterval
|
|
]
|
|
|
|
instance J.FromJSON LiveQueriesOptions where
|
|
parseJSON = J.withObject "live query options" \o ->
|
|
LiveQueriesOptions <$> o J..: "batch_size"
|
|
<*> o J..: "refetch_delay"
|
|
|
|
newtype BatchSize = BatchSize {unBatchSize :: NonNegativeInt}
|
|
deriving (Show, Eq, J.ToJSON, J.FromJSON)
|
|
|
|
mkBatchSize :: Int -> Maybe BatchSize
|
|
mkBatchSize x = BatchSize <$> mkNonNegativeInt x
|
|
|
|
-- TODO this is treated as milliseconds in fromEnv and as seconds in ToJSON.
|
|
-- ideally this would have e.g. ... unRefetchInterval :: Milliseconds
|
|
newtype RefetchInterval = RefetchInterval {unRefetchInterval :: NonNegativeDiffTime}
|
|
deriving (Show, Eq, J.ToJSON, J.FromJSON)
|
|
|
|
mkRefetchInterval :: DiffTime -> Maybe RefetchInterval
|
|
mkRefetchInterval x = RefetchInterval <$> mkNonNegativeDiffTime x
|