Skip to content

Commit

Permalink
feat(decorators): add DateOnly and DateTime (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Aug 24, 2020
1 parent 7f1e447 commit 6c77c2f
Show file tree
Hide file tree
Showing 22 changed files with 454 additions and 98 deletions.
27 changes: 27 additions & 0 deletions examples/02-complex-example/generated/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export type UserOrderByInput = 'createdAt_ASC' |
'booleanField_DESC' |
'dateField_ASC' |
'dateField_DESC' |
'dateOnlyField_ASC' |
'dateOnlyField_DESC' |
'dateTimeField_ASC' |
'dateTimeField_DESC' |
'emailField_ASC' |
'emailField_DESC' |
'enumField_ASC' |
Expand Down Expand Up @@ -137,6 +141,8 @@ export interface BaseWhereInput {
export interface UserCreateInput {
booleanField?: Boolean | null
dateField?: DateTime | null
dateOnlyField?: Date | null
dateTimeField?: DateTime | null
emailField?: String | null
enumField?: StringEnum | null
floatField?: Float | null
Expand Down Expand Up @@ -175,6 +181,8 @@ export interface UserCreateInput {
export interface UserUpdateInput {
booleanField?: Boolean | null
dateField?: DateTime | null
dateOnlyField?: Date | null
dateTimeField?: DateTime | null
emailField?: String | null
enumField?: StringEnum | null
floatField?: Float | null
Expand Down Expand Up @@ -242,6 +250,16 @@ export interface UserWhereInput {
dateField_lte?: DateTime | null
dateField_gt?: DateTime | null
dateField_gte?: DateTime | null
dateOnlyField_eq?: Date | null
dateOnlyField_lt?: Date | null
dateOnlyField_lte?: Date | null
dateOnlyField_gt?: Date | null
dateOnlyField_gte?: Date | null
dateTimeField_eq?: DateTime | null
dateTimeField_lt?: DateTime | null
dateTimeField_lte?: DateTime | null
dateTimeField_gt?: DateTime | null
dateTimeField_gte?: DateTime | null
emailField_eq?: String | null
emailField_contains?: String | null
emailField_startsWith?: String | null
Expand Down Expand Up @@ -456,6 +474,8 @@ export interface User extends BaseGraphQLObject {
version: Int
booleanField?: Boolean | null
dateField?: DateTime | null
dateOnlyField?: Date | null
dateTimeField?: DateTime | null
emailField?: String | null
enumField?: StringEnum | null
floatField?: Float | null
Expand Down Expand Up @@ -495,6 +515,13 @@ The `Boolean` scalar type represents `true` or `false`.
*/
export type Boolean = boolean

/*
A date string, such as 2007-12-03, compliant with the `full-date` format
outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for
representation of dates and times using the Gregorian calendar.
*/
export type Date = string

/*
The javascript `Date` as string. Type represents date and time as the ISO Date string.
*/
Expand Down
104 changes: 79 additions & 25 deletions examples/02-complex-example/generated/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// will be re-written. If you need to change this file, update models or add
// new TypeGraphQL objects
// @ts-ignore
import { GraphQLDateTime as DateTime } from "graphql-iso-date";
import { DateResolver as Date } from "graphql-scalars";
// @ts-ignore
import { GraphQLID as ID } from "graphql";
// @ts-ignore
Expand All @@ -14,13 +14,19 @@ import {
Int
} from "type-graphql";
// @ts-ignore
import { registerEnumType } from "type-graphql";
import { registerEnumType, GraphQLISODateTime as DateTime } from "type-graphql";

// @ts-ignore eslint-disable-next-line @typescript-eslint/no-var-requires
const { GraphQLJSONObject } = require("graphql-type-json");

// @ts-ignore
import { BaseWhereInput, JsonObject, PaginationArgs } from "../../../src";
import {
BaseWhereInput,
JsonObject,
PaginationArgs,
DateOnlyString,
DateTimeString
} from "../../../src";
import { StringEnum } from "../src/modules/user/user.model";
// @ts-ignore
import { User } from "../src/modules/user/user.model";
Expand All @@ -41,6 +47,12 @@ export enum UserOrderByEnum {
dateField_ASC = "dateField_ASC",
dateField_DESC = "dateField_DESC",

dateOnlyField_ASC = "dateOnlyField_ASC",
dateOnlyField_DESC = "dateOnlyField_DESC",

dateTimeField_ASC = "dateTimeField_ASC",
dateTimeField_DESC = "dateTimeField_DESC",

emailField_ASC = "emailField_ASC",
emailField_DESC = "emailField_DESC",

Expand Down Expand Up @@ -135,19 +147,19 @@ export class UserWhereInput {
@TypeGraphQLField(() => [ID], { nullable: true })
id_in?: string[];

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

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

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

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

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

@TypeGraphQLField(() => ID, { nullable: true })
Expand All @@ -156,19 +168,19 @@ export class UserWhereInput {
@TypeGraphQLField(() => [ID], { nullable: true })
createdById_in?: string[];

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

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

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

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

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

@TypeGraphQLField(() => ID, { nullable: true })
Expand All @@ -180,19 +192,19 @@ export class UserWhereInput {
@TypeGraphQLField({ nullable: true })
deletedAt_all?: Boolean;

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

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

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

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

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

@TypeGraphQLField(() => ID, { nullable: true })
Expand All @@ -207,21 +219,51 @@ export class UserWhereInput {
@TypeGraphQLField(() => [Boolean], { nullable: true })
booleanField_in?: Boolean[];

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

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

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

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

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

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField_eq?: DateOnlyString;

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField_lt?: DateOnlyString;

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField_lte?: DateOnlyString;

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField_gt?: DateOnlyString;

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField_gte?: DateOnlyString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField_eq?: DateTimeString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField_lt?: DateTimeString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField_lte?: DateTimeString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField_gt?: DateTimeString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField_gte?: DateTimeString;

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

Expand Down Expand Up @@ -678,9 +720,15 @@ export class UserCreateInput {
@TypeGraphQLField({ nullable: true })
booleanField?: boolean;

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

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField?: DateOnlyString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField?: DateTimeString;

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

Expand Down Expand Up @@ -786,9 +834,15 @@ export class UserUpdateInput {
@TypeGraphQLField({ nullable: true })
booleanField?: boolean;

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

@TypeGraphQLField(() => Date, { nullable: true })
dateOnlyField?: DateOnlyString;

@TypeGraphQLField(() => DateTime, { nullable: true })
dateTimeField?: DateTimeString;

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

Expand Down
27 changes: 27 additions & 0 deletions examples/02-complex-example/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ input BaseWhereInput {
deletedById_eq: String
}

"""
A date string, such as 2007-12-03, compliant with the `full-date` format
outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for
representation of dates and times using the Gregorian calendar.
"""
scalar Date

"""
The javascript `Date` as string. Type represents date and time as the ISO Date string.
"""
Expand Down Expand Up @@ -108,6 +115,8 @@ type User implements BaseGraphQLObject {
version: Int!
booleanField: Boolean
dateField: DateTime
dateOnlyField: Date
dateTimeField: DateTime
emailField: String
enumField: StringEnum
floatField: Float
Expand Down Expand Up @@ -147,6 +156,8 @@ type User implements BaseGraphQLObject {
input UserCreateInput {
booleanField: Boolean
dateField: DateTime
dateOnlyField: Date
dateTimeField: DateTime
emailField: String
enumField: StringEnum
floatField: Float
Expand Down Expand Up @@ -193,6 +204,10 @@ enum UserOrderByInput {
booleanField_DESC
dateField_ASC
dateField_DESC
dateOnlyField_ASC
dateOnlyField_DESC
dateTimeField_ASC
dateTimeField_DESC
emailField_ASC
emailField_DESC
enumField_ASC
Expand Down Expand Up @@ -252,6 +267,8 @@ enum UserOrderByInput {
input UserUpdateInput {
booleanField: Boolean
dateField: DateTime
dateOnlyField: Date
dateTimeField: DateTime
emailField: String
enumField: StringEnum
floatField: Float
Expand Down Expand Up @@ -319,6 +336,16 @@ input UserWhereInput {
dateField_lte: DateTime
dateField_gt: DateTime
dateField_gte: DateTime
dateOnlyField_eq: Date
dateOnlyField_lt: Date
dateOnlyField_lte: Date
dateOnlyField_gt: Date
dateOnlyField_gte: Date
dateTimeField_eq: DateTime
dateTimeField_lt: DateTime
dateTimeField_lte: DateTime
dateTimeField_gt: DateTime
dateTimeField_gte: DateTime
emailField_eq: String
emailField_contains: String
emailField_startsWith: String
Expand Down
12 changes: 11 additions & 1 deletion examples/02-complex-example/src/modules/user/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
BooleanField,
CustomField,
DateField,
DateOnlyField,
DateOnlyString,
DateTimeField,
DateTimeString,
EmailField,
EnumField,
IdField,
Expand Down Expand Up @@ -32,8 +36,14 @@ export class User extends BaseModel {
@DateField({ nullable: true })
dateField: Date;

@DateOnlyField({ nullable: true })
dateOnlyField?: DateOnlyString;

@DateTimeField({ nullable: true })
dateTimeField?: DateTimeString;

@EmailField({ nullable: true })
emailField: string;
emailField?: string;

@EnumField('StringEnum', StringEnum, { nullable: true })
enumField: StringEnum;
Expand Down
4 changes: 4 additions & 0 deletions examples/02-complex-example/tools/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ async function seedDatabase() {
emptyArray: []
};
const dateField = new Date().toISOString();
const dateOnlyField = new Date().toISOString().substring(0, 10);
const dateTimeField = new Date().toISOString();

try {
const user = await binding.mutation.createUser(
Expand All @@ -53,6 +55,8 @@ async function seedDatabase() {
stringField,
jsonField,
dateField,
dateOnlyField,
dateTimeField,
enumField: 'FOO',
geometryField: {
type: 'Point',
Expand Down
Loading

0 comments on commit 6c77c2f

Please sign in to comment.