Skip to content

Commit

Permalink
feat(config): allow WARTHOG_DB_URL to set all DB config (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Sep 28, 2020
1 parent d598d3e commit 5a75c4a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 194 deletions.
4 changes: 1 addition & 3 deletions examples/02-complex-example/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ NODE_ENV=development
PGUSER=postgres
WARTHOG_APP_HOST=localhost
WARTHOG_APP_PORT=4100
WARTHOG_DB_DATABASE=warthog-example-2
WARTHOG_DB_USERNAME=postgres
WARTHOG_DB_PASSWORD=
WARTHOG_DB_URL=postgres://postgres:@localhost:5432/warthog-example-2
WARTHOG_DB_SYNCHRONIZE=true
WARTHOG_RESOLVERS_PATH=./src/**/*.resolver.ts
42 changes: 5 additions & 37 deletions examples/02-complex-example/generated/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ export const Binding = makeBindingClass<BindingConstructor<Binding>>({ schema: s
export type StringEnum = 'FOO' |
'BAR'

export type UserOrderByInput = 'createdAt_ASC' |
'createdAt_DESC' |
'updatedAt_ASC' |
'updatedAt_DESC' |
'deletedAt_ASC' |
'deletedAt_DESC' |
'booleanField_ASC' |
export type UserOrderByInput = 'booleanField_ASC' |
'booleanField_DESC' |
'dateField_ASC' |
'dateField_DESC' |
Expand Down Expand Up @@ -153,7 +147,7 @@ export interface UserCreateInput {
bigIntField?: Float | null
jsonField?: JSONObject | null
jsonFieldNoFilter?: JSONObject | null
stringField?: String | null
stringField: String
noFilterField?: String | null
noSortField?: String | null
noFilterOrSortField?: String | null
Expand Down Expand Up @@ -227,30 +221,6 @@ export interface UserUpdateInput {
}

export interface UserWhereInput {
id_eq?: ID_Input | null
id_in?: ID_Output[] | ID_Output | null
createdAt_eq?: DateTime | null
createdAt_lt?: DateTime | null
createdAt_lte?: DateTime | null
createdAt_gt?: DateTime | null
createdAt_gte?: DateTime | null
createdById_eq?: ID_Input | null
createdById_in?: ID_Output[] | ID_Output | null
updatedAt_eq?: DateTime | null
updatedAt_lt?: DateTime | null
updatedAt_lte?: DateTime | null
updatedAt_gt?: DateTime | null
updatedAt_gte?: DateTime | null
updatedById_eq?: ID_Input | null
updatedById_in?: ID_Output[] | ID_Output | null
deletedAt_all?: Boolean | null
deletedAt_eq?: DateTime | null
deletedAt_lt?: DateTime | null
deletedAt_lte?: DateTime | null
deletedAt_gt?: DateTime | null
deletedAt_gte?: DateTime | null
deletedById_eq?: ID_Input | null
deletedById_in?: ID_Output[] | ID_Output | null
booleanField_eq?: Boolean | null
booleanField_in?: Boolean[] | Boolean | null
dateField_eq?: DateTime | null
Expand Down Expand Up @@ -426,7 +396,6 @@ export interface UserWhereInput {
}

export interface UserWhereUniqueInput {
id?: ID_Input | null
emailField?: String | null
enumField?: StringEnum | null
stringField?: String | null
Expand Down Expand Up @@ -470,11 +439,10 @@ export interface BaseModelUUID extends BaseGraphQLObject {
}

export interface PageInfo {
limit: Float
offset: Float
totalCount: Float
hasNextPage: Boolean
hasPreviousPage: Boolean
startCursor?: String | null
endCursor?: String | null
}

export interface StandardDeleteResponse {
Expand Down Expand Up @@ -504,7 +472,7 @@ export interface User extends BaseGraphQLObject {
bigIntField?: Int | null
jsonField?: JSONObject | null
jsonFieldNoFilter?: JSONObject | null
stringField?: String | null
stringField: String
noFilterField?: String | null
noSortField?: String | null
noFilterOrSortField?: String | null
Expand Down
89 changes: 3 additions & 86 deletions examples/02-complex-example/generated/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { registerEnumType, GraphQLISODateTime as DateTime } from "type-graphql";
const { GraphQLJSONObject } = require('graphql-type-json');
// prettier-ignore
// @ts-ignore

import { BaseWhereInput, JsonObject, PaginationArgs, DateOnlyString, DateTimeString } from '../../../src';

import { StringEnum } from "../src/modules/user/user.model";
Expand All @@ -28,15 +29,6 @@ import { StringEnum } from "../src/modules/user/user.model";
import { User } from "../src/modules/user/user.model";

export enum UserOrderByEnum {
createdAt_ASC = "createdAt_ASC",
createdAt_DESC = "createdAt_DESC",

updatedAt_ASC = "updatedAt_ASC",
updatedAt_DESC = "updatedAt_DESC",

deletedAt_ASC = "deletedAt_ASC",
deletedAt_DESC = "deletedAt_DESC",

booleanField_ASC = "booleanField_ASC",
booleanField_DESC = "booleanField_DESC",

Expand Down Expand Up @@ -137,78 +129,6 @@ registerEnumType(UserOrderByEnum, {

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

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

@TypeGraphQLField(() => DateTime, { nullable: true })
createdAt_eq?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
createdAt_lt?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
createdAt_lte?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
createdAt_gt?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
createdAt_gte?: Date;

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

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

@TypeGraphQLField(() => DateTime, { nullable: true })
updatedAt_eq?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
updatedAt_lt?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
updatedAt_lte?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
updatedAt_gt?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
updatedAt_gte?: Date;

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

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

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

@TypeGraphQLField(() => DateTime, { nullable: true })
deletedAt_eq?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
deletedAt_lt?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
deletedAt_lte?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
deletedAt_gt?: Date;

@TypeGraphQLField(() => DateTime, { nullable: true })
deletedAt_gte?: Date;

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

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

@TypeGraphQLField(() => Boolean, { nullable: true })
booleanField_eq?: Boolean;

Expand Down Expand Up @@ -728,9 +648,6 @@ export class UserWhereInput {

@TypeGraphQLInputType()
export class UserWhereUniqueInput {
@TypeGraphQLField(() => ID, { nullable: true })
id?: string;

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

Expand Down Expand Up @@ -785,8 +702,8 @@ export class UserCreateInput {
@TypeGraphQLField(() => GraphQLJSONObject, { nullable: true })
jsonFieldNoFilter?: JsonObject;

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

@TypeGraphQLField({ nullable: true })
noFilterField?: string;
Expand Down
40 changes: 4 additions & 36 deletions examples/02-complex-example/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ type Mutation {
}

type PageInfo {
limit: Float!
offset: Float!
totalCount: Float!
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}

type Query {
Expand Down Expand Up @@ -129,7 +128,7 @@ type User implements BaseGraphQLObject {
jsonFieldNoFilter: JSONObject

"""This is a string field"""
stringField: String
stringField: String!
noFilterField: String
noSortField: String
noFilterOrSortField: String
Expand Down Expand Up @@ -172,7 +171,7 @@ input UserCreateInput {
bigIntField: Float
jsonField: JSONObject
jsonFieldNoFilter: JSONObject
stringField: String
stringField: String!
noFilterField: String
noSortField: String
noFilterOrSortField: String
Expand Down Expand Up @@ -202,12 +201,6 @@ input UserCreateInput {
}

enum UserOrderByInput {
createdAt_ASC
createdAt_DESC
updatedAt_ASC
updatedAt_DESC
deletedAt_ASC
deletedAt_DESC
booleanField_ASC
booleanField_DESC
dateField_ASC
Expand Down Expand Up @@ -317,30 +310,6 @@ input UserUpdateInput {
}

input UserWhereInput {
id_eq: ID
id_in: [ID!]
createdAt_eq: DateTime
createdAt_lt: DateTime
createdAt_lte: DateTime
createdAt_gt: DateTime
createdAt_gte: DateTime
createdById_eq: ID
createdById_in: [ID!]
updatedAt_eq: DateTime
updatedAt_lt: DateTime
updatedAt_lte: DateTime
updatedAt_gt: DateTime
updatedAt_gte: DateTime
updatedById_eq: ID
updatedById_in: [ID!]
deletedAt_all: Boolean
deletedAt_eq: DateTime
deletedAt_lt: DateTime
deletedAt_lte: DateTime
deletedAt_gt: DateTime
deletedAt_gte: DateTime
deletedById_eq: ID
deletedById_in: [ID!]
booleanField_eq: Boolean
booleanField_in: [Boolean!]
dateField_eq: DateTime
Expand Down Expand Up @@ -516,7 +485,6 @@ input UserWhereInput {
}

input UserWhereUniqueInput {
id: ID
emailField: String
enumField: StringEnum
stringField: String
Expand Down
23 changes: 10 additions & 13 deletions examples/02-complex-example/src/modules/user/user.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import { Arg, Args, Authorized, Ctx, Mutation, Query, Resolver } from 'type-graphql';
import { Repository } from 'typeorm';
import { InjectRepository } from 'typeorm-typedi-extensions';
import { Inject } from 'typedi';

import { BaseContext, BaseResolver, StandardDeleteResponse } from '../../../../../src';
import { BaseContext, StandardDeleteResponse } from '../../../../../src';
import {
UserCreateInput,
UserUpdateArgs,
UserWhereArgs,
UserWhereInput,
UserWhereUniqueInput
} from '../../../generated';

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

@Resolver(User)
export class UserResolver extends BaseResolver<User> {
constructor(@InjectRepository(User) public readonly userRepository: Repository<User>) {
super(User, userRepository);
}
export class UserResolver {
constructor(@Inject('UserService') public readonly service: UserService) {}

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

@Authorized('user:read')
@Query(() => User)
async user(@Arg('where') where: UserWhereUniqueInput): Promise<User> {
return this.findOne<UserWhereUniqueInput>(where);
return this.service.findOne<UserWhereUniqueInput>(where);
}

@Authorized('user:create')
@Mutation(() => User)
async createUser(@Arg('data') data: UserCreateInput, @Ctx() ctx: BaseContext): Promise<User> {
return this.create(data, ctx.user.id);
return this.service.create(data, ctx.user.id);
}

@Authorized('user:update')
Expand All @@ -42,7 +39,7 @@ export class UserResolver extends BaseResolver<User> {
@Args() { data, where }: UserUpdateArgs,
@Ctx() ctx: BaseContext
): Promise<User> {
return this.update(data, where, ctx.user.id);
return this.service.update(data, where, ctx.user.id);
}

@Authorized('user:delete')
Expand All @@ -51,6 +48,6 @@ export class UserResolver extends BaseResolver<User> {
@Arg('where') where: UserWhereUniqueInput,
@Ctx() ctx: BaseContext
): Promise<StandardDeleteResponse> {
return this.delete(where, ctx.user.id);
return this.service.delete(where, ctx.user.id);
}
}
14 changes: 14 additions & 0 deletions examples/02-complex-example/src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Service } from 'typedi';
import { Repository } from 'typeorm';
import { InjectRepository } from 'typeorm-typedi-extensions';

import { BaseService } from '../../../../../src';

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

@Service('UserService')
export class UserService extends BaseService<User> {
constructor(@InjectRepository(User) protected readonly repository: Repository<User>) {
super(User, repository);
}
}
Loading

0 comments on commit 5a75c4a

Please sign in to comment.