Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sikanhe/reason-dataloader
Dataloader in Reason using Future as the async primitive
https://github.com/sikanhe/reason-dataloader
dataloader graphql reasonml
Last synced: 23 days ago
JSON representation
Dataloader in Reason using Future as the async primitive
- Host: GitHub
- URL: https://github.com/sikanhe/reason-dataloader
- Owner: sikanhe
- Created: 2019-05-28T01:41:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T22:48:28.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T13:34:35.010Z (about 1 month ago)
- Topics: dataloader, graphql, reasonml
- Language: OCaml
- Homepage:
- Size: 736 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dataloader
This is an implementation of [Dataloader](https://github.com/graphql/dataloader) in Reason using [Future](https://github.com/RationalJS/future) as the async primitive.
- Original Implemetation: https://github.com/graphql/dataloader
- Future library used: https://github.com/RationalJS/futureCheckout `src/dataloader.rei` for the full API interface
# Usage
```reason
let userLoader = Dataloader.make(userIds => getUsersByIds(userIds));
userLoader.load(1)
->Future.get(user => Js.log2("found user with ID = 1", user));
```# Caching
Calling the same loader instance with the same keys will result in returning cached futures;
```reason
userLoader.load(1) // Future with key = 1
userLoader.load(1) // will not issue a dispatch and returns the same Future as previous call
```You can pre-populate the cache with `prime(key, value)`, or clear the cache with `clear(key)` and `clearAll()`.
It is recommended to create new instances of loaders per user request, so
1) we don't have a global cache that does not get garbage collected
2) Having multiple requests writing/reading from the same cache, resulting in unpredictable behaviors.