Skip to content

Commit

Permalink
fix(model-api): update to model API
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 committed Jan 8, 2019
1 parent 7f05a5b commit 696bc9b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ to see how to use Warthog in a project or check out the
Create an entity:

```typescript
import { BaseObject, EntityObject, StringField } from 'warthog';
import { BaseModel, Model, StringField } from 'warthog';

@EntityObject()
export class User extends BaseObject {
@Model()
export class User extends BaseModel {
@StringField()
name?: string;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/1-simple-seed/src/modules/user/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Authorized } from 'type-graphql';

import { BaseObject, EmailField, EntityObject, StringField } from '../../../../../src';
import { BaseModel, EmailField, Model, StringField } from '../../../../../src';

@EntityObject()
export class User extends BaseObject {
@Model()
export class User extends BaseModel {
@StringField({ maxLength: 30 })
firstName?: string;

Expand Down
2 changes: 1 addition & 1 deletion src/core/BaseObject.ts → src/core/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export abstract class BaseGraphQLObject {

// This class adds all of the TypeORM decorators needed to create the DB table
@ObjectType({ implements: BaseGraphQLObject })
export abstract class BaseObject implements BaseGraphQLObject {
export abstract class BaseModel implements BaseGraphQLObject {
@PrimaryColumn({ type: String })
id!: ID;

Expand Down
4 changes: 0 additions & 4 deletions src/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export class App {
}

async buildGraphQLSchema(): Promise<GraphQLSchema> {
console.log('buildGraphQLSchema start ');
if (!this.schema) {
this.schema = await buildSchema({
authChecker,
Expand All @@ -94,13 +93,10 @@ export class App {
});
}

console.log('this.schema', this.schema);

return this.schema;
}

async writeSchemaFile() {
console.log('got to writeSchemaFile', this.schema);
// Write schema to dist folder so that it's available in package
return writeFileSync(path.join(this.generatedFolder, 'schema.graphql'), printSchema(this.schema as GraphQLSchema), {
encoding: 'utf8',
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './app';
export * from './BaseObject';
export * from './BaseModel';
export * from './binding';
export { Context } from './Context';
export * from './types';
4 changes: 2 additions & 2 deletions src/decorators/EntityObject.ts → src/decorators/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Entity } from 'typeorm';

import { composeClassDecorators, ClassDecoratorFactory } from '../utils/';

interface EntityObjectOptions {
interface ModelOptions {
auditTableName?: string;
}

export function EntityObject(this: any, args: EntityObjectOptions = {}): any {
export function Model(this: any, args: ModelOptions = {}): any {
const factories = [Entity() as ClassDecoratorFactory, ObjectType() as ClassDecoratorFactory];

return composeClassDecorators(...factories);
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './EmailField';
export * from './EntityObject';
export * from './Model';
export * from './StringField';
export * from './ForeignKeyField';
4 changes: 2 additions & 2 deletions src/tgql/BaseResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
Repository
} from 'typeorm';

import { BaseObject, WhereInput } from '../core';
import { BaseModel, WhereInput } from '../core';
import { StandardDeleteResponse } from './DeleteResponse';

export class BaseResolver<E extends BaseObject> {
export class BaseResolver<E extends BaseModel> {
// TODO: need to figure out why we couldn't type this as Repository<E>
constructor(protected entityClass: any, protected repository: Repository<any>) {
if (!entityClass) {
Expand Down
2 changes: 1 addition & 1 deletion src/tgql/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { authChecker } from './authChecker';
export { BaseObject } from '../core/BaseObject';
export { BaseModel } from '../core/BaseModel';
export * from './BaseResolver';
export * from './BaseWhereInput';
export * from './DeleteResponse';
Expand Down

0 comments on commit 696bc9b

Please sign in to comment.