{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Morpheus.Subscriptions.Stream
( toOutStream,
runStreamWS,
runStreamHTTP,
ApiContext (..),
Input (..),
Output,
API (..),
PUB,
SUB,
)
where
import Data.ByteString.Lazy.Char8 (ByteString)
import Data.Morpheus.Error
( globalErrorMessage,
)
import Data.Morpheus.Internal.Utils
( failure,
)
import Data.Morpheus.Subscriptions.Apollo
( ApolloAction (..),
apolloFormat,
toApolloResponse,
)
import Data.Morpheus.Subscriptions.ClientConnectionStore
( ClientConnectionStore,
SessionID (..),
Updates (..),
endSession,
insertConnection,
startSession,
)
import Data.Morpheus.Subscriptions.Event (Event (..))
import Data.Morpheus.Types.IO
( GQLRequest (..),
GQLResponse (..),
)
import Data.Morpheus.Types.Internal.AST
( GQLErrors,
VALID,
Value (..),
)
import Data.Morpheus.Types.Internal.Resolving
( Channel,
ResponseEvent (..),
ResponseStream,
Result (..),
ResultT (..),
runResultT,
)
import Data.UUID (UUID)
import Relude hiding (ByteString)
data API = PUB | SUB
type SUB = 'SUB
type PUB = 'PUB
data
Input
(api :: API)
where
InitConnection :: UUID -> Input SUB
Request :: GQLRequest -> Input PUB
run :: ApiContext SUB e m -> Updates e m -> m ()
run :: ApiContext SUB e m -> Updates e m -> m ()
run SubContext {(ClientConnectionStore e m -> ClientConnectionStore e m) -> m ()
updateStore :: forall event (m :: * -> *).
ApiContext SUB event m
-> (ClientConnectionStore event m -> ClientConnectionStore event m)
-> m ()
updateStore :: (ClientConnectionStore e m -> ClientConnectionStore e m) -> m ()
updateStore} (Updates ClientConnectionStore e m -> ClientConnectionStore e m
changes) = (ClientConnectionStore e m -> ClientConnectionStore e m) -> m ()
updateStore ClientConnectionStore e m -> ClientConnectionStore e m
changes
data ApiContext (api :: API) event (m :: * -> *) where
PubContext ::
{ ApiContext PUB event m -> event -> m ()
eventPublisher :: event -> m ()
} ->
ApiContext PUB event m
SubContext ::
{ ApiContext SUB event m -> m ByteString
listener :: m ByteString,
ApiContext SUB event m -> ByteString -> m ()
callback :: ByteString -> m (),
ApiContext SUB event m
-> (ClientConnectionStore event m -> ClientConnectionStore event m)
-> m ()
updateStore :: (ClientConnectionStore event m -> ClientConnectionStore event m) -> m ()
} ->
ApiContext SUB event m
data
Output
(api :: API)
e
(m :: * -> *)
where
SubOutput ::
{ Output SUB e m
-> ApiContext SUB e m -> m (Either ByteString [Updates e m])
streamWS :: ApiContext SUB e m -> m (Either ByteString [Updates e m])
} ->
Output SUB e m
PubOutput ::
{ Output PUB e m -> ApiContext PUB e m -> m GQLResponse
streamHTTP :: ApiContext PUB e m -> m GQLResponse
} ->
Output PUB e m
handleResponseStream ::
( Monad m,
Eq (Channel e),
Hashable (Channel e)
) =>
SessionID ->
ResponseStream e m (Value VALID) ->
Output SUB e m
handleResponseStream :: SessionID -> ResponseStream e m (Value VALID) -> Output SUB e m
handleResponseStream SessionID
session (ResultT m (Result (ResponseEvent e m) (Value VALID))
res) =
(ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m
forall e (m :: * -> *).
(ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m
SubOutput ((ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m)
-> (ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m
forall a b. (a -> b) -> a -> b
$ m (Either ByteString [Updates e m])
-> ApiContext SUB e m -> m (Either ByteString [Updates e m])
forall a b. a -> b -> a
const (m (Either ByteString [Updates e m])
-> ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> m (Either ByteString [Updates e m])
-> ApiContext SUB e m
-> m (Either ByteString [Updates e m])
forall a b. (a -> b) -> a -> b
$ Result (ResponseEvent e m) (Value VALID)
-> Either ByteString [Updates e m]
unfoldR (Result (ResponseEvent e m) (Value VALID)
-> Either ByteString [Updates e m])
-> m (Result (ResponseEvent e m) (Value VALID))
-> m (Either ByteString [Updates e m])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Result (ResponseEvent e m) (Value VALID))
res
where
execute :: ResponseEvent e m -> Either ByteString (Updates e m)
execute Publish {} = GQLErrors -> Either ByteString (Updates e m)
forall a. GQLErrors -> Either ByteString a
apolloError (GQLErrors -> Either ByteString (Updates e m))
-> GQLErrors -> Either ByteString (Updates e m)
forall a b. (a -> b) -> a -> b
$ Message -> GQLErrors
globalErrorMessage Message
"websocket can only handle subscriptions, not mutations"
execute (Subscribe Channel e
ch e -> m GQLResponse
subRes) = Updates e m -> Either ByteString (Updates e m)
forall a b. b -> Either a b
Right (Updates e m -> Either ByteString (Updates e m))
-> Updates e m -> Either ByteString (Updates e m)
forall a b. (a -> b) -> a -> b
$ Channel e -> (e -> m GQLResponse) -> SessionID -> Updates e m
forall (m :: * -> *) e.
(Monad m, Eq (Channel e), Hashable (Channel e)) =>
Channel e -> (e -> m GQLResponse) -> SessionID -> Updates e m
startSession Channel e
ch e -> m GQLResponse
subRes SessionID
session
unfoldR :: Result (ResponseEvent e m) (Value VALID)
-> Either ByteString [Updates e m]
unfoldR Success {[ResponseEvent e m]
events :: forall events a. Result events a -> [events]
events :: [ResponseEvent e m]
events} = (ResponseEvent e m -> Either ByteString (Updates e m))
-> [ResponseEvent e m] -> Either ByteString [Updates e m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ResponseEvent e m -> Either ByteString (Updates e m)
execute [ResponseEvent e m]
events
unfoldR Failure {GQLErrors
errors :: forall events a. Result events a -> GQLErrors
errors :: GQLErrors
errors} = GQLErrors -> Either ByteString [Updates e m]
forall a. GQLErrors -> Either ByteString a
apolloError GQLErrors
errors
apolloError :: GQLErrors -> Either ByteString a
apolloError :: GQLErrors -> Either ByteString a
apolloError = ByteString -> Either ByteString a
forall a b. a -> Either a b
Left (ByteString -> Either ByteString a)
-> (GQLErrors -> ByteString) -> GQLErrors -> Either ByteString a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ID -> GQLResponse -> ByteString
toApolloResponse (SessionID -> ID
sid SessionID
session) (GQLResponse -> ByteString)
-> (GQLErrors -> GQLResponse) -> GQLErrors -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GQLErrors -> GQLResponse
Errors
handleWSRequest ::
( Monad m,
Functor m,
Eq ch,
Hashable ch
) =>
( GQLRequest ->
ResponseStream (Event ch con) m (Value VALID)
) ->
UUID ->
ByteString ->
Output SUB (Event ch con) m
handleWSRequest :: (GQLRequest -> ResponseStream (Event ch con) m (Value VALID))
-> UUID -> ByteString -> Output SUB (Event ch con) m
handleWSRequest GQLRequest -> ResponseStream (Event ch con) m (Value VALID)
gqlApp UUID
clientId = Either ByteString ApolloAction -> Output SUB (Event ch con) m
handle (Either ByteString ApolloAction -> Output SUB (Event ch con) m)
-> (ByteString -> Either ByteString ApolloAction)
-> ByteString
-> Output SUB (Event ch con) m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either ByteString ApolloAction
apolloFormat
where
handle :: Either ByteString ApolloAction -> Output SUB (Event ch con) m
handle = (ByteString -> Output SUB (Event ch con) m)
-> (ApolloAction -> Output SUB (Event ch con) m)
-> Either ByteString ApolloAction
-> Output SUB (Event ch con) m
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m
forall (m :: * -> *) e.
Applicative m =>
Either ByteString [Updates e m] -> Output SUB e m
liftWS (Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m)
-> (ByteString -> Either ByteString [Updates (Event ch con) m])
-> ByteString
-> Output SUB (Event ch con) m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either ByteString [Updates (Event ch con) m]
forall a b. a -> Either a b
Left) ApolloAction -> Output SUB (Event ch con) m
handleAction
handleAction :: ApolloAction -> Output SUB (Event ch con) m
handleAction ApolloAction
ConnectionInit = Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m
forall (m :: * -> *) e.
Applicative m =>
Either ByteString [Updates e m] -> Output SUB e m
liftWS (Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m)
-> Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m
forall a b. (a -> b) -> a -> b
$ [Updates (Event ch con) m]
-> Either ByteString [Updates (Event ch con) m]
forall a b. b -> Either a b
Right []
handleAction (SessionStart ID
sessionId GQLRequest
request) =
SessionID
-> ResponseStream (Event ch con) m (Value VALID)
-> Output SUB (Event ch con) m
forall (m :: * -> *) e.
(Monad m, Eq (Channel e), Hashable (Channel e)) =>
SessionID -> ResponseStream e m (Value VALID) -> Output SUB e m
handleResponseStream (UUID -> ID -> SessionID
SessionID UUID
clientId ID
sessionId) (GQLRequest -> ResponseStream (Event ch con) m (Value VALID)
gqlApp GQLRequest
request)
handleAction (SessionStop ID
sessionId) =
Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m
forall (m :: * -> *) e.
Applicative m =>
Either ByteString [Updates e m] -> Output SUB e m
liftWS (Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m)
-> Either ByteString [Updates (Event ch con) m]
-> Output SUB (Event ch con) m
forall a b. (a -> b) -> a -> b
$
[Updates (Event ch con) m]
-> Either ByteString [Updates (Event ch con) m]
forall a b. b -> Either a b
Right [SessionID -> Updates (Event ch con) m
forall ch con (m :: * -> *).
(Eq ch, Hashable ch) =>
SessionID -> Updates (Event ch con) m
endSession (UUID -> ID -> SessionID
SessionID UUID
clientId ID
sessionId)]
liftWS ::
Applicative m =>
Either ByteString [Updates e m] ->
Output SUB e m
liftWS :: Either ByteString [Updates e m] -> Output SUB e m
liftWS = (ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m
forall e (m :: * -> *).
(ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m
SubOutput ((ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m)
-> (Either ByteString [Updates e m]
-> ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Either ByteString [Updates e m]
-> Output SUB e m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either ByteString [Updates e m])
-> ApiContext SUB e m -> m (Either ByteString [Updates e m])
forall a b. a -> b -> a
const (m (Either ByteString [Updates e m])
-> ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> (Either ByteString [Updates e m]
-> m (Either ByteString [Updates e m]))
-> Either ByteString [Updates e m]
-> ApiContext SUB e m
-> m (Either ByteString [Updates e m])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either ByteString [Updates e m]
-> m (Either ByteString [Updates e m])
forall (f :: * -> *) a. Applicative f => a -> f a
pure
runStreamWS ::
(Monad m) =>
ApiContext SUB e m ->
Output SUB e m ->
m ()
runStreamWS :: ApiContext SUB e m -> Output SUB e m -> m ()
runStreamWS scope :: ApiContext SUB e m
scope@SubContext {ByteString -> m ()
callback :: ByteString -> m ()
callback :: forall event (m :: * -> *).
ApiContext SUB event m -> ByteString -> m ()
callback} SubOutput {ApiContext SUB e m -> m (Either ByteString [Updates e m])
streamWS :: ApiContext SUB e m -> m (Either ByteString [Updates e m])
streamWS :: forall e (m :: * -> *).
Output SUB e m
-> ApiContext SUB e m -> m (Either ByteString [Updates e m])
streamWS} =
ApiContext SUB e m -> m (Either ByteString [Updates e m])
streamWS ApiContext SUB e m
scope
m (Either ByteString [Updates e m])
-> (Either ByteString [Updates e m] -> m ()) -> m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ByteString -> m ())
-> ([Updates e m] -> m ())
-> Either ByteString [Updates e m]
-> m ()
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ByteString -> m ()
callback ((Updates e m -> m ()) -> [Updates e m] -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (ApiContext SUB e m -> Updates e m -> m ()
forall e (m :: * -> *). ApiContext SUB e m -> Updates e m -> m ()
run ApiContext SUB e m
scope))
runStreamHTTP ::
(Monad m) =>
ApiContext PUB e m ->
Output PUB e m ->
m GQLResponse
runStreamHTTP :: ApiContext PUB e m -> Output PUB e m -> m GQLResponse
runStreamHTTP ApiContext PUB e m
scope PubOutput {ApiContext PUB e m -> m GQLResponse
streamHTTP :: ApiContext PUB e m -> m GQLResponse
streamHTTP :: forall e (m :: * -> *).
Output PUB e m -> ApiContext PUB e m -> m GQLResponse
streamHTTP} =
ApiContext PUB e m -> m GQLResponse
streamHTTP ApiContext PUB e m
scope
toOutStream ::
( Monad m,
Eq ch,
Hashable ch
) =>
( GQLRequest ->
ResponseStream (Event ch con) m (Value VALID)
) ->
Input api ->
Output api (Event ch con) m
toOutStream :: (GQLRequest -> ResponseStream (Event ch con) m (Value VALID))
-> Input api -> Output api (Event ch con) m
toOutStream GQLRequest -> ResponseStream (Event ch con) m (Value VALID)
app (InitConnection UUID
clientId) =
(ApiContext SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m]))
-> Output SUB (Event ch con) m
forall e (m :: * -> *).
(ApiContext SUB e m -> m (Either ByteString [Updates e m]))
-> Output SUB e m
SubOutput ApiContext SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m])
handle
where
handle :: ApiContext SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m])
handle ws :: ApiContext SUB (Event ch con) m
ws@SubContext {m ByteString
listener :: m ByteString
listener :: forall event (m :: * -> *). ApiContext SUB event m -> m ByteString
listener, ByteString -> m ()
callback :: ByteString -> m ()
callback :: forall event (m :: * -> *).
ApiContext SUB event m -> ByteString -> m ()
callback} = do
let runS :: Output SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m])
runS (SubOutput ApiContext SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m])
x) = ApiContext SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m])
x ApiContext SUB (Event ch con) m
ws
Either ByteString [Updates (Event ch con) m]
bla <- m ByteString
listener m ByteString
-> (ByteString -> m (Either ByteString [Updates (Event ch con) m]))
-> m (Either ByteString [Updates (Event ch con) m])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Output SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m])
runS (Output SUB (Event ch con) m
-> m (Either ByteString [Updates (Event ch con) m]))
-> (ByteString -> Output SUB (Event ch con) m)
-> ByteString
-> m (Either ByteString [Updates (Event ch con) m])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GQLRequest -> ResponseStream (Event ch con) m (Value VALID))
-> UUID -> ByteString -> Output SUB (Event ch con) m
forall (m :: * -> *) ch con.
(Monad m, Functor m, Eq ch, Hashable ch) =>
(GQLRequest -> ResponseStream (Event ch con) m (Value VALID))
-> UUID -> ByteString -> Output SUB (Event ch con) m
handleWSRequest GQLRequest -> ResponseStream (Event ch con) m (Value VALID)
app UUID
clientId
Either ByteString [Updates (Event ch con) m]
-> m (Either ByteString [Updates (Event ch con) m])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ByteString [Updates (Event ch con) m]
-> m (Either ByteString [Updates (Event ch con) m]))
-> Either ByteString [Updates (Event ch con) m]
-> m (Either ByteString [Updates (Event ch con) m])
forall a b. (a -> b) -> a -> b
$ ((ClientConnectionStore (Event ch con) m
-> ClientConnectionStore (Event ch con) m)
-> Updates (Event ch con) m
forall e (m :: * -> *).
(ClientConnectionStore e m -> ClientConnectionStore e m)
-> Updates e m
Updates (UUID
-> (ByteString -> m ())
-> ClientConnectionStore (Event ch con) m
-> ClientConnectionStore (Event ch con) m
forall (m :: * -> *) e.
UUID -> (ByteString -> m ()) -> StoreMap e m
insertConnection UUID
clientId ByteString -> m ()
callback) Updates (Event ch con) m
-> [Updates (Event ch con) m] -> [Updates (Event ch con) m]
forall a. a -> [a] -> [a]
:) ([Updates (Event ch con) m] -> [Updates (Event ch con) m])
-> Either ByteString [Updates (Event ch con) m]
-> Either ByteString [Updates (Event ch con) m]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Either ByteString [Updates (Event ch con) m]
bla
toOutStream GQLRequest -> ResponseStream (Event ch con) m (Value VALID)
app (Request GQLRequest
req) =
(ApiContext PUB (Event ch con) m -> m GQLResponse)
-> Output PUB (Event ch con) m
forall e (m :: * -> *).
(ApiContext PUB e m -> m GQLResponse) -> Output PUB e m
PubOutput ((ApiContext PUB (Event ch con) m -> m GQLResponse)
-> Output PUB (Event ch con) m)
-> (ApiContext PUB (Event ch con) m -> m GQLResponse)
-> Output PUB (Event ch con) m
forall a b. (a -> b) -> a -> b
$ ResponseStream (Event ch con) m (Value VALID)
-> ApiContext PUB (Event ch con) m -> m GQLResponse
forall (m :: * -> *) e.
Monad m =>
ResponseStream e m (Value VALID)
-> ApiContext PUB e m -> m GQLResponse
handleResponseHTTP (GQLRequest -> ResponseStream (Event ch con) m (Value VALID)
app GQLRequest
req)
handleResponseHTTP ::
( Monad m
) =>
ResponseStream e m (Value VALID) ->
ApiContext PUB e m ->
m GQLResponse
handleResponseHTTP :: ResponseStream e m (Value VALID)
-> ApiContext PUB e m -> m GQLResponse
handleResponseHTTP
ResponseStream e m (Value VALID)
res
PubContext {e -> m ()
eventPublisher :: e -> m ()
eventPublisher :: forall event (m :: * -> *). ApiContext PUB event m -> event -> m ()
eventPublisher} = ResultT e m (Value VALID) -> m (Result e (Value VALID))
forall event (m :: * -> *) a.
ResultT event m a -> m (Result event a)
runResultT (ResponseStream e m (Value VALID)
-> (ResponseEvent e m -> ResultT e m e)
-> ResultT e m (Value VALID)
forall (m :: * -> *) e a e'.
Monad m =>
ResponseStream e m a
-> (ResponseEvent e m -> ResultT e' m e') -> ResultT e' m a
handleRes ResponseStream e m (Value VALID)
res ResponseEvent e m -> ResultT e m e
forall (f :: * -> *) a (m :: * -> *).
Failure GQLErrors f =>
ResponseEvent a m -> f a
execute) m (Result e (Value VALID))
-> (Result e (Value VALID) -> m GQLResponse) -> m GQLResponse
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Result e (Value VALID) -> m GQLResponse
runResult
where
runResult :: Result e (Value VALID) -> m GQLResponse
runResult Success {Value VALID
result :: forall events a. Result events a -> a
result :: Value VALID
result, [e]
events :: [e]
events :: forall events a. Result events a -> [events]
events} = (e -> m ()) -> [e] -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ e -> m ()
eventPublisher [e]
events m () -> GQLResponse -> m GQLResponse
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value VALID -> GQLResponse
Data Value VALID
result
runResult Failure {GQLErrors
errors :: GQLErrors
errors :: forall events a. Result events a -> GQLErrors
errors} = GQLResponse -> m GQLResponse
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GQLResponse -> m GQLResponse) -> GQLResponse -> m GQLResponse
forall a b. (a -> b) -> a -> b
$ GQLErrors -> GQLResponse
Errors GQLErrors
errors
execute :: ResponseEvent a m -> f a
execute (Publish a
event) = a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
event
execute Subscribe {} = GQLErrors -> f a
forall error (f :: * -> *) v. Failure error f => error -> f v
failure (Message -> GQLErrors
globalErrorMessage Message
"http server can't handle subscription")
handleRes ::
(Monad m) =>
ResponseStream e m a ->
(ResponseEvent e m -> ResultT e' m e') ->
ResultT e' m a
handleRes :: ResponseStream e m a
-> (ResponseEvent e m -> ResultT e' m e') -> ResultT e' m a
handleRes ResponseStream e m a
res ResponseEvent e m -> ResultT e' m e'
execute = m (Result e' a) -> ResultT e' m a
forall event (m :: * -> *) a.
m (Result event a) -> ResultT event m a
ResultT (m (Result e' a) -> ResultT e' m a)
-> m (Result e' a) -> ResultT e' m a
forall a b. (a -> b) -> a -> b
$ ResponseStream e m a -> m (Result (ResponseEvent e m) a)
forall event (m :: * -> *) a.
ResultT event m a -> m (Result event a)
runResultT ResponseStream e m a
res m (Result (ResponseEvent e m) a)
-> (Result (ResponseEvent e m) a -> m (Result e' a))
-> m (Result e' a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ResultT e' m a -> m (Result e' a)
forall event (m :: * -> *) a.
ResultT event m a -> m (Result event a)
runResultT (ResultT e' m a -> m (Result e' a))
-> (Result (ResponseEvent e m) a -> ResultT e' m a)
-> Result (ResponseEvent e m) a
-> m (Result e' a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ResponseEvent e m -> ResultT e' m e')
-> Result (ResponseEvent e m) a -> ResultT e' m a
forall (m :: * -> *) e e' a.
Monad m =>
(e -> ResultT e' m e') -> Result e a -> ResultT e' m a
unfoldRes ResponseEvent e m -> ResultT e' m e'
execute
unfoldRes ::
(Monad m) =>
(e -> ResultT e' m e') ->
Result e a ->
ResultT e' m a
unfoldRes :: (e -> ResultT e' m e') -> Result e a -> ResultT e' m a
unfoldRes e -> ResultT e' m e'
execute Success {a
result :: a
result :: forall events a. Result events a -> a
result, GQLErrors
warnings :: forall events a. Result events a -> GQLErrors
warnings :: GQLErrors
warnings, [e]
events :: [e]
events :: forall events a. Result events a -> [events]
events} =
(e -> ResultT e' m e') -> [e] -> ResultT e' m [e']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse e -> ResultT e' m e'
execute [e]
events
ResultT e' m [e'] -> ([e'] -> ResultT e' m a) -> ResultT e' m a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ( m (Result e' a) -> ResultT e' m a
forall event (m :: * -> *) a.
m (Result event a) -> ResultT event m a
ResultT (m (Result e' a) -> ResultT e' m a)
-> ([e'] -> m (Result e' a)) -> [e'] -> ResultT e' m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Result e' a -> m (Result e' a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(Result e' a -> m (Result e' a))
-> ([e'] -> Result e' a) -> [e'] -> m (Result e' a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> GQLErrors -> [e'] -> Result e' a
forall events a. a -> GQLErrors -> [events] -> Result events a
Success
a
result
GQLErrors
warnings
)
unfoldRes e -> ResultT e' m e'
_ Failure {GQLErrors
errors :: GQLErrors
errors :: forall events a. Result events a -> GQLErrors
errors} = m (Result e' a) -> ResultT e' m a
forall event (m :: * -> *) a.
m (Result event a) -> ResultT event m a
ResultT (m (Result e' a) -> ResultT e' m a)
-> m (Result e' a) -> ResultT e' m a
forall a b. (a -> b) -> a -> b
$ Result e' a -> m (Result e' a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Result e' a -> m (Result e' a)) -> Result e' a -> m (Result e' a)
forall a b. (a -> b) -> a -> b
$ Failure :: forall events a. GQLErrors -> Result events a
Failure {GQLErrors
errors :: GQLErrors
errors :: GQLErrors
errors}