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-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-16 09:36:35 +00:00
|
|
|
|
|
|
|
const log = debug('snowball:server');
|
|
|
|
const configFilePath = 'environments/local.toml';
|
|
|
|
|
|
|
|
export const main = async (): Promise<void> => {
|
|
|
|
// TODO: get config path using cli
|
2024-01-17 05:23:01 +00:00
|
|
|
const { server, database } = await getConfig<Config>(configFilePath);
|
|
|
|
|
|
|
|
const db = new Database(database);
|
|
|
|
await db.init();
|
2024-01-16 09:36:35 +00:00
|
|
|
|
2024-01-17 04:32:06 +00:00
|
|
|
const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString();
|
2024-01-17 05:23:01 +00:00
|
|
|
const resolvers = await createResolvers(db);
|
|
|
|
|
|
|
|
await createAndStartServer(typeDefs, resolvers, server);
|
2024-01-16 09:36:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
log('Starting server...');
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|