/
index.ts
34 lines (32 loc) · 1008 Bytes
/
index.ts
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
33
34
import { GraphQLModule } from '@graphql-modules/core';
import Container from 'typedi';
import { Connection } from 'typeorm';
import { log } from '../utils/log';
import { createAccounts } from './accounts';
import { createInternal } from './internal';
import { isAuthenticated } from './internal/utils/isAuthenticated';
export const createModules = async (connection: Connection) => {
const accounts = await createAccounts(connection);
const internal = await createInternal(connection);
return new GraphQLModule({
imports: () => [internal, accounts],
context(context) {
const requestId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
const container = Container.of(requestId);
const ctx = {
requestId,
container,
};
container.set('context', ctx);
return ctx;
},
logger: {
clientError: log,
log,
error: log,
},
resolversComposition: {
'Mutation.createUser': [isAuthenticated()],
},
});
};