Skip to content
Permalink
Browse files

feat(codegen): codegen without db connection (#247)

  • Loading branch information...
goldcaddy77 committed Nov 17, 2019
1 parent 83ee9bb commit 45eacec9bf2c216f20f1cd41150479d4ea7862ad
Showing with 10,716 additions and 13,762 deletions.
  1. +1 −1 .circleci/config.yml
  2. +2 −0 .eslintrc.js
  3. +7 −7 .markdownlint.json
  4. +1 −0 .yarnrc
  5. +24 −12 README.md
  6. +64 −1 examples/01-simple-model/generated/classes.ts
  7. +4 −28 examples/01-simple-model/package.json
  8. +261 −3,847 examples/01-simple-model/yarn.lock
  9. +27 −5 examples/02-complex-example/generated/binding.ts
  10. +123 −12 examples/02-complex-example/generated/classes.ts
  11. +26 −4 examples/02-complex-example/generated/schema.graphql
  12. +7 −9 examples/02-complex-example/package.json
  13. +16 −3 examples/02-complex-example/src/modules/user/user.model.ts
  14. +986 −1,127 examples/02-complex-example/yarn.lock
  15. +130 −4 examples/03-one-to-many-relationship/generated/classes.ts
  16. +8 −9 examples/03-one-to-many-relationship/package.json
  17. +985 −1,126 examples/03-one-to-many-relationship/yarn.lock
  18. +324 −9 examples/04-many-to-many-relationship/generated/classes.ts
  19. +8 −9 examples/04-many-to-many-relationship/package.json
  20. +985 −1,126 examples/04-many-to-many-relationship/yarn.lock
  21. +64 −1 examples/05-migrations/generated/classes.ts
  22. +9 −10 examples/05-migrations/package.json
  23. +1,054 −1,334 examples/05-migrations/yarn.lock
  24. +64 −1 examples/06-base-service/generated/classes.ts
  25. +7 −9 examples/06-base-service/package.json
  26. +986 −1,127 examples/06-base-service/yarn.lock
  27. +544 −40 examples/07-feature-flags/generated/classes.ts
  28. +4 −14 examples/07-feature-flags/package.json
  29. +1 −2 examples/07-feature-flags/src/feature-flag-user/feature-flag-user.service.ts
  30. +972 −1,171 examples/07-feature-flags/yarn.lock
  31. +130 −4 examples/08-performance/generated/classes.ts
  32. +8 −9 examples/08-performance/package.json
  33. +985 −1,126 examples/08-performance/yarn.lock
  34. +130 −4 examples/09-production/generated/classes.ts
  35. +8 −9 examples/09-production/package.json
  36. +985 −1,126 examples/09-production/yarn.lock
  37. +5 −1 package.json
  38. +17 −7 src/cli/commands/codegen.ts
  39. +2 −3 src/core/BaseService.ts
  40. +19 −20 src/core/code-generator.ts
  41. +4 −2 src/core/config.ts
  42. +3 −1 src/core/logger.ts
  43. +1 −1 src/core/server.test.ts
  44. +1 −3 src/core/server.ts
  45. +2 −0 src/core/types.ts
  46. +13 −7 src/decorators/BooleanField.ts
  47. +16 −7 src/decorators/DateField.ts
  48. +10 −4 src/decorators/EmailField.ts
  49. +14 −5 src/decorators/EnumField.ts
  50. +14 −4 src/decorators/FloatField.ts
  51. +39 −0 src/decorators/IdField.ts
  52. +14 −4 src/decorators/IntField.ts
  53. +22 −0 src/decorators/InterfaceType.ts
  54. +10 −5 src/decorators/JSONField.ts
  55. +2 −2 src/decorators/ManyToOne.ts
  56. +32 −6 src/decorators/StringField.ts
  57. +2 −0 src/decorators/index.ts
  58. +1 −1 src/metadata/index.ts
  59. +190 −19 src/metadata/metadata-storage.ts
  60. +16 −11 src/schema/SchemaGenerator.ts
  61. +174 −210 src/schema/TypeORMConverter.ts
  62. +0 −35 src/test/functional/cli.test.ts
  63. +4 −1 src/test/functional/server.test.ts
  64. +4 −1 src/test/modules/kitchen-sink/kitchen-sink.model.ts
  65. +1 −0 src/tgql/index.ts
  66. +22 −0 src/tgql/loadGlobs.ts
  67. +4 −4 src/utils/decoratorComposer.ts
  68. +6 −3 tools/bootstrap-all.sh
  69. +2 −1 tsconfig.eslint.json
  70. +110 −68 yarn.lock
@@ -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
@@ -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
},
@@ -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": ".,;:"
}
}
@@ -0,0 +1 @@
registry "https://registry.npmjs.org"
@@ -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 {
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
@@ -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 {
@@ -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;

@@ -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",
@@ -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 45eacec

Please sign in to comment.
You can’t perform that action at this time.