Skip to content

Commit 54a6f42

Browse files
committed
feat: add dataLoaderConfigurationMap
1 parent 82d5226 commit 54a6f42

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ const updateUserPassword = (user: UserRecordType, newPassword: string) => {
223223

224224
```
225225

226+
You can optionally pass a second parameter to `createLoaders` – loader configuration map, e.g.
227+
228+
```js
229+
const loaders = createLoaders(connection, {
230+
UserByIdLoader: {
231+
cache: false
232+
}
233+
});
234+
235+
```
236+
226237
### Handling non-nullable columns in materialized views
227238

228239
Unfortunately, PostgreSQL does not describe materilized view columns as non-nullable even when you add a constraint that enforce this contract ([see this Stack Overflow question](https://stackoverflow.com/q/47242219/368691)).

src/utilities/generateDataLoaderFactory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const log = Logger.child({
2828
const createLoaderByIdsDeclaration = (loaderName: string, tableName: string, keyColumnName, columnSelector: string, resultIsArray: boolean) => {
2929
return `const ${loaderName} = new DataLoader((ids) => {
3030
return getByIds(connection, '${tableName}', ids, '${keyColumnName}', '${columnSelector}', ${String(resultIsArray)}, NotFoundError);
31-
});`;
31+
}, dataLoaderConfigurationMap.${loaderName});`;
3232
};
3333

3434
const createLoaderByIdsUsingJoiningTableDeclaration = (
@@ -41,7 +41,7 @@ const createLoaderByIdsUsingJoiningTableDeclaration = (
4141
) => {
4242
return `const ${loaderName} = new DataLoader((ids) => {
4343
return getByIdsUsingJoiningTable(connection, '${joiningTableName}', '${targetResourceTableName}', '${joiningKeyName}', '${lookupKeyName}', '${columnSelector}', ids);
44-
});`;
44+
}, dataLoaderConfigurationMap.${loaderName});`;
4545
};
4646

4747
// eslint-disable-next-line complexity
@@ -259,7 +259,7 @@ ${loaderTypes.map((body) => {
259259
}).sort().join(',\n')}
260260
|};
261261
262-
export const createLoaders = (connection: DatabaseConnectionType): LoadersType => {
262+
export const createLoaders = (connection: DatabaseConnectionType, dataLoaderConfigurationMap: Object = {}): LoadersType => {
263263
${loaders
264264
.map((body) => {
265265
return indent(body, 2);

0 commit comments

Comments
 (0)