Skip to content

Commit

Permalink
fix: tsConfigFilePath is ignored
Browse files Browse the repository at this point in the history
close: unlight#88
  • Loading branch information
unlight committed Apr 3, 2022
1 parent 9483cdd commit d98e146
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 96 deletions.
1 change: 1 addition & 0 deletions @generated/dummy/dummy.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
184 changes: 92 additions & 92 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -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[]
}
14 changes: 14 additions & 0 deletions src/helpers/create-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
14 changes: 12 additions & 2 deletions src/helpers/create-config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -100,7 +101,7 @@ export function createConfig(data: Record<string, unknown>) {

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,
Expand Down Expand Up @@ -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<string, ConfigInputItem>) {
if (!data) {
return [];
Expand Down

0 comments on commit d98e146

Please sign in to comment.