mickhansen / dataloader-sequelize

Batching and simplification of Sequelize with facebook/dataloader
MIT License
284 stars 58 forks source link

possible to get dataloader native methods #104

Closed ssdk86 closed 4 years ago

ssdk86 commented 4 years ago

Hello! It is possible to get native dataloader methods like .clear() or .clearAll() that can manipulate dataloader-sequelize cached instances? for example

import {createContext, EXPECTED_OPTIONS_KEY} from 'dataloader-sequelize';
const context = createContext(sequelize);

const results = await User.findAll({where: {/* super complicated */}});
context.prime(results);
let user = await User.findById(2, {[EXPECTED_OPTIONS_KEY]: context});
console.log(!!user); // true

context__prototype__.clearAll(); // get dataloader  .clearAll()
user = await User.findById(2, {[EXPECTED_OPTIONS_KEY]: context});
console.log(!!user); // false
mickhansen commented 4 years ago

Not at this time, we create more than one internal dataloader. It would be possible to expose a clearAll method that calls all internal dataloaders and clear them. We could likely also have a prime counterpart that works with the same logic but does a clear instead.

mickhansen commented 4 years ago

111 addresses clearing the cache

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.