diff --git a/@generated/dummy/dummy.model.ts b/@generated/dummy/dummy.model.ts index 9980fecd..6d472d9c 100644 --- a/@generated/dummy/dummy.model.ts +++ b/@generated/dummy/dummy.model.ts @@ -4,6 +4,7 @@ import { ID } from '@nestjs/graphql'; import { Float } from '@nestjs/graphql'; import { Int } from '@nestjs/graphql'; import { GraphQLDecimal } from 'prisma-graphql-type-decimal'; +import { Decimal } from '@prisma/client/runtime'; import { GraphQLJSON } from 'graphql-type-json'; @ObjectType() diff --git a/README.md b/README.md index 8f9fbc0a..60c49f0f 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,9 @@ Possible tokens: #### `tsConfigFilePath` -Path to `tsconfig.json` +Path to `tsconfig.json` (absolute path or relative to current working directory) Type: `string | undefined` -Default: `undefined` +Default: `tsconfig.json` if exists, `undefined` otherwise #### `combineScalarFilters` diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2ed5fa1f..77222bbe 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,123 +1,123 @@ datasource database { - provider = "postgres" - url = env("DATABASE_URL") + provider = "postgres" + url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" - previewFeatures = ["filterJson", "fullTextSearch"] + provider = "prisma-client-js" + previewFeatures = ["filterJson", "fullTextSearch"] } generator nestgraphql { - provider = "node -r ts-node/register/transpile-only src/index.ts" - output = "../@generated" - noAtomicOperations = false - combineScalarFilters = false - reExport = None - emitSingle = false - emitCompiled = false - purgeOutput = false - requireSingleFieldsInWhereUniqueInput = false - fields_Validator_from = "class-validator" - fields_Validator_input = true - fields_Scalars_from = "graphql-scalars" - fields_Scalars_input = true - useInputType_WhereInput_ALL = "WhereInput" - decorate_1_type = "Create@(One|Many)UserArgs" - decorate_1_field = data - decorate_1_name = ValidateNested - decorate_1_from = "class-validator" - decorate_1_arguments = "[]" - decorate_2_type = "Create@(One|Many)UserArgs" - decorate_2_field = data - decorate_2_from = "class-transformer" - decorate_2_arguments = "['() => {propertyType.0}']" - decorate_2_name = Type - decorate_2_namedImport = true + provider = "node -r ts-node/register/transpile-only src/index.ts" + output = "../@generated" + noAtomicOperations = false + combineScalarFilters = false + reExport = None + emitSingle = false + emitCompiled = false + purgeOutput = false + requireSingleFieldsInWhereUniqueInput = false + fields_Validator_from = "class-validator" + fields_Validator_input = true + fields_Scalars_from = "graphql-scalars" + fields_Scalars_input = true + useInputType_WhereInput_ALL = "WhereInput" + decorate_1_type = "Create@(One|Many)UserArgs" + decorate_1_field = data + decorate_1_name = ValidateNested + decorate_1_from = "class-validator" + decorate_1_arguments = "[]" + decorate_2_type = "Create@(One|Many)UserArgs" + decorate_2_field = data + decorate_2_from = "class-transformer" + decorate_2_arguments = "['() => {propertyType.0}']" + decorate_2_name = Type + decorate_2_namedImport = true } /// User really model User { - id String @id @default(cuid()) - /// @FieldType('Scalars.GraphQLEmailAddress') - email String @unique - /// User's name - /// @Validator.MinLength(3) - /// @Validator.MaxLength(50) - name String @unique - /// @HideField() - password String - bio String? - image String? - following User[] @relation("UserFollows", references: [id]) - followers User[] @relation("UserFollows", references: [id]) - favoriteArticles Article[] @relation(name: "FavoritedArticles", references: [id]) - articles Article[] @relation("ArticleAuthor") - comments Comment[] - countComments Int? - rating Float? - role Role? - profile Profile? + id String @id @default(cuid()) + /// @FieldType('Scalars.GraphQLEmailAddress') + email String @unique + /// User's name + /// @Validator.MinLength(3) + /// @Validator.MaxLength(50) + name String @unique + /// @HideField() + password String + bio String? + image String? + following User[] @relation("UserFollows", references: [id]) + followers User[] @relation("UserFollows", references: [id]) + favoriteArticles Article[] @relation(name: "FavoritedArticles", references: [id]) + articles Article[] @relation("ArticleAuthor") + comments Comment[] + countComments Int? + rating Float? + role Role? + profile Profile? - @@unique([email, name]) + @@unique([email, name]) } model Tag { - id String @id @default(cuid()) - name String @unique - articles Article[] + id String @id @default(cuid()) + name String @unique + articles Article[] } model Article { - id String @id @default(cuid()) - slug String @unique - title String - description String - body String - tags Tag[] - /// @HideField({ match: '*Create*Input' }) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - favoritesCount Int @default(0) - author User @relation(name: "ArticleAuthor", fields: [authorId], references: [id]) - authorId String - favoritedBy User[] @relation(name: "FavoritedArticles", references: [id]) - comments Comment[] - active Boolean? @default(true) + id String @id @default(cuid()) + slug String @unique + title String + description String + body String + tags Tag[] + /// @HideField({ match: '*Create*Input' }) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + favoritesCount Int @default(0) + author User @relation(name: "ArticleAuthor", fields: [authorId], references: [id]) + authorId String + favoritedBy User[] @relation(name: "FavoritedArticles", references: [id]) + comments Comment[] + active Boolean? @default(true) } model Comment { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - /// @HideField({ match: '*Update*Input' }) - updatedAt DateTime @updatedAt - body String - author User @relation(fields: [authorId], references: [id]) - authorId String - article Article? @relation(fields: [articleId], references: [id]) - articleId String? + id String @id @default(cuid()) + createdAt DateTime @default(now()) + /// @HideField({ match: '*Update*Input' }) + updatedAt DateTime @updatedAt + body String + author User @relation(fields: [authorId], references: [id]) + authorId String + article Article? @relation(fields: [articleId], references: [id]) + articleId String? } enum Role { - USER + USER } model Profile { - id Int @id @default(autoincrement()) - user User @relation(fields: [userId], references: [id]) - userId String - dummy String? + id Int @id @default(autoincrement()) + user User @relation(fields: [userId], references: [id]) + userId String @unique + dummy String? } model Dummy { - id String @id - created DateTime @default(now()) - floaty Float - int Int? - float Float? - bytes Bytes? - decimal Decimal? - bigInt BigInt? - json Json? - friends String[] + id String @id + created DateTime @default(now()) + floaty Float + int Int? + float Float? + bytes Bytes? + decimal Decimal? + bigInt BigInt? + json Json? + friends String[] } diff --git a/src/helpers/create-config.spec.ts b/src/helpers/create-config.spec.ts index edfc63d5..c453ad5e 100644 --- a/src/helpers/create-config.spec.ts +++ b/src/helpers/create-config.spec.ts @@ -80,4 +80,18 @@ describe('createConfig', () => { expect(result.decorate).toBeInstanceOf(Array); expect(result.decorate).toHaveLength(2); }); + + it('tsConfigFilePath value', () => { + const result = createConfig({ + tsConfigFilePath: 'x.json', + }); + + expect(result.tsConfigFilePath).toEqual('x.json'); + }); + + it('tsConfigFilePath default', () => { + const result = createConfig({}); + + expect(result.tsConfigFilePath).toEqual('tsconfig.json'); + }); }); diff --git a/src/helpers/create-config.ts b/src/helpers/create-config.ts index 2718ca9d..295b0473 100644 --- a/src/helpers/create-config.ts +++ b/src/helpers/create-config.ts @@ -1,8 +1,9 @@ import { ok } from 'assert'; import filenamify from 'filenamify'; import { unflatten } from 'flat'; +import { existsSync } from 'fs'; import JSON5 from 'json5'; -import { Dictionary, merge, trim } from 'lodash'; +import { Dictionary, memoize, merge, trim } from 'lodash'; import outmatch from 'outmatch'; import { ReExport } from '../handlers/re-export'; @@ -100,7 +101,7 @@ export function createConfig(data: Record) { return { outputFilePattern, - tsConfigFilePath: undefined as string | undefined, + tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath), combineScalarFilters: toBoolean(config.combineScalarFilters), noAtomicOperations: toBoolean(config.noAtomicOperations), reExport: (ReExport[String(config.reExport)] || ReExport.None) as ReExport, @@ -128,6 +129,15 @@ type ConfigInputItem = { [index: string]: string | undefined; }; +const tsConfigFileExists = memoize((filePath: string) => { + return existsSync(filePath); +}); + +function createTsConfigFilePathValue(value: unknown): string | undefined { + if (typeof value === 'string') return value; + if (tsConfigFileExists('tsconfig.json')) return 'tsconfig.json'; +} + function createUseInputType(data?: Record) { if (!data) { return [];