Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implementation of data-fetching operations. Most users should import Haxl.Core instead.
Synopsis
- dataFetch :: (DataSource u r, Request r a) => r a -> GenHaxl u w a
- dataFetchWithShow :: (DataSource u r, Eq (r a), Hashable (r a), Typeable (r a)) => ShowReq r a -> r a -> GenHaxl u w a
- uncachedRequest :: forall a u w (r :: * -> *). (DataSource u r, Request r a) => r a -> GenHaxl u w a
- cacheResult :: Request r a => r a -> IO a -> GenHaxl u w a
- cacheResultWithShow :: (Eq (r a), Hashable (r a), Typeable (r a)) => ShowReq r a -> r a -> IO a -> GenHaxl u w a
- cacheRequest :: Request req a => req a -> Either SomeException a -> GenHaxl u w ()
- performFetches :: forall u w. Int -> Env u w -> [BlockedFetches u] -> IO (Int, [IO ()])
- performRequestStore :: forall u w. Int -> Env u w -> RequestStore u -> IO (Int, [IO ()])
- type ShowReq r a = (r a -> String, a -> String)
Documentation
dataFetch :: (DataSource u r, Request r a) => r a -> GenHaxl u w a Source #
Performs actual fetching of data for a Request
from a DataSource
.
dataFetchWithShow :: (DataSource u r, Eq (r a), Hashable (r a), Typeable (r a)) => ShowReq r a -> r a -> GenHaxl u w a Source #
Performs actual fetching of data for a Request
from a DataSource
, using
the given show functions for requests and their results.
uncachedRequest :: forall a u w (r :: * -> *). (DataSource u r, Request r a) => r a -> GenHaxl u w a Source #
A data request that is not cached. This is not what you want for normal read requests, because then multiple identical requests may return different results, and this invalidates some of the properties that we expect Haxl computations to respect: that data fetches can be arbitrarily reordered, and identical requests can be commoned up, for example.
uncachedRequest
is useful for performing writes, provided those
are done in a safe way - that is, not mixed with reads that might
conflict in the same Haxl computation.
if we are recording or running a test, we fallback to using dataFetch This allows us to store the request in the cache when recording, which allows a transparent run afterwards. Without this, the test would try to call the datasource during testing and that would be an exception.
cacheResultWithShow :: (Eq (r a), Hashable (r a), Typeable (r a)) => ShowReq r a -> r a -> IO a -> GenHaxl u w a Source #
Transparently provides caching in the same way as cacheResult
, but uses
the given functions to show requests and their results.
cacheRequest :: Request req a => req a -> Either SomeException a -> GenHaxl u w () Source #
Inserts a request/result pair into the cache. Throws an exception
if the request has already been issued, either via dataFetch
or
cacheRequest
.
This can be used to pre-populate the cache when running tests, to avoid going to the actual data source and ensure that results are deterministic.
performFetches :: forall u w. Int -> Env u w -> [BlockedFetches u] -> IO (Int, [IO ()]) Source #
Issues a batch of fetches in a RequestStore
. After
performFetches
, all the requests in the RequestStore
are
complete, and all of the ResultVar
s are full.
performRequestStore :: forall u w. Int -> Env u w -> RequestStore u -> IO (Int, [IO ()]) Source #