Skip to content

Commit 58ad2b4

Browse files
committed
Add tests
1 parent a585226 commit 58ad2b4

2 files changed

Lines changed: 208 additions & 127 deletions

File tree

src/service.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ module.exports = function(mixinOptions) {
2626
subscriptionEventName: "graphql.publish",
2727
});
2828

29-
/**
30-
* DataLoader options
31-
* @type {Map<string, Object.<string, any>>} Action name key; value of options object to pass to DataLoader constructor
32-
*/
33-
const dataLoaderOptions = new Map();
34-
3529
const serviceSchema = {
3630
events: {
3731
"$services.changed"() {
@@ -232,9 +226,9 @@ module.exports = function(mixinOptions) {
232226
return ctx.call(actionName, _.defaultsDeep({}, args, rootParams, staticParams));
233227
};
234228

235-
if (dataLoaderOptions.has(actionName)) {
229+
if (this.dataLoaderOptions.has(actionName)) {
236230
// use any specified options assigned to this action
237-
const options = dataLoaderOptions.get(actionName);
231+
const options = this.dataLoaderOptions.get(actionName);
238232
return new DataLoader(batchLoadFn, options);
239233
}
240234

@@ -577,10 +571,10 @@ module.exports = function(mixinOptions) {
577571
* Build a map of options to use with DataLoader
578572
*
579573
* @param {Object[]} services
580-
* @modifies {dataLoaderOptions}
574+
* @modifies {this.dataLoaderOptions}
581575
*/
582576
buildLoaderOptionMap(services) {
583-
dataLoaderOptions.clear(); // clear map before rebuilding
577+
this.dataLoaderOptions.clear(); // clear map before rebuilding
584578

585579
services.forEach(service => {
586580
Object.values(service.actions).forEach(action => {
@@ -591,7 +585,7 @@ module.exports = function(mixinOptions) {
591585
serviceName,
592586
actionName
593587
);
594-
dataLoaderOptions.set(
588+
this.dataLoaderOptions.set(
595589
fullActionName,
596590
graphqlDefinition.dataLoaderOptions
597591
);
@@ -607,6 +601,7 @@ module.exports = function(mixinOptions) {
607601
this.graphqlSchema = null;
608602
this.pubsub = null;
609603
this.shouldUpdateGraphqlSchema = true;
604+
this.dataLoaderOptions = new Map();
610605

611606
const route = _.defaultsDeep(mixinOptions.routeOptions, {
612607
aliases: {

0 commit comments

Comments
 (0)