Skip to content

Commit

Permalink
feat(app): rename app to server (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Jan 26, 2019
1 parent 533d838 commit aa279f4
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ export class UserResolver extends BaseResolver<User> {

import 'reflect-metadata';
import { Container } from 'typedi';
import { App } from 'warthog';
import { Server } from 'warthog';

async function bootstrap() {
const app = new App({ container: Container });
return app.start();
const server = new Server({ container: Container });
return server.start();
}

bootstrap()
Expand Down
6 changes: 3 additions & 3 deletions examples/1-simple-model/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Container } from 'typedi';

dotenv.config();

import { App } from '../../../src/';
import { Server } from '../../../src/';

async function bootstrap() {
const app = new App({
const server = new Server({
container: Container,
warthogImportPath: '../../../src' // Path written in generated classes
});

return app.start();
return server.start();
}

bootstrap().catch((error: Error) => {
Expand Down
10 changes: 5 additions & 5 deletions examples/2-complex-example/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import 'reflect-metadata';

import { Binding } from '../generated/binding';

import { getServer } from './app';
import { User } from './modules/user/user.model';
import { getServer } from './server';

const app = getServer({}, { logging: false });
const server = getServer({}, { logging: false });
let binding: Binding;
let testUser: User;

beforeAll(async done => {
console.error = jest.fn();

await app.start();
binding = ((await app.getBinding()) as unknown) as Binding; // TODO: clean this up
await server.start();
binding = ((await server.getBinding()) as unknown) as Binding; // TODO: clean this up

const key = new Date().getTime();

Expand All @@ -34,7 +34,7 @@ beforeAll(async done => {

afterAll(async done => {
(console.error as any).mockRestore();
await app.stop();
await server.stop();
done();
});

Expand Down
6 changes: 3 additions & 3 deletions examples/2-complex-example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'reflect-metadata';

import * as dotenv from 'dotenv';

import { getServer } from './app';
import { getServer } from './server';

dotenv.config();

async function bootstrap() {
const app = getServer();
await app.start();
const server = getServer();
await server.start();
}

bootstrap().catch((error: Error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'reflect-metadata';

import { Container } from 'typedi';

import { App, BaseContext } from '../../../src/';
import { BaseContext, Server } from '../../../src/';

// import { User } from './modules/user/user.model';

Expand All @@ -15,7 +15,7 @@ interface Context extends BaseContext {
}

export function getServer(AppOptions = {}, dbOptions = {}) {
return new App<Context>(
return new Server<Context>(
{
container: Container,
// Inject a fake user. In a real app you'd parse a JWT to add the user
Expand Down
2 changes: 1 addition & 1 deletion examples/2-complex-example/tools/generate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Debug from 'debug';

import { getServer } from '../src/app';
import { getServer } from '../src/server';

const logger = Debug('warthog:generate');

Expand Down
10 changes: 5 additions & 5 deletions examples/2-complex-example/tools/seed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Debug from 'debug';
import * as Faker from 'faker';

import { getServer } from '../src/app';
import { getServer } from '../src/server';

if (process.env.NODE_ENV !== 'development') {
throw 'Seeding only available in development environment';
Expand All @@ -12,10 +12,10 @@ const logger = Debug('warthog:seed');
const NUM_USERS = 100;

async function seedDatabase() {
const app = getServer();
await app.start();
const server = getServer();
await server.start();

const binding = await app.getBinding();
const binding = await server.getBinding();

for (let index = 0; index < NUM_USERS; index++) {
const random = new Date()
Expand Down Expand Up @@ -45,7 +45,7 @@ async function seedDatabase() {
}
}

return app.stop();
return server.stop();
}

seedDatabase()
Expand Down
8 changes: 4 additions & 4 deletions examples/3-one-to-many-relationship/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import 'reflect-metadata';
import * as dotenv from 'dotenv';
import 'reflect-metadata';
import { Container } from 'typedi';

dotenv.config();

import { App } from '../../../src/';
import { Server } from '../../../src/';

async function bootstrap() {
const app = new App({
const server = new Server({
container: Container,
warthogImportPath: '../../../src' // Path written in generated classes
});

await app.start();
await server.start();
}

bootstrap().catch((error: Error) => {
Expand Down
8 changes: 4 additions & 4 deletions examples/4-many-to-many-relationship/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import 'reflect-metadata';
import * as dotenv from 'dotenv';
import 'reflect-metadata';
import { Container } from 'typedi';

dotenv.config();

import { App } from '../../../src/';
import { Server } from '../../../src/';

async function bootstrap() {
const app = new App({
const server = new Server({
container: Container,
warthogImportPath: '../../../src' // Path written in generated classes
});

await app.start();
await server.start();
}

bootstrap().catch((error: Error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './app';
export * from './server';
export * from './BaseModel';
export * from './Context';
export * from './types';
14 changes: 9 additions & 5 deletions src/core/app.ts → src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ import { CodeGenerator } from './code-generator';
import { BaseContext } from './Context';
import { Maybe } from './types';

export interface AppOptions<T> {
authChecker?: AuthChecker<T>;
export interface ServerOptions<T> {
container: Container;

authChecker?: AuthChecker<T>;
context?: (request: Request) => object;
host?: string;
generatedFolder?: string;
middlewares?: any[]; // TODO: fix
mockDBConnection?: boolean;
openPlayground?: boolean;
port?: string | number;
resolversPath: string[];
resolversPath?: string[];
warthogImportPath?: string;
}

export class App<C extends BaseContext> {
export class Server<C extends BaseContext> {
appHost: string;
appPort: number;
authChecker: AuthChecker<C>;
Expand All @@ -52,7 +53,7 @@ export class App<C extends BaseContext> {
schema?: GraphQLSchema;

constructor(
private appOptions: AppOptions<C>,
private appOptions: ServerOptions<C>,
private dbOptions: Partial<ConnectionOptions> = {}
) {
if (!process.env.NODE_ENV) {
Expand Down Expand Up @@ -190,3 +191,6 @@ export class App<C extends BaseContext> {
return process.env.NODE_ENV === 'development';
}
}

// Backwards compatability. This was renamed.
export const App = Server;

0 comments on commit aa279f4

Please sign in to comment.