https://github.com/deptno/dataloader-toolbox
dataloader toolbox
https://github.com/deptno/dataloader-toolbox
dataloader graphql session sorter toolbox
Last synced: 8 months ago
JSON representation
dataloader toolbox
- Host: GitHub
- URL: https://github.com/deptno/dataloader-toolbox
- Owner: deptno
- Created: 2020-08-07T18:15:10.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T18:59:14.000Z (about 5 years ago)
- Last Synced: 2025-02-02T06:45:31.951Z (8 months ago)
- Topics: dataloader, graphql, session, sorter, toolbox
- Language: TypeScript
- Homepage:
- Size: 62.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dataloader-toolbox
## install
```shell script
npm install dataloader-toolbox
```## api
### createDataLoaderSession
create a session and add to context when you create new context(per request).
session function returns dataloader function from normal function.#### code
```ts
const session = createDataLoaderSession()
// add it to context
const getData = (keys: string[]) => {
// find data keys: ['key1', 'key2', 'key3']return [...data]
}async function resolver(parent, args, context) {
context.session(getData).load('key1')
context.session(getData).load('key2')
context.session(getData).load('key3')
}
```### dataLoaderSorter
`dataloader` does not support sorting, you need to sorter.
#### code
```ts
const resolver = (keys: string[]) => {
type Item = {
id: string
}const sql = `
select *
from table
where id in (${keys})`
// query returns Promise
return query(sql).then(dataLoaderSorter(keys, 'id'))
}
```## license
MIT