Skip to content

Commit

Permalink
feat(codegen): codegen without db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 committed Nov 17, 2019
1 parent 83ee9bb commit 8c642e3
Show file tree
Hide file tree
Showing 70 changed files with 10,716 additions and 13,762 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -27,7 +27,7 @@ jobs:
flags: backend
- run:
name: deploy
command: yarn run semantic-release || true
command: DEBUG=condition* yarn run semantic-release --debug || true
- save_cache:
key: *yarn_cache_key
paths: ~/circleci/node_modules
2 changes: 2 additions & 0 deletions .eslintrc.js
Expand Up @@ -12,6 +12,8 @@ module.exports = {
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
// This is the same as tsconfig.json, but it also includes the examples. We don't want to inclue the
// examples in the actual bundled asset
project: './tsconfig.eslint.json',
sourceType: 'module' // Allows for the use of imports
},
Expand Down
14 changes: 7 additions & 7 deletions .markdownlint.json
@@ -1,12 +1,12 @@
{
"MD009": {
"br_spaces": 2
"first-line-h1": {
"level": 2
},
"MD013": false,
"MD026": {
"punctuation": ".,;:"
"line-length": false,
"no-inline-html": {
"allowed_elements": ["a", "img", "p"]
},
"MD029": {
"style": "ordered"
"no-trailing-punctuation": {
"punctuation": ".,;:"
}
}
1 change: 1 addition & 0 deletions .yarnrc
@@ -0,0 +1 @@
registry "https://registry.npmjs.org"
36 changes: 24 additions & 12 deletions README.md
Expand Up @@ -76,7 +76,7 @@ yarn add warthog
The model will auto-generate your database table and graphql types. Warthog will find all models that match the following glob - `'/**/*.model.ts'`. So for this file, you would name it `user.model.ts`

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

@Model()
export class User extends BaseModel {
Expand All @@ -90,20 +90,25 @@ export class User extends BaseModel {
The resolver auto-generates queries and mutations in your GraphQL schema. Warthog will find all resolvers that match the following glob - `'/**/*.resolver.ts'`. So for this file, you would name it `user.resolver.ts`

```typescript
import { User } from './user.model';
import { UserService } from './user.service';
import { User } from "./user.model";
import { UserService } from "./user.service";

@Resolver(User)
export class UserResolver {
constructor(@Inject('UserService') readonly service: UserService) {}
constructor(@Inject("UserService") readonly service: UserService) {}

@Query(() => [User])
async users(@Args() { where, orderBy, limit, offset }: UserWhereArgs): Promise<User[]> {
async users(
@Args() { where, orderBy, limit, offset }: UserWhereArgs
): Promise<User[]> {
return this.service.find<UserWhereInput>(where, orderBy, limit, offset);
}

@Mutation(() => User)
async createUser(@Arg('data') data: UserCreateInput, @Ctx() ctx: BaseContext): Promise<User> {
async createUser(
@Arg("data") data: UserCreateInput,
@Ctx() ctx: BaseContext
): Promise<User> {
return this.service.create(data, ctx.user.id);
}
}
Expand All @@ -112,11 +117,13 @@ export class UserResolver {
### 3. Create a Service

```typescript
import { User } from './user.model';
import { User } from "./user.model";

@Service('UserService')
@Service("UserService")
export class UserService extends BaseService<User> {
constructor(@InjectRepository(User) protected readonly repository: Repository<User>) {
constructor(
@InjectRepository(User) protected readonly repository: Repository<User>
) {
super(User, repository);
}
}
Expand All @@ -135,8 +142,8 @@ WARTHOG_DB_PASSWORD=
### 5. Run your server

```typescript
import 'reflect-metadata';
import { Server } from 'warthog';
import "reflect-metadata";
import { Server } from "warthog";

async function bootstrap() {
const server = new Server();
Expand Down Expand Up @@ -166,7 +173,12 @@ type Mutation {
}

type Query {
users(offset: Int, limit: Int = 50, where: UserWhereInput, orderBy: UserOrderByInput): [User!]!
users(
offset: Int
limit: Int = 50
where: UserWhereInput
orderBy: UserOrderByInput
): [User!]!
}

input UserCreateInput {
Expand Down
65 changes: 64 additions & 1 deletion examples/01-simple-model/generated/classes.ts
Expand Up @@ -58,7 +58,70 @@ registerEnumType(UserOrderByEnum, {
});

@TypeGraphQLInputType()
export class UserWhereInput extends BaseWhereInput {
export class UserWhereInput {
@TypeGraphQLField(() => String, { nullable: true })
id_eq?: string;

@TypeGraphQLField(() => [String], { nullable: true })
id_in?: string[];

@TypeGraphQLField({ nullable: true })
createdAt_eq?: String;

@TypeGraphQLField({ nullable: true })
createdAt_lt?: String;

@TypeGraphQLField({ nullable: true })
createdAt_lte?: String;

@TypeGraphQLField({ nullable: true })
createdAt_gt?: String;

@TypeGraphQLField({ nullable: true })
createdAt_gte?: String;

@TypeGraphQLField(() => String, { nullable: true })
createdById_eq?: string;

@TypeGraphQLField({ nullable: true })
updatedAt_eq?: String;

@TypeGraphQLField({ nullable: true })
updatedAt_lt?: String;

@TypeGraphQLField({ nullable: true })
updatedAt_lte?: String;

@TypeGraphQLField({ nullable: true })
updatedAt_gt?: String;

@TypeGraphQLField({ nullable: true })
updatedAt_gte?: String;

@TypeGraphQLField(() => String, { nullable: true })
updatedById_eq?: string;

@TypeGraphQLField({ nullable: true })
deletedAt_all?: Boolean;

@TypeGraphQLField({ nullable: true })
deletedAt_eq?: String;

@TypeGraphQLField({ nullable: true })
deletedAt_lt?: String;

@TypeGraphQLField({ nullable: true })
deletedAt_lte?: String;

@TypeGraphQLField({ nullable: true })
deletedAt_gt?: String;

@TypeGraphQLField({ nullable: true })
deletedAt_gte?: String;

@TypeGraphQLField(() => String, { nullable: true })
deletedById_eq?: string;

@TypeGraphQLField({ nullable: true })
firstName_eq?: string;

Expand Down
32 changes: 4 additions & 28 deletions examples/01-simple-model/package.json
@@ -1,6 +1,7 @@
{
"name": "example1",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"bootstrap": "cd ../.. && yarn && yarn link && cd - && yarn && yarn db:drop:tempbd && yarn codegen && yarn db:create",
"codegen": "yarn warthog codegen",
Expand All @@ -15,37 +16,12 @@
"//": "Allows us to use the local warthog CLI in commands above",
"warthog": "../../bin/warthog"
},
"dependencies": {
"handlebars": "^4.0.14",
"lodash": "^4.17.13",
"reflect-metadata": "^0.1.12",
"typescript": "^3.2.2"
},
"dependencies": {},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/faker": "^4.1.4",
"@types/isomorphic-fetch": "^0.0.34",
"@types/jest": "^23.3.11",
"@types/node": "^10.12.18",
"faker": "^4.1.0",
"jest": "^23.6.0",
"npm-run-all": "^4.1.5",
"@types/node": "^10.17.5",
"ts-jest": "^23.10.5",
"ts-node": "^7.0.1",
"ts-node-dev": "^1.0.0-pre.32"
},
"jest": {
"transform": {
".ts": "ts-jest"
},
"testRegex": "\\.test\\.ts$",
"moduleFileExtensions": [
"ts",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"\\.test\\.ts$"
]
"ts-node-dev": "^1.0.0-pre.44"
}
}

0 comments on commit 8c642e3

Please sign in to comment.