Last active
April 5, 2020 02:14
-
-
Save AugustoCalaca/d454292c3d7fe3ce5c09c346c7a15819 to your computer and use it in GitHub Desktop.
register dataloaders, get dataloaders and so on
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type GetLoader = () => DataLoader<string, any>; | |
| type Dataloaders = { | |
| [loader: string]: GetLoader; | |
| }; | |
| const dataloaders: Dataloaders = {}; | |
| export const registerDataLoader = (name: string, getLoader: GetLoader) => { | |
| dataloaders[name] = getLoader; | |
| }; | |
| export const getDataloaders = (): GraphQLDataLoaders => Object.keys(dataloaders).reduce( | |
| (acc, loaderKey) => ({ | |
| ...acc, | |
| [loaderKey]: dataloaders[loaderKey](), | |
| }), | |
| {}, | |
| ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment