Sign in

    moonbitstack/moongql/loader does not have a README file

    DataLoader

    pub struct DataLoader[K, V] {
    batch_load : (Array[K]) -> Array[V]
    key : (K) -> String
    cache : Map[String, V]
    queue : Array[K]
    queued : Map[String, Bool]
    }

    A batching, caching loader over key type K and value type V. batch_load receives the distinct, un-cached keys and must return their values positionally (result i is the value for key i). key derives a stable cache/identity string for a key.

    DataLoader::clear

    fn[K, V] DataLoader::clear(self : DataLoader[K, V], k : K) -> Unit

    Drop the cached value for k, so the next load+dispatch reloads it.

    DataLoader::clear_all

    fn[K, V] DataLoader::clear_all(self : DataLoader[K, V]) -> Unit

    Drop the whole cache.

    DataLoader::dispatch

    fn[K, V] DataLoader::dispatch(self : DataLoader[K, V]) -> Unit

    Run the pending batch: call batch_load once with the queued distinct keys, store each returned value in the cache under its key, and clear the queue. A no-op when nothing is queued, so it is safe to call after every pass.

    DataLoader::get

    fn[K, V] DataLoader::get(self : DataLoader[K, V], k : K) -> V?

    The cached value for k, or None if it has not been loaded and dispatched.

    DataLoader::load

    fn[K, V] DataLoader::load(self : DataLoader[K, V], k : K) -> Unit

    Queue k for the next dispatch. A key already cached or already queued in this pass is dropped, so the batch that dispatch runs sees each distinct key exactly once — this dedupe is what collapses N+1 into one call.

    DataLoader::load_many

    fn[K, V] DataLoader::load_many(self : DataLoader[K, V], ks : Array[K]) -> Unit

    Queue several keys for the next dispatch.

    DataLoader::load_now

    fn[K, V] DataLoader::load_now(self : DataLoader[K, V], k : K) -> V?

    Load one key and dispatch immediately, returning its value. Convenience for a single lookup; batching still applies to anything already queued.

    DataLoader::new

    fn[K, V] DataLoader::new(batch_load : (Array[K]) -> Array[V], key : (K) -> String) -> DataLoader[K, V]

    Create a loader from its batch-load function and a key-identity function.

    DataLoader::prime

    fn[K, V] DataLoader::prime(self : DataLoader[K, V], k : K, v : V) -> Unit

    Seed the cache with a known value so a later load for k never hits the backend (strawberry/Facebook DataLoader's prime).

    Source Files