-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventsFactory.ts
More file actions
32 lines (25 loc) · 980 Bytes
/
eventsFactory.ts
File metadata and controls
32 lines (25 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { ResolverContextBase } from '../../types/graphql';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const EventsFactory = require('../../models/eventsFactory');
/**
* Returns a per-request, per-project EventsFactory instance
* Uses context.eventsFactoryCache to memoize by projectId
*
* @param {ResolverContextBase} context - resolver context
* @param {string} projectId - project id to get EventsFactory instance for
* @returns {EventsFactory} - EventsFactory instance bound to a specific project object
*/
export function getEventsFactory(context: ResolverContextBase, projectId: string) {
if (!context.eventsFactoryCache) {
context.eventsFactoryCache = new Map();
}
const cache = context.eventsFactoryCache;
if (cache) {
if (!cache.has(projectId)) {
cache.set(projectId, new EventsFactory(projectId));
}
return cache.get(projectId);
}
return new EventsFactory(projectId);
}
export default getEventsFactory;