We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 200b522 commit 923a75fCopy full SHA for 923a75f
README.md
@@ -487,6 +487,21 @@ const usernameLoader = new DataLoader(async names => {
487
})
488
```
489
490
+### Freezing results to enforce immutability
491
+
492
+Since DataLoader caches values, it's typically assumed these values will be
493
+treated as if they were immutable. While DataLoader itself doesn't enforce
494
+this, you can create a higher-order function to enforce immutability
495
+with Object.freeze():
496
497
+```js
498
+function freezeResults(batchLoader) {
499
+ return keys => batchLoader(keys).then(values => values.map(Object.freeze))
500
+}
501
502
+const myLoader = new DataLoader(freezeResults(myBatchLoader))
503
+```
504
505
506
## Common Back-ends
507
0 commit comments