prisma-nestjs-graphql 15.2.6 → 15.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -83
- package/index.js +128 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Generate object types, inputs, args, etc. from prisma schema file for usage with
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- Generates only necessary imports
|
|
8
|
+
- Combines zoo of nested/nullable filters
|
|
9
|
+
- Does not generate resolvers, since it's application specific
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -40,8 +40,8 @@ npm install graphql-type-json prisma-graphql-type-decimal
|
|
|
40
40
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
-
|
|
44
|
-
-
|
|
43
|
+
- [graphql-type-json](https://github.com/taion/graphql-type-json)
|
|
44
|
+
- [prisma-graphql-type-decimal](https://github.com/unlight/prisma-graphql-type-decimal)
|
|
45
45
|
|
|
46
46
|
Or write you own graphql scalar types, [read more on docs.nestjs.com](https://docs.nestjs.com/graphql/scalars).
|
|
47
47
|
|
|
@@ -59,10 +59,10 @@ Type: `string`
|
|
|
59
59
|
Default: `{model}/{name}.{type}.ts`
|
|
60
60
|
Possible tokens:
|
|
61
61
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
62
|
+
- `{model}` Model name in dashed case or 'prisma' if unknown
|
|
63
|
+
- `{name}` Dashed-case name of model/input/arg without suffix
|
|
64
|
+
- `{type}` Short type name (model, input, args, output)
|
|
65
|
+
- `{plural.type}` Plural short type name (models, inputs, enums)
|
|
66
66
|
|
|
67
67
|
#### `tsConfigFilePath`
|
|
68
68
|
|
|
@@ -149,30 +149,30 @@ generator nestgraphql {
|
|
|
149
149
|
|
|
150
150
|
Where:
|
|
151
151
|
|
|
152
|
-
-
|
|
153
|
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
- `typeName` Full name or partial name of the class where need to choose input type.
|
|
153
|
+
Example: `UserCreateInput` full name, `WhereInput` partial name, matches `UserWhereInput`, `PostWhereInput`, etc.
|
|
154
|
+
- `property` Property of the class for which need to choose type. Special case name `ALL` means any / all properties.
|
|
155
|
+
- `pattern` Part of name (or full) of type which should be chosen, you can use
|
|
156
|
+
wild card or negate symbols, in this case pattern should starts with `match:`,
|
|
157
|
+
e.g. `match:*UncheckedCreateInput` see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
158
158
|
|
|
159
159
|
Example:
|
|
160
160
|
|
|
161
161
|
```ts
|
|
162
162
|
export type PostWhereInput = {
|
|
163
|
-
|
|
163
|
+
author?: XOR<UserRelationFilter, UserWhereInput>;
|
|
164
164
|
};
|
|
165
165
|
export type UserRelationFilter = {
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
is?: UserWhereInput;
|
|
167
|
+
isNot?: UserWhereInput;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
export type UserWhereInput = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
AND?: Enumerable<UserWhereInput>;
|
|
172
|
+
OR?: Enumerable<UserWhereInput>;
|
|
173
|
+
NOT?: Enumerable<UserWhereInput>;
|
|
174
|
+
id?: StringFilter | string;
|
|
175
|
+
name?: StringFilter | string;
|
|
176
176
|
};
|
|
177
177
|
```
|
|
178
178
|
|
|
@@ -190,8 +190,8 @@ generator nestgraphql {
|
|
|
190
190
|
```ts
|
|
191
191
|
@InputType()
|
|
192
192
|
export class PostWhereInput {
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
@Field(() => UserWhereInput, { nullable: true })
|
|
194
|
+
author?: UserWhereInput;
|
|
195
195
|
}
|
|
196
196
|
```
|
|
197
197
|
|
|
@@ -214,24 +214,24 @@ generator nestgraphql {
|
|
|
214
214
|
|
|
215
215
|
Where `{key}` any identifier to group values (written in [flatten](https://github.com/hughsk/flat) style)
|
|
216
216
|
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
224
|
-
-
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
- `decorate_{key}_type` - outmatch pattern to match class name
|
|
218
|
+
- `decorate_{key}_field` - outmatch pattern to match field name
|
|
219
|
+
- `decorate_{key}_from` - module specifier to import from (e.g `class-validator`)
|
|
220
|
+
- `decorate_{key}_name` - import name or name with namespace
|
|
221
|
+
- `decorate_{key}_defaultImport` - import as default
|
|
222
|
+
- `decorate_{key}_namespaceImport` - use this name as import namespace
|
|
223
|
+
- `decorate_{key}_namedImport` - named import (without namespace)
|
|
224
|
+
- `decorate_{key}_arguments` - arguments for decorator (if decorator need to be called as function)
|
|
225
|
+
Special tokens can be used:
|
|
226
|
+
- `{propertyType.0}` - field's type (TypeScript type annotation)
|
|
227
227
|
|
|
228
228
|
Example of generated class:
|
|
229
229
|
|
|
230
230
|
```ts
|
|
231
231
|
@ArgsType()
|
|
232
232
|
export class CreateOneUserArgs {
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
@Field(() => UserCreateInput, { nullable: false })
|
|
234
|
+
data!: UserCreateInput;
|
|
235
235
|
}
|
|
236
236
|
```
|
|
237
237
|
|
|
@@ -259,10 +259,10 @@ import { Type } from 'class-transformer';
|
|
|
259
259
|
|
|
260
260
|
@ArgsType()
|
|
261
261
|
export class CreateOneUserArgs {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
@Field(() => UserCreateInput, { nullable: false })
|
|
263
|
+
@ValidateNested()
|
|
264
|
+
@Type(() => UserCreateInput)
|
|
265
|
+
data!: UserCreateInput;
|
|
266
266
|
}
|
|
267
267
|
```
|
|
268
268
|
|
|
@@ -329,13 +329,45 @@ May generate:
|
|
|
329
329
|
import { GraphQLBigInt } from 'graphql-scalars';
|
|
330
330
|
|
|
331
331
|
export class BigIntFilter {
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
@Field(() => GraphQLBigInt, { nullable: true })
|
|
333
|
+
equals?: bigint | number;
|
|
334
334
|
}
|
|
335
335
|
```
|
|
336
336
|
|
|
337
337
|
It will affect all inputs and outputs types (including models).
|
|
338
338
|
|
|
339
|
+
## Documentation and field options
|
|
340
|
+
|
|
341
|
+
Comments with double slash will projected to typescript code comments
|
|
342
|
+
and some `@Field()` decorator options
|
|
343
|
+
|
|
344
|
+
For example:
|
|
345
|
+
|
|
346
|
+
```prisma
|
|
347
|
+
model Product {
|
|
348
|
+
// Old description
|
|
349
|
+
// @deprecated Use new name instead
|
|
350
|
+
oldName
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
May produce:
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
@ObjectType()
|
|
358
|
+
export class Product {
|
|
359
|
+
/**
|
|
360
|
+
* Old description
|
|
361
|
+
* @deprecated Use new name instead
|
|
362
|
+
*/
|
|
363
|
+
@Field(() => String, {
|
|
364
|
+
description: 'Old description',
|
|
365
|
+
deprecationReason: 'Use new name instead',
|
|
366
|
+
})
|
|
367
|
+
oldName: string;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
339
371
|
## Field Settings
|
|
340
372
|
|
|
341
373
|
Special directives in triple slash comments for more precise code generation.
|
|
@@ -352,9 +384,9 @@ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
|
352
384
|
|
|
353
385
|
Examples:
|
|
354
386
|
|
|
355
|
-
-
|
|
356
|
-
-
|
|
357
|
-
-
|
|
387
|
+
- `@HideField()` same as `@HideField({ output: true })`
|
|
388
|
+
- `@HideField({ input: true, output: true })`
|
|
389
|
+
- `@HideField({ match: 'UserCreate*Input' })`
|
|
358
390
|
|
|
359
391
|
```prisma
|
|
360
392
|
model User {
|
|
@@ -373,24 +405,24 @@ May generate classes:
|
|
|
373
405
|
```ts
|
|
374
406
|
@ObjectType()
|
|
375
407
|
export class User {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
408
|
+
@HideField()
|
|
409
|
+
password: string;
|
|
410
|
+
@HideField()
|
|
411
|
+
secret: string;
|
|
412
|
+
@Field(() => Date, { nullable: false })
|
|
413
|
+
createdAt: Date;
|
|
382
414
|
}
|
|
383
415
|
```
|
|
384
416
|
|
|
385
417
|
```ts
|
|
386
418
|
@InputType()
|
|
387
419
|
export class UserCreateInput {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
420
|
+
@Field()
|
|
421
|
+
password: string;
|
|
422
|
+
@HideField()
|
|
423
|
+
secret: string;
|
|
424
|
+
@HideField()
|
|
425
|
+
createdAt: Date;
|
|
394
426
|
}
|
|
395
427
|
```
|
|
396
428
|
|
|
@@ -480,9 +512,9 @@ import * as Validator from 'class-validator';
|
|
|
480
512
|
|
|
481
513
|
@InputType()
|
|
482
514
|
export class UserCreateInput {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
515
|
+
@Field(() => String, { nullable: false })
|
|
516
|
+
@Validator.MinLength(3)
|
|
517
|
+
name!: string;
|
|
486
518
|
}
|
|
487
519
|
```
|
|
488
520
|
|
|
@@ -539,8 +571,8 @@ import * as Scalars from 'graphql-scalars';
|
|
|
539
571
|
|
|
540
572
|
@InputType()
|
|
541
573
|
export class UserCreateInput {
|
|
542
|
-
|
|
543
|
-
|
|
574
|
+
@Field(() => Scalars.GraphQLEmailAddress, { nullable: false })
|
|
575
|
+
email!: string;
|
|
544
576
|
}
|
|
545
577
|
```
|
|
546
578
|
|
|
@@ -602,8 +634,8 @@ import * as TF from 'type-fest';
|
|
|
602
634
|
|
|
603
635
|
@ObjectType()
|
|
604
636
|
export class User {
|
|
605
|
-
|
|
606
|
-
|
|
637
|
+
@Field(() => GraphQLJSON)
|
|
638
|
+
data!: TF.JsonObject;
|
|
607
639
|
}
|
|
608
640
|
```
|
|
609
641
|
|
|
@@ -629,9 +661,9 @@ May generate:
|
|
|
629
661
|
@Directive('@extends')
|
|
630
662
|
@Directive('@key(fields: "id")')
|
|
631
663
|
export class User {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
664
|
+
@Field(() => ID, { nullable: false })
|
|
665
|
+
@Directive('@external')
|
|
666
|
+
id!: string;
|
|
635
667
|
}
|
|
636
668
|
```
|
|
637
669
|
|
|
@@ -671,21 +703,21 @@ export class User {}
|
|
|
671
703
|
|
|
672
704
|
## Similar Projects
|
|
673
705
|
|
|
674
|
-
-
|
|
675
|
-
-
|
|
676
|
-
-
|
|
677
|
-
-
|
|
678
|
-
-
|
|
679
|
-
-
|
|
680
|
-
-
|
|
706
|
+
- https://github.com/kimjbstar/prisma-class-generator
|
|
707
|
+
- https://github.com/odroe/nest-gql-mix
|
|
708
|
+
- https://github.com/rfermann/nestjs-prisma-graphql-generator
|
|
709
|
+
- https://github.com/madscience/graphql-codegen-nestjs
|
|
710
|
+
- https://github.com/wSedlacek/prisma-generators/tree/master/libs/nestjs
|
|
711
|
+
- https://github.com/EndyKaufman/typegraphql-prisma-nestjs
|
|
712
|
+
- https://github.com/MichalLytek/typegraphql-prisma
|
|
681
713
|
|
|
682
714
|
## Resources
|
|
683
715
|
|
|
684
|
-
-
|
|
685
|
-
-
|
|
686
|
-
-
|
|
687
|
-
-
|
|
688
|
-
-
|
|
689
|
-
-
|
|
690
|
-
-
|
|
691
|
-
-
|
|
716
|
+
- Todo - https://github.com/unlight/prisma-nestjs-graphql/issues/2
|
|
717
|
+
- https://github.com/prisma/prisma/blob/main/packages/client/src/generation/TSClient/TSClient.ts
|
|
718
|
+
- https://ts-ast-viewer.com/
|
|
719
|
+
- https://github.com/unlight/nestjs-graphql-prisma-realworld-example-app
|
|
720
|
+
- https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/data-model
|
|
721
|
+
- JSON type for the code first approach - https://github.com/nestjs/graphql/issues/111#issuecomment-631452899
|
|
722
|
+
- https://github.com/paljs/prisma-tools/tree/master/packages/plugins
|
|
723
|
+
- https://github.com/wasp-lang/wasp
|
package/index.js
CHANGED
|
@@ -749,6 +749,7 @@ function inputType(args) {
|
|
|
749
749
|
arguments: [
|
|
750
750
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
751
751
|
import_json5.default.stringify({
|
|
752
|
+
...settings == null ? void 0 : settings.fieldArguments(),
|
|
752
753
|
nullable: !isRequired
|
|
753
754
|
})
|
|
754
755
|
]
|
|
@@ -849,81 +850,126 @@ var ObjectSettings = class extends Array {
|
|
|
849
850
|
}
|
|
850
851
|
return resultArguments.map((x) => import_json52.default.stringify(x));
|
|
851
852
|
}
|
|
853
|
+
fieldArguments() {
|
|
854
|
+
const item1 = this.find((item) => item.kind === "Field");
|
|
855
|
+
if (item1) {
|
|
856
|
+
return item1.arguments;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
852
859
|
};
|
|
853
860
|
__name(ObjectSettings, "ObjectSettings");
|
|
854
861
|
function createObjectSettings(args) {
|
|
855
|
-
var _a, _b, _c, _d, _e;
|
|
856
862
|
const { config, text } = args;
|
|
857
863
|
const result = new ObjectSettings();
|
|
858
864
|
const textLines = text.split("\n");
|
|
859
865
|
const documentationLines = [];
|
|
866
|
+
let fieldElement = result.find((item) => item.kind === "Field");
|
|
867
|
+
if (!fieldElement) {
|
|
868
|
+
fieldElement = {
|
|
869
|
+
name: "",
|
|
870
|
+
kind: "Field",
|
|
871
|
+
arguments: {}
|
|
872
|
+
};
|
|
873
|
+
}
|
|
860
874
|
for (const line of textLines) {
|
|
861
875
|
const match = /^@(?<name>\w+(\.(\w+))?)\((?<args>.*)\)/.exec(line);
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
876
|
+
const { element, documentLine } = createSettingElement({
|
|
877
|
+
line,
|
|
878
|
+
config,
|
|
879
|
+
fieldElement,
|
|
880
|
+
match
|
|
881
|
+
});
|
|
882
|
+
if (element) {
|
|
883
|
+
result.push(element);
|
|
866
884
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
name: "",
|
|
870
|
-
arguments: [],
|
|
871
|
-
input: false,
|
|
872
|
-
output: false,
|
|
873
|
-
model: false,
|
|
874
|
-
from: ""
|
|
875
|
-
};
|
|
876
|
-
if (name === "TypeGraphQL.omit" || name === "HideField") {
|
|
877
|
-
Object.assign(element, hideFieldDecorator(match));
|
|
878
|
-
} else if ([
|
|
879
|
-
"FieldType",
|
|
880
|
-
"PropertyType"
|
|
881
|
-
].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
|
|
882
|
-
const options = customType(match.groups.args);
|
|
883
|
-
(0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, {
|
|
884
|
-
kind: name
|
|
885
|
-
});
|
|
886
|
-
} else if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
|
|
887
|
-
element.kind = "ObjectType";
|
|
888
|
-
const options = customType(match.groups.args);
|
|
889
|
-
if (typeof options[0] === "string" && options[0]) {
|
|
890
|
-
options.name = options[0];
|
|
891
|
-
}
|
|
892
|
-
if ((0, import_lodash4.isObject)(options[1])) {
|
|
893
|
-
(0, import_lodash4.merge)(options, options[1]);
|
|
894
|
-
}
|
|
895
|
-
element.arguments = {
|
|
896
|
-
name: options.name,
|
|
897
|
-
isAbstract: options.isAbstract
|
|
898
|
-
};
|
|
899
|
-
} else if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
|
|
900
|
-
const options = customType(match.groups.args);
|
|
901
|
-
(0, import_lodash4.merge)(element, {
|
|
902
|
-
model: true,
|
|
903
|
-
from: "@nestjs/graphql"
|
|
904
|
-
}, options, {
|
|
905
|
-
name,
|
|
906
|
-
namespace: false,
|
|
907
|
-
kind: "Decorator",
|
|
908
|
-
arguments: Array.isArray(options.arguments) ? options.arguments.map((s) => import_json52.default.stringify(s)) : options.arguments
|
|
909
|
-
});
|
|
910
|
-
} else {
|
|
911
|
-
const namespace = getNamespace(name);
|
|
912
|
-
element.namespaceImport = namespace;
|
|
913
|
-
const options = {
|
|
914
|
-
name,
|
|
915
|
-
arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
|
|
916
|
-
};
|
|
917
|
-
(0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
|
|
885
|
+
if (documentLine) {
|
|
886
|
+
documentationLines.push(line);
|
|
918
887
|
}
|
|
919
|
-
result.push(element);
|
|
920
888
|
}
|
|
921
889
|
return {
|
|
922
890
|
settings: result,
|
|
923
|
-
documentation: documentationLines.filter(Boolean).join("
|
|
891
|
+
documentation: documentationLines.filter(Boolean).join("\n") || void 0
|
|
924
892
|
};
|
|
925
893
|
}
|
|
926
894
|
__name(createObjectSettings, "createObjectSettings");
|
|
895
|
+
function createSettingElement({ line, config, fieldElement, match }) {
|
|
896
|
+
var _a, _b, _c, _d, _e;
|
|
897
|
+
const result = {
|
|
898
|
+
documentLine: "",
|
|
899
|
+
element: void 0
|
|
900
|
+
};
|
|
901
|
+
if (line.startsWith("@deprecated")) {
|
|
902
|
+
fieldElement.arguments["deprecationReason"] = (0, import_lodash4.trim)(line.slice(11));
|
|
903
|
+
result.element = fieldElement;
|
|
904
|
+
return result;
|
|
905
|
+
}
|
|
906
|
+
const name = (_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.name;
|
|
907
|
+
if (!(match && name)) {
|
|
908
|
+
result.documentLine = line;
|
|
909
|
+
return result;
|
|
910
|
+
}
|
|
911
|
+
const element = {
|
|
912
|
+
kind: "Decorator",
|
|
913
|
+
name: "",
|
|
914
|
+
arguments: [],
|
|
915
|
+
input: false,
|
|
916
|
+
output: false,
|
|
917
|
+
model: false,
|
|
918
|
+
from: ""
|
|
919
|
+
};
|
|
920
|
+
result.element = element;
|
|
921
|
+
if (name === "TypeGraphQL.omit" || name === "HideField") {
|
|
922
|
+
Object.assign(element, hideFieldDecorator(match));
|
|
923
|
+
return result;
|
|
924
|
+
}
|
|
925
|
+
if ([
|
|
926
|
+
"FieldType",
|
|
927
|
+
"PropertyType"
|
|
928
|
+
].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
|
|
929
|
+
const options2 = customType(match.groups.args);
|
|
930
|
+
(0, import_lodash4.merge)(element, options2.namespace && config.fields[options2.namespace], options2, {
|
|
931
|
+
kind: name
|
|
932
|
+
});
|
|
933
|
+
return result;
|
|
934
|
+
}
|
|
935
|
+
if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
|
|
936
|
+
element.kind = "ObjectType";
|
|
937
|
+
const options2 = customType(match.groups.args);
|
|
938
|
+
if (typeof options2[0] === "string" && options2[0]) {
|
|
939
|
+
options2.name = options2[0];
|
|
940
|
+
}
|
|
941
|
+
if ((0, import_lodash4.isObject)(options2[1])) {
|
|
942
|
+
(0, import_lodash4.merge)(options2, options2[1]);
|
|
943
|
+
}
|
|
944
|
+
element.arguments = {
|
|
945
|
+
name: options2.name,
|
|
946
|
+
isAbstract: options2.isAbstract
|
|
947
|
+
};
|
|
948
|
+
return result;
|
|
949
|
+
}
|
|
950
|
+
if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
|
|
951
|
+
const options2 = customType(match.groups.args);
|
|
952
|
+
(0, import_lodash4.merge)(element, {
|
|
953
|
+
model: true,
|
|
954
|
+
from: "@nestjs/graphql"
|
|
955
|
+
}, options2, {
|
|
956
|
+
name,
|
|
957
|
+
namespace: false,
|
|
958
|
+
kind: "Decorator",
|
|
959
|
+
arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => import_json52.default.stringify(s)) : options2.arguments
|
|
960
|
+
});
|
|
961
|
+
return result;
|
|
962
|
+
}
|
|
963
|
+
const namespace = getNamespace(name);
|
|
964
|
+
element.namespaceImport = namespace;
|
|
965
|
+
const options = {
|
|
966
|
+
name,
|
|
967
|
+
arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
|
|
968
|
+
};
|
|
969
|
+
(0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
|
|
970
|
+
return result;
|
|
971
|
+
}
|
|
972
|
+
__name(createSettingElement, "createSettingElement");
|
|
927
973
|
function customType(args) {
|
|
928
974
|
var _a;
|
|
929
975
|
const result = {};
|
|
@@ -1035,6 +1081,25 @@ var import_lodash5 = require("lodash");
|
|
|
1035
1081
|
var import_pupa2 = __toESM(require("pupa"));
|
|
1036
1082
|
var import_ts_morph5 = require("ts-morph");
|
|
1037
1083
|
|
|
1084
|
+
// src/helpers/create-comment.ts
|
|
1085
|
+
function createComment(documentation, settings) {
|
|
1086
|
+
var _a;
|
|
1087
|
+
const documentationLines = documentation.split("\n");
|
|
1088
|
+
const commentLines = [
|
|
1089
|
+
"/**"
|
|
1090
|
+
];
|
|
1091
|
+
for (const line of documentationLines) {
|
|
1092
|
+
commentLines.push(` * ${line}`);
|
|
1093
|
+
}
|
|
1094
|
+
const deprecationReason = (_a = settings == null ? void 0 : settings.fieldArguments()) == null ? void 0 : _a.deprecationReason;
|
|
1095
|
+
if (deprecationReason) {
|
|
1096
|
+
commentLines.push(` * @deprecated ${deprecationReason}`);
|
|
1097
|
+
}
|
|
1098
|
+
commentLines.push(" */\n");
|
|
1099
|
+
return commentLines.join("\n");
|
|
1100
|
+
}
|
|
1101
|
+
__name(createComment, "createComment");
|
|
1102
|
+
|
|
1038
1103
|
// src/helpers/get-output-type-name.ts
|
|
1039
1104
|
function getOutputTypeName(name) {
|
|
1040
1105
|
return name.replace(/(?:OutputType|Output)$/, "");
|
|
@@ -1080,8 +1145,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1080
1145
|
});
|
|
1081
1146
|
if (documentation) {
|
|
1082
1147
|
if (!classStructure.leadingTrivia) {
|
|
1083
|
-
classStructure.leadingTrivia =
|
|
1084
|
-
`;
|
|
1148
|
+
classStructure.leadingTrivia = createComment(documentation);
|
|
1085
1149
|
}
|
|
1086
1150
|
objectTypeOptions.description = documentation;
|
|
1087
1151
|
}
|
|
@@ -1147,15 +1211,14 @@ function modelOutputType(outputType2, args) {
|
|
|
1147
1211
|
isList
|
|
1148
1212
|
});
|
|
1149
1213
|
if (typeof property.leadingTrivia === "string" && (modelField == null ? void 0 : modelField.documentation)) {
|
|
1150
|
-
property.leadingTrivia +=
|
|
1151
|
-
`;
|
|
1214
|
+
property.leadingTrivia += createComment(modelField.documentation, settings);
|
|
1152
1215
|
}
|
|
1153
1216
|
(_c = classStructure.properties) == null ? void 0 : _c.push(property);
|
|
1154
1217
|
if (propertySettings) {
|
|
1155
1218
|
importDeclarations.create({
|
|
1156
1219
|
...propertySettings
|
|
1157
1220
|
});
|
|
1158
|
-
} else if (
|
|
1221
|
+
} else if (propertyType.includes("Decimal")) {
|
|
1159
1222
|
importDeclarations.add("Decimal", "@prisma/client/runtime");
|
|
1160
1223
|
}
|
|
1161
1224
|
(0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
|
|
@@ -1174,6 +1237,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1174
1237
|
arguments: [
|
|
1175
1238
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1176
1239
|
import_json53.default.stringify({
|
|
1240
|
+
...settings == null ? void 0 : settings.fieldArguments(),
|
|
1177
1241
|
nullable: Boolean(field.isNullable),
|
|
1178
1242
|
defaultValue: [
|
|
1179
1243
|
"number",
|
|
@@ -1413,6 +1477,7 @@ function outputType(outputType1, args) {
|
|
|
1413
1477
|
arguments: [
|
|
1414
1478
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1415
1479
|
import_json54.default.stringify({
|
|
1480
|
+
...settings == null ? void 0 : settings.fieldArguments(),
|
|
1416
1481
|
nullable: Boolean(field.isNullable)
|
|
1417
1482
|
})
|
|
1418
1483
|
]
|
package/package.json
CHANGED