mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-24 16:03:37 +03:00
342391f39d
This upgrades the version of Ormolu required by the HGE repository to v0.5.0.1, and reformats all code accordingly. Ormolu v0.5 reformats code that uses infix operators. This is mostly useful, adding newlines and indentation to make it clear which operators are applied first, but in some cases, it's unpleasant. To make this easier on the eyes, I had to do the following: * Add a few fixity declarations (search for `infix`) * Add parentheses to make precedence clear, allowing Ormolu to keep everything on one line * Rename `relevantEq` to `(==~)` in #6651 and set it to `infix 4` * Add a few _.ormolu_ files (thanks to @hallettj for helping me get started), mostly for Autodocodec operators that don't have explicit fixity declarations In general, I think these changes are quite reasonable. They mostly affect indentation. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6675 GitOrigin-RevId: cd47d87f1d089fb0bc9dcbbe7798dbceedcd7d83
63 lines
2.0 KiB
Haskell
63 lines
2.0 KiB
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
module Hasura.GraphQL.Execute.Subscription.Options
|
|
( SubscriptionsOptions (..),
|
|
LiveQueriesOptions,
|
|
StreamQueriesOptions,
|
|
BatchSize (..),
|
|
RefetchInterval (..),
|
|
mkSubscriptionsOptions,
|
|
mkBatchSize,
|
|
mkRefetchInterval,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson qualified as J
|
|
import Hasura.Base.Instances ()
|
|
import Hasura.Prelude
|
|
import Refined (NonNegative, Refined, refineFail, refineTH)
|
|
|
|
data SubscriptionsOptions = SubscriptionsOptions
|
|
{ _lqoBatchSize :: !BatchSize,
|
|
_lqoRefetchInterval :: !RefetchInterval
|
|
}
|
|
deriving (Show, Eq)
|
|
|
|
type LiveQueriesOptions = SubscriptionsOptions
|
|
|
|
type StreamQueriesOptions = SubscriptionsOptions
|
|
|
|
mkSubscriptionsOptions :: Maybe BatchSize -> Maybe RefetchInterval -> SubscriptionsOptions
|
|
mkSubscriptionsOptions batchSize refetchInterval =
|
|
SubscriptionsOptions
|
|
{ _lqoBatchSize = fromMaybe (BatchSize $$(refineTH 100)) batchSize,
|
|
_lqoRefetchInterval = fromMaybe (RefetchInterval $$(refineTH 1)) refetchInterval
|
|
}
|
|
|
|
instance J.ToJSON SubscriptionsOptions where
|
|
toJSON (SubscriptionsOptions batchSize refetchInterval) =
|
|
J.object
|
|
[ "batch_size" J..= batchSize,
|
|
"refetch_delay" J..= refetchInterval
|
|
]
|
|
|
|
instance J.FromJSON SubscriptionsOptions where
|
|
parseJSON = J.withObject "live query options" \o ->
|
|
SubscriptionsOptions
|
|
<$> o J..: "batch_size"
|
|
<*> o J..: "refetch_delay"
|
|
|
|
newtype BatchSize = BatchSize {unBatchSize :: Refined NonNegative Int}
|
|
deriving (Show, Eq, J.ToJSON, J.FromJSON)
|
|
|
|
mkBatchSize :: Int -> Maybe BatchSize
|
|
mkBatchSize x = BatchSize <$> refineFail 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 :: Refined NonNegative DiffTime}
|
|
deriving (Show, Eq, J.ToJSON, J.FromJSON)
|
|
|
|
mkRefetchInterval :: DiffTime -> Maybe RefetchInterval
|
|
mkRefetchInterval x = RefetchInterval <$> refineFail x
|