2024-01-16 09:36:35 +00:00
|
|
|
import 'reflect-metadata';
|
|
|
|
import debug from 'debug';
|
2024-01-17 04:32:06 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
2024-01-30 14:20:53 +00:00
|
|
|
import { OAuthApp } from '@octokit/oauth-app';
|
|
|
|
|
2024-01-17 05:23:01 +00:00
|
|
|
import { Database } from './database';
|
2024-01-16 09:36:35 +00:00
|
|
|
import { createAndStartServer } from './server';
|
2024-01-17 04:32:06 +00:00
|
|
|
import { createResolvers } from './resolvers';
|
2024-01-16 09:36:35 +00:00
|
|
|
import { getConfig } from './utils';
|
2024-01-17 05:23:01 +00:00
|
|
|
import { Config } from './config';
|
2024-01-19 09:52:25 +00:00
|
|
|
import { DEFAULT_CONFIG_FILE_PATH } from './constants';
|
2024-02-02 09:32:12 +00:00
|
|
|
import { Service } from './service';
|
2024-01-16 09:36:35 +00:00
|
|
|
|
|
|
|
const log = debug('snowball:server');
|
|
|
|
|
|
|
|
export const main = async (): Promise<void> => {
|
|
|
|
// TODO: get config path using cli
|
2024-01-30 14:20:53 +00:00
|
|
|
const { server, database, githubOauth } = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
|
2024-01-17 05:23:01 +00:00
|
|
|
|
2024-01-30 14:20:53 +00:00
|
|
|
// TODO: Move to Service class
|
|
|
|
const app = new OAuthApp({
|
|
|
|
clientType: 'oauth-app',
|
|
|
|
clientId: githubOauth.clientId,
|
|
|
|
clientSecret: githubOauth.clientSecret
|
|
|
|
});
|
|
|
|
|
2024-02-08 09:29:19 +00:00
|
|
|
const db = new Database(database);
|
|
|
|
await db.init();
|
|
|
|
const service = new Service(db, app);
|
|
|
|
|
2024-01-17 04:32:06 +00:00
|
|
|
const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString();
|
2024-02-08 09:29:19 +00:00
|
|
|
const resolvers = await createResolvers(service);
|
2024-01-17 05:23:01 +00:00
|
|
|
|
|
|
|
await createAndStartServer(typeDefs, resolvers, server);
|
2024-01-16 09:36:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
log('Starting server...');
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|