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
- dataFetchWithInsert :: forall u w r a. (DataSource u r, Eq (r a), Hashable (r a), Typeable (r a)) => (r a -> String) -> (r a -> DataCacheItem u w a -> DataCache (DataCacheItem u w) -> IO ()) -> r a -> GenHaxl u w a
- uncachedRequest :: forall a u w (r :: Type -> Type). (DataSource u r, Request r a) => r a -> GenHaxl u w a
- cacheResult :: Request r a => r a -> IO a -> GenHaxl u w a
- dupableCacheRequest :: Request req a => req a -> Either SomeException a -> GenHaxl u w ()
- 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. Env u w -> [BlockedFetches u] -> IO ()
- performRequestStore :: forall u w. Env u w -> RequestStore u -> 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.
dataFetchWithInsert :: forall u w r a. (DataSource u r, Eq (r a), Hashable (r a), Typeable (r a)) => (r a -> String) -> (r a -> DataCacheItem u w a -> DataCache (DataCacheItem u w) -> IO ()) -> r a -> GenHaxl u w a Source #
Performs actual fetching of data for a Request
from a DataSource
, using
the given function to insert requests in the cache.
uncachedRequest :: forall a u w (r :: Type -> Type). (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.
dupableCacheRequest :: Request req a => req a -> Either SomeException a -> GenHaxl u w () Source #
Similar to cacheRequest
but doesn't throw an exception if the key
already exists in the cache.
If this function is called twice to cache the same Haxl request, the first
value will be discarded and overwritten with the second value.
Useful e.g. for unit tests
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. Env u w -> [BlockedFetches u] -> 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. Env u w -> RequestStore u -> IO () Source #