Skip to content

Commit

Permalink
Merge branch 'next' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
unlight committed Apr 30, 2021
2 parents 7197d6c + 1ec9a98 commit f799c9e
Show file tree
Hide file tree
Showing 89 changed files with 1,447 additions and 337 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = {
},
overrides: [
{
files: ['*.spec.ts', '**/test/**/*.ts'],
files: ['*.spec.ts', '**/{test,@generated}/**/*.ts'],
rules: {
'sonarjs/no-identical-functions': 0,
'consistent-return': 0,
Expand All @@ -112,6 +112,7 @@ module.exports = {
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-non-null-asserted-optional-chain': 0,
'import/max-dependencies': 0,
'sonarjs/no-duplicate-string': 0,
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## [11.4.0](https://github.com/unlight/nestjs-graphql-prisma/compare/v11.3.1...v11.4.0) (2021-04-28)


### Features

* **configuration:** Allow purge output folder ([a360869](https://github.com/unlight/nestjs-graphql-prisma/commit/a360869fba2685ee5e463fcb6781039ec88b2356)), closes [#7](https://github.com/unlight/nestjs-graphql-prisma/issues/7)

### [11.3.1](https://github.com/unlight/nestjs-graphql-prisma/compare/v11.3.0...v11.3.1) (2021-04-25)


### Bug Fixes

* Existence check of tsconfig ([4d523d2](https://github.com/unlight/nestjs-graphql-prisma/commit/4d523d2d99b5ab73a7de680a4ee603748a17c325)), closes [#23](https://github.com/unlight/nestjs-graphql-prisma/issues/23)

## [11.3.0](https://github.com/unlight/nestjs-graphql-prisma/compare/v11.2.0...v11.3.0) (2021-04-25)


### Features

* @PropertyType() to replace types_ configuration ([4a7313d](https://github.com/unlight/nestjs-graphql-prisma/commit/4a7313dcab940093b238c050405a935c92c26248))


### Bug Fixes

* Model types mismatch ([ffe70b6](https://github.com/unlight/nestjs-graphql-prisma/commit/ffe70b69a3fa1661c5f1beed9bc490ccd2f292c4)), closes [#21](https://github.com/unlight/nestjs-graphql-prisma/issues/21)
* Prisma client generator is optional ([4ce28f1](https://github.com/unlight/nestjs-graphql-prisma/commit/4ce28f153ef8fd9e27066a8f2a0402c27ad4d679)), closes [#25](https://github.com/unlight/nestjs-graphql-prisma/issues/25)

## [11.2.0](https://github.com/unlight/nestjs-graphql-prisma/compare/v11.1.0...v11.2.0) (2021-04-16)


Expand Down
94 changes: 87 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ generator nestgraphql {
npx prisma generate
```

3. If your models have `Decimal` and `Json` types, you need install:

```sh
npm install graphql-type-json prisma-graphql-type-decimal

```

- [graphql-type-json](https://github.com/taion/graphql-type-json)
- [prisma-graphql-type-decimal](https://github.com/unlight/prisma-graphql-type-decimal)

Or write you own graphql scalar types, [read more on docs.nestjs.com](https://docs.nestjs.com/graphql/scalars).

## Generator options

#### `output`
Expand All @@ -53,8 +65,8 @@ Possible tokens:
#### `tsConfigFilePath`

Path to `tsconfig.json`
Type: `string`
Default: `tsconfig.json`
Type: `string | undefined`
Default: `undefined`

#### `combineScalarFilters`

Expand Down Expand Up @@ -102,8 +114,15 @@ with temporal dead zone when generating merged file.
Type: `boolean`
Default: `false`

#### `types_*`
#### `purgeOutput`

Delete all files in `output` folder
Type: `boolean`
Default: `false`

#### `types_*` (deprecated)

<details>
Map prisma scalar types in [flatten](https://github.com/hughsk/flat) style

- `types_{type}_fieldType` TypeScript field type name
Expand Down Expand Up @@ -147,6 +166,8 @@ Generated fields:
field: Date;
```

</details>

## Field Settings

Special directives in triple slash comments for more precise code generation.
Expand Down Expand Up @@ -206,6 +227,7 @@ generator nestgraphql {
fields_{Namespace}_output = true | false
fields_{Namespace}_defaultImport = "default import name" | true
fields_{Namespace}_namespaceImport = "namespace import name"
fields_{Namespace}_namedImport = true | false
}
```

Expand All @@ -214,9 +236,8 @@ Where `{Namespace}` is a namespace used in field triple slash comment.

##### `fields_{Namespace}_from`

Name of the module, which will be used in import (`class-validator`, `graphql-scalars`, etc.)
Type: `string`
Required: yes
Required. Name of the module, which will be used in import (`class-validator`, `graphql-scalars`, etc.)
Type: `string`

##### `fields_{Namespace}_input`

Expand All @@ -243,7 +264,14 @@ Import all as this namespace from module
Type: `undefined | string`
Default: Equals to `{Namespace}`

Example:
##### `fields_{Namespace}_namedImport`

If imported module has internal namespace, this allow to generate named import,
imported name will be equal to `{Namespace}`, see [example of usage](#propertytype)
Type: `boolean`
Default: `false`

Custom decorators example:

```prisma
generator nestgraphql {
Expand Down Expand Up @@ -327,6 +355,58 @@ model User {
The result will be the same. `Scalars` is the namespace here.
Missing field options will merged from generator configuration.

##### @PropertyType()

Similar to `@FieldType()` but refer to TypeScript property (actually field too).

Named import example:

```prisma
model Transfer {
id String @id
/// @PropertyType({ name: 'Prisma.Decimal', from: '@prisma/client', namedImport: true })
money Decimal
}
```

May generate following:

```ts
import { Prisma } from '@prisma/client';

@ObjectType()
export class User {
@Field(() => GraphQLDecimal)
money!: Prisma.Decimal;
}
```

Another example:

```
generator nestgraphql {
fields_TF_from = "type-fest"
}
model User {
id String @id
/// @PropertyType('TF.JsonObject')
data Json
}
```

May generate:

```ts
import * as TF from 'type-fest';

@ObjectType()
export class User {
@Field(() => GraphQLJSON)
data!: TF.JsonObject;
}
```

## Similar Projects

- https://github.com/wSedlacek/prisma-generators/tree/master/libs/nestjs
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"precise-commits": "^1.0.2",
"prettier": "^2.2.1",
"prisma": "2.21.2",
"prisma-graphql-type-decimal": "^1.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.7",
"semantic-release": "^17.4.2",
Expand Down
8 changes: 5 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ datasource database {

generator client {
provider = "prisma-client-js"
previewFeatures = ["orderByRelation", "selectRelationCount"]
previewFeatures = ["orderByRelation", "selectRelationCount", "orderByAggregateGroup"]
}

generator nestgraphql {
provider = "node -r ts-node/register/transpile-only src/index.ts"
output = "../src/@generated"
provider = "node -r ts-node/register/transpile-only src/index.ts"
output = "../src/@generated"
noAtomicOperations = false
combineScalarFilters = false
reExport = None
emitSingle = false
emitCompiled = false
purgeOutput = false
}

model User {
Expand Down Expand Up @@ -77,6 +78,7 @@ enum Role {

model Dummy {
id String @id
created DateTime @default(now())
floaty Float
int Int?
float Float?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Field, InputType } from '@nestjs/graphql';

import { SortOrder } from '../prisma/sort-order.enum';

@InputType()
export class ArticleAvgOrderByAggregateInput {
@Field(() => SortOrder, { nullable: true })
favoritesCount?: SortOrder;
}
36 changes: 36 additions & 0 deletions src/@generated/article/article-count-order-by-aggregate.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Field, InputType } from '@nestjs/graphql';

import { SortOrder } from '../prisma/sort-order.enum';

@InputType()
export class ArticleCountOrderByAggregateInput {
@Field(() => SortOrder, { nullable: true })
id?: SortOrder;

@Field(() => SortOrder, { nullable: true })
slug?: SortOrder;

@Field(() => SortOrder, { nullable: true })
title?: SortOrder;

@Field(() => SortOrder, { nullable: true })
description?: SortOrder;

@Field(() => SortOrder, { nullable: true })
body?: SortOrder;

@Field(() => SortOrder, { nullable: true })
createdAt?: SortOrder;

@Field(() => SortOrder, { nullable: true })
updatedAt?: SortOrder;

@Field(() => SortOrder, { nullable: true })
favoritesCount?: SortOrder;

@Field(() => SortOrder, { nullable: true })
authorId?: SortOrder;

@Field(() => SortOrder, { nullable: true })
active?: SortOrder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Field, InputType } from '@nestjs/graphql';
import { SortOrder } from '../prisma/sort-order.enum';

@InputType()
export class ArticleOrderByInput {
export class ArticleMaxOrderByAggregateInput {
@Field(() => SortOrder, { nullable: true })
id?: SortOrder;

Expand Down
36 changes: 36 additions & 0 deletions src/@generated/article/article-min-order-by-aggregate.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Field, InputType } from '@nestjs/graphql';

import { SortOrder } from '../prisma/sort-order.enum';

@InputType()
export class ArticleMinOrderByAggregateInput {
@Field(() => SortOrder, { nullable: true })
id?: SortOrder;

@Field(() => SortOrder, { nullable: true })
slug?: SortOrder;

@Field(() => SortOrder, { nullable: true })
title?: SortOrder;

@Field(() => SortOrder, { nullable: true })
description?: SortOrder;

@Field(() => SortOrder, { nullable: true })
body?: SortOrder;

@Field(() => SortOrder, { nullable: true })
createdAt?: SortOrder;

@Field(() => SortOrder, { nullable: true })
updatedAt?: SortOrder;

@Field(() => SortOrder, { nullable: true })
favoritesCount?: SortOrder;

@Field(() => SortOrder, { nullable: true })
authorId?: SortOrder;

@Field(() => SortOrder, { nullable: true })
active?: SortOrder;
}
56 changes: 56 additions & 0 deletions src/@generated/article/article-order-by-with-aggregation.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Field, InputType } from '@nestjs/graphql';

import { SortOrder } from '../prisma/sort-order.enum';
import { ArticleAvgOrderByAggregateInput } from './article-avg-order-by-aggregate.input';
import { ArticleCountOrderByAggregateInput } from './article-count-order-by-aggregate.input';
import { ArticleMaxOrderByAggregateInput } from './article-max-order-by-aggregate.input';
import { ArticleMinOrderByAggregateInput } from './article-min-order-by-aggregate.input';
import { ArticleSumOrderByAggregateInput } from './article-sum-order-by-aggregate.input';

@InputType()
export class ArticleOrderByWithAggregationInput {
@Field(() => SortOrder, { nullable: true })
id?: SortOrder;

@Field(() => SortOrder, { nullable: true })
slug?: SortOrder;

@Field(() => SortOrder, { nullable: true })
title?: SortOrder;

@Field(() => SortOrder, { nullable: true })
description?: SortOrder;

@Field(() => SortOrder, { nullable: true })
body?: SortOrder;

@Field(() => SortOrder, { nullable: true })
createdAt?: SortOrder;

@Field(() => SortOrder, { nullable: true })
updatedAt?: SortOrder;

@Field(() => SortOrder, { nullable: true })
favoritesCount?: SortOrder;

@Field(() => SortOrder, { nullable: true })
authorId?: SortOrder;

@Field(() => SortOrder, { nullable: true })
active?: SortOrder;

@Field(() => ArticleCountOrderByAggregateInput, { nullable: true })
_count?: ArticleCountOrderByAggregateInput;

@Field(() => ArticleAvgOrderByAggregateInput, { nullable: true })
_avg?: ArticleAvgOrderByAggregateInput;

@Field(() => ArticleMaxOrderByAggregateInput, { nullable: true })
_max?: ArticleMaxOrderByAggregateInput;

@Field(() => ArticleMinOrderByAggregateInput, { nullable: true })
_min?: ArticleMinOrderByAggregateInput;

@Field(() => ArticleSumOrderByAggregateInput, { nullable: true })
_sum?: ArticleSumOrderByAggregateInput;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Field, InputType } from '@nestjs/graphql';

import { SortOrder } from '../prisma/sort-order.enum';

@InputType()
export class ArticleSumOrderByAggregateInput {
@Field(() => SortOrder, { nullable: true })
favoritesCount?: SortOrder;
}
Loading

0 comments on commit f799c9e

Please sign in to comment.