Skip to content
Permalink
Browse files

fix(examples): clean up examples, some got stale (#240)

  • Loading branch information
goldcaddy77 committed Nov 16, 2019
1 parent 6d80096 commit 6412bb26537d2fcb714f44cbfb4de43339af9fab
@@ -12,7 +12,7 @@ module.exports = {
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
project: './tsconfig.json',
project: './tsconfig.eslint.json',
sourceType: 'module' // Allows for the use of imports
},
rules: {
@@ -1,25 +1,17 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",
"editor.formatOnSave": true,
"[typescript]": {
"editor.formatOnSave": true
},
// Don't auto-format ejs templates
"[html]": {
"editor.formatOnSave": false
},
"eslint.autoFixOnSave": true,
"prettier.printWidth": 100,
"prettier.singleQuote": true,
"prettier.semi": false,
"eslint.validate": [
"javascript",
{
"language": "typescript",
"autoFix": true
}
],
"prettier.eslintIntegration": true,
"search.exclude": {
"dist/": true,
"node_modules/": true
@@ -222,7 +222,6 @@ input UserWhereUniqueInput {
}
# ...
```
Notice how we've only added a single field on the model and you get pagination, filtering and tracking of who created, updated and deleted records automatically.
@@ -362,6 +361,18 @@ Running `yarn warthog generate featureFlag` would create 3 files in the `./src/f

It is recommended that you not run Warthog's TypeScript files via `ts-node` in Production as we do in development as `ts-node` has been known to cause issues in some smaller AWS instances. Instead, compile down to JS and run in `node`. For a full project example (using [dotenvi](https://github.com/b3ross/dotenvi) for config management), see [warthog-starter](https://github.com/goldcaddy77/warthog-starter)

## Contributing

PRs accepted, fire away! Or add issues if you have use cases Warthog doesn't cover.

Before contributing, make sure you have Postgres installed and running with a user named `postgres` with an empty password. If you don't have this local Postgres user, you'll need to update the `.env` files in the `examples` folders to point to a user that can run DB migrations.

Once you have this user set up, you can build a specific example by navigating to that folder and running `yarn bootstrap`.

If you want to build all examples, you can run `yarn bootstrap` from the Warthog root folder.

It's helpful to add a new feature to the Warthog and make use of it in one of the examples folders until you've determined how it's going to work. Once you have it working, you can add tests.

## Intentionally Opinionated

Warthog is intentionally opinionated to accelerate development and make use of technology-specific features:
@@ -381,10 +392,6 @@ Special thanks to:

Warthog is essentially a really opinionated composition of TypeORM and TypeGraphQL that uses similar GraphQL conventions to the Prisma project.

## Contribute

PRs accepted, fire away! Or add issues if you have use cases Warthog doesn't cover.

## License

MIT © Dan Caddigan
@@ -40,6 +40,9 @@ export const Binding = makeBindingClass<BindingConstructor<Binding>>({ schema })
* Types
*/

export type StringEnum = 'FOO' |
'BAR'

export type UserOrderByInput = 'createdAt_ASC' |
'createdAt_DESC' |
'updatedAt_ASC' |
@@ -56,6 +59,8 @@ export type UserOrderByInput = 'createdAt_ASC' |
'age_DESC' |
'isRequired_ASC' |
'isRequired_DESC' |
'stringEnumField_ASC' |
'stringEnumField_DESC' |
'rating_ASC' |
'rating_DESC'

@@ -89,6 +94,7 @@ export interface UserCreateInput {
email: String
age: Float
isRequired: Boolean
stringEnumField: StringEnum
rating: Float
}

@@ -98,6 +104,7 @@ export interface UserUpdateInput {
email?: String | null
age?: Float | null
isRequired?: Boolean | null
stringEnumField?: StringEnum | null
rating?: Float | null
}

@@ -146,6 +153,8 @@ export interface UserWhereInput {
age_in?: Int[] | Int | null
isRequired_eq?: Boolean | null
isRequired_in?: Boolean[] | Boolean | null
stringEnumField_eq?: StringEnum | null
stringEnumField_in?: StringEnum[] | StringEnum | null
rating_eq?: Float | null
rating_gt?: Float | null
rating_gte?: Float | null
@@ -214,6 +223,7 @@ export interface User extends BaseGraphQLObject {
email: String
age: Int
isRequired: Boolean
stringEnumField: StringEnum
rating: Float
}

@@ -16,6 +16,7 @@ import { registerEnumType } from "type-graphql";
const { GraphQLJSONObject } = require("graphql-type-json");

import { BaseWhereInput, PaginationArgs } from "../../../src";
import { StringEnum } from "../src/user.model";
// @ts-ignore
import { User } from "../src/user.model";

@@ -44,6 +45,9 @@ export enum UserOrderByEnum {
isRequired_ASC = "isRequired_ASC",
isRequired_DESC = "isRequired_DESC",

stringEnumField_ASC = "stringEnumField_ASC",
stringEnumField_DESC = "stringEnumField_DESC",

rating_ASC = "rating_ASC",
rating_DESC = "rating_DESC"
}
@@ -123,6 +127,12 @@ export class UserWhereInput extends BaseWhereInput {
@TypeGraphQLField(() => [Boolean], { nullable: true })
isRequired_in?: Boolean[];

@TypeGraphQLField(() => StringEnum, { nullable: true })
stringEnumField_eq?: StringEnum;

@TypeGraphQLField(() => [StringEnum], { nullable: true })
stringEnumField_in?: StringEnum[];

@TypeGraphQLField({ nullable: true })
rating_eq?: number;

@@ -168,6 +178,9 @@ export class UserCreateInput {
@TypeGraphQLField()
isRequired!: boolean;

@TypeGraphQLField(() => StringEnum)
stringEnumField!: StringEnum;

@TypeGraphQLField()
rating!: number;
}
@@ -189,6 +202,9 @@ export class UserUpdateInput {
@TypeGraphQLField({ nullable: true })
isRequired?: boolean;

@TypeGraphQLField(() => StringEnum, { nullable: true })
stringEnumField?: StringEnum;

@TypeGraphQLField({ nullable: true })
rating?: number;
}
@@ -79,6 +79,11 @@ type StandardDeleteResponse {
id: ID!
}

enum StringEnum {
FOO
BAR
}

type User implements BaseGraphQLObject {
id: ID!
createdAt: DateTime!
@@ -93,6 +98,7 @@ type User implements BaseGraphQLObject {
email: String!
age: Int!
isRequired: Boolean!
stringEnumField: StringEnum!
rating: Float!
}

@@ -102,6 +108,7 @@ input UserCreateInput {
email: String!
age: Float!
isRequired: Boolean!
stringEnumField: StringEnum!
rating: Float!
}

@@ -122,6 +129,8 @@ enum UserOrderByInput {
age_DESC
isRequired_ASC
isRequired_DESC
stringEnumField_ASC
stringEnumField_DESC
rating_ASC
rating_DESC
}
@@ -132,6 +141,7 @@ input UserUpdateInput {
email: String
age: Float
isRequired: Boolean
stringEnumField: StringEnum
rating: Float
}

@@ -180,6 +190,8 @@ input UserWhereInput {
age_in: [Int!]
isRequired_eq: Boolean
isRequired_in: [Boolean!]
stringEnumField_eq: StringEnum
stringEnumField_in: [StringEnum!]
rating_eq: Float
rating_gt: Float
rating_gte: Float
@@ -2,13 +2,13 @@
"name": "example1",
"version": "0.0.0",
"scripts": {
"bootstrap": "cd ../.. && yarn && yarn link && cd - && yarn && yarn clean && yarn db:create && yarn codegen",
"clean": "rm -f ./warthog.sqlite.tmp",
"codegen": "warthog codegen",
"db:create": "warthog db:create",
"db:drop": "warthog db:drop",
"bootstrap": "cd ../.. && yarn && yarn link && cd - && yarn && yarn db:drop:tempbd && yarn codegen && yarn db:create",
"codegen": "yarn warthog codegen",
"db:create": "yarn warthog db:create",
"db:drop": "yarn warthog db:drop",
"db:drop:tempbd": "rm -f ./warthog.sqlite.tmp",
"db:seed:dev": "ts-node tools/seed.ts",
"playground": "warthog playground",
"playground": "yarn warthog playground",
"start": "yarn start:ts",
"start:ts": "DEBUG=warthog* ts-node-dev --type-check src/index.ts",
"start:prod": "ts-node src/index.ts",
@@ -2,7 +2,7 @@ import {
BaseModel,
BooleanField,
EmailField,
// EnumField,
EnumField,
FloatField,
IntField,
Model,
@@ -11,10 +11,10 @@ import {

// Note: this must be exported and in the same file where it's attached with @EnumField
// Also - must use string enums
// export enum StringEnum {
// FOO = 'FOO',
// BAR = 'BAR'
// }
export enum StringEnum {
FOO = 'FOO',
BAR = 'BAR'
}

@Model()
export class User extends BaseModel {
@@ -33,8 +33,8 @@ export class User extends BaseModel {
@BooleanField()
isRequired?: boolean;

// @EnumField('StringEnum', StringEnum)
// stringEnumField: StringEnum;
@EnumField('StringEnum', StringEnum)
stringEnumField: StringEnum;

@FloatField()
rating?: number;
@@ -40,6 +40,9 @@ export const Binding = makeBindingClass<BindingConstructor<Binding>>({ schema })
* Types
*/

export type StringEnum = 'FOO' |
'BAR'

export type UserOrderByInput = 'createdAt_ASC' |
'createdAt_DESC' |
'updatedAt_ASC' |
@@ -90,7 +93,7 @@ export interface BaseWhereInput {
export interface UserCreateInput {
firstName: String
lastName: String
stringEnumField: String
stringEnumField: StringEnum
email: String
registeredAt: DateTime
nickName?: String | null
@@ -101,7 +104,7 @@ export interface UserCreateInput {
export interface UserUpdateInput {
firstName?: String | null
lastName?: String | null
stringEnumField?: String | null
stringEnumField?: StringEnum | null
email?: String | null
registeredAt?: DateTime | null
nickName?: String | null
@@ -141,11 +144,8 @@ export interface UserWhereInput {
lastName_startsWith?: String | null
lastName_endsWith?: String | null
lastName_in?: String[] | String | null
stringEnumField_eq?: String | null
stringEnumField_contains?: String | null
stringEnumField_startsWith?: String | null
stringEnumField_endsWith?: String | null
stringEnumField_in?: String[] | String | null
stringEnumField_eq?: StringEnum | null
stringEnumField_in?: StringEnum[] | StringEnum | null
email_eq?: String | null
email_contains?: String | null
email_startsWith?: String | null
@@ -169,6 +169,8 @@ export interface UserWhereInput {

export interface UserWhereUniqueInput {
id?: String | null
firstName?: String | null
stringEnumField?: StringEnum | null
email?: String | null
}

@@ -224,7 +226,7 @@ export interface User extends BaseGraphQLObject {
version: Int
firstName: String
lastName: String
stringEnumField: String
stringEnumField: StringEnum
email: String
registeredAt: DateTime
nickName?: String | null

0 comments on commit 6412bb2

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