Skip to content

Commit fc2cd18

Browse files
committed
Fix handling multiple attribute comments on a single field
1 parent a86cef5 commit fc2cd18

12 files changed

Lines changed: 121 additions & 54 deletions

File tree

experiments/postgres/prisma/generated/client/edge.js

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

experiments/postgres/prisma/generated/client/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,6 +3223,7 @@ export namespace Prisma {
32233223
updatedAt: Date
32243224
/**
32253225
* @TypeGraphQL.omit(input: true)
3226+
* @TypeGraphQL.field(name: "isPublished")
32263227
*/
32273228
published: boolean
32283229
title: string

experiments/postgres/prisma/generated/client/index.js

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

experiments/postgres/prisma/generated/client/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ model post {
7272
/// @TypeGraphQL.omit(input: ["create", "update"])
7373
updatedAt DateTime @updatedAt
7474
/// @TypeGraphQL.omit(input: true)
75+
/// @TypeGraphQL.field(name: "isPublished")
7576
published Boolean @default(false)
7677
title String
7778
/// @TypeGraphQL.omit(output: true)

experiments/postgres/prisma/generated/type-graphql/dmmf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
"default": false,
268268
"isGenerated": false,
269269
"isUpdatedAt": false,
270-
"documentation": "@TypeGraphQL.omit(input: true)"
270+
"documentation": "@TypeGraphQL.omit(input: true)\n@TypeGraphQL.field(name: \"isPublished\")"
271271
},
272272
{
273273
"name": "title",

experiments/postgres/prisma/generated/type-graphql/enhance.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ function applyTypeClassEnhanceConfig<
562562

563563
const modelsInfo = {
564564
MainUser: ["id", "email", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases"],
565-
Post: ["uuid", "createdAt", "updatedAt", "published", "title", "content", "authorId", "kind", "metadata"],
565+
Post: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "content", "authorId", "kind", "metadata"],
566566
Category: ["name", "slug", "number"],
567567
Patient: ["firstName", "lastName", "email"],
568568
Movie: ["directorFirstName", "directorLastName", "title"],
@@ -727,11 +727,11 @@ const inputsInfo = {
727727
MainUserWhereUniqueInput: ["id", "email", "AND", "OR", "NOT", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases", "clientPosts", "editorPosts"],
728728
MainUserOrderByWithAggregationInput: ["id", "email", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases", "_count", "_avg", "_max", "_min", "_sum"],
729729
MainUserScalarWhereWithAggregatesInput: ["AND", "OR", "NOT", "id", "email", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases"],
730-
PostWhereInput: ["AND", "OR", "NOT", "uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "author", "editor"],
731-
PostOrderByWithRelationAndSearchRelevanceInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "author", "editor", "_relevance"],
732-
PostWhereUniqueInput: ["uuid", "AND", "OR", "NOT", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "author", "editor"],
733-
PostOrderByWithAggregationInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "_count", "_avg", "_max", "_min", "_sum"],
734-
PostScalarWhereWithAggregatesInput: ["AND", "OR", "NOT", "uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
730+
PostWhereInput: ["AND", "OR", "NOT", "uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "author", "editor"],
731+
PostOrderByWithRelationAndSearchRelevanceInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "author", "editor", "_relevance"],
732+
PostWhereUniqueInput: ["uuid", "AND", "OR", "NOT", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "author", "editor"],
733+
PostOrderByWithAggregationInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata", "_count", "_avg", "_max", "_min", "_sum"],
734+
PostScalarWhereWithAggregatesInput: ["AND", "OR", "NOT", "uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
735735
CategoryWhereInput: ["AND", "OR", "NOT", "name", "slug", "number"],
736736
CategoryOrderByWithRelationAndSearchRelevanceInput: ["name", "slug", "number", "_relevance"],
737737
CategoryWhereUniqueInput: ["categoryCompoundUnique", "AND", "OR", "NOT", "name", "slug", "number"],
@@ -781,10 +781,10 @@ const inputsInfo = {
781781
MainUserUpdateInput: ["email", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases", "clientPosts", "editorPosts"],
782782
MainUserCreateManyInput: ["id", "email", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases"],
783783
MainUserUpdateManyMutationInput: ["email", "firstName", "age", "accountBalance", "amount", "role", "grades", "aliases"],
784-
PostCreateInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata", "author", "editor"],
785-
PostUpdateInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata", "author", "editor"],
786-
PostCreateManyInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
787-
PostUpdateManyMutationInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata"],
784+
PostCreateInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata", "author", "editor"],
785+
PostUpdateInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata", "author", "editor"],
786+
PostCreateManyInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
787+
PostUpdateManyMutationInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata"],
788788
CategoryCreateInput: ["name", "slug", "number"],
789789
CategoryUpdateInput: ["name", "slug", "number"],
790790
CategoryCreateManyInput: ["name", "slug", "number"],
@@ -850,10 +850,10 @@ const inputsInfo = {
850850
MainUserRelationFilter: ["is", "isNot"],
851851
UserNullableRelationFilter: ["is", "isNot"],
852852
PostOrderByRelevanceInput: ["fields", "sort", "search"],
853-
PostCountOrderByAggregateInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
853+
PostCountOrderByAggregateInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
854854
PostAvgOrderByAggregateInput: ["authorId", "editorId"],
855-
PostMaxOrderByAggregateInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind"],
856-
PostMinOrderByAggregateInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind"],
855+
PostMaxOrderByAggregateInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind"],
856+
PostMinOrderByAggregateInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind"],
857857
PostSumOrderByAggregateInput: ["authorId", "editorId"],
858858
DateTimeWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "_count", "_min", "_max"],
859859
BoolWithAggregatesFilter: ["equals", "not", "_count", "_min", "_max"],
@@ -983,16 +983,16 @@ const inputsInfo = {
983983
NestedBigIntNullableWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "_count", "_avg", "_sum", "_min", "_max"],
984984
NestedBytesNullableWithAggregatesFilter: ["equals", "in", "notIn", "not", "_count", "_min", "_max"],
985985
NestedDecimalNullableWithAggregatesFilter: ["equals", "in", "notIn", "lt", "lte", "gt", "gte", "not", "_count", "_avg", "_sum", "_min", "_max"],
986-
PostCreateWithoutAuthorInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata", "editor"],
986+
PostCreateWithoutAuthorInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata", "editor"],
987987
PostCreateOrConnectWithoutAuthorInput: ["where", "create"],
988988
PostCreateManyAuthorInputEnvelope: ["data", "skipDuplicates"],
989-
PostCreateWithoutEditorInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata", "author"],
989+
PostCreateWithoutEditorInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata", "author"],
990990
PostCreateOrConnectWithoutEditorInput: ["where", "create"],
991991
PostCreateManyEditorInputEnvelope: ["data", "skipDuplicates"],
992992
PostUpsertWithWhereUniqueWithoutAuthorInput: ["where", "update", "create"],
993993
PostUpdateWithWhereUniqueWithoutAuthorInput: ["where", "data"],
994994
PostUpdateManyWithWhereWithoutAuthorInput: ["where", "data"],
995-
PostScalarWhereInput: ["AND", "OR", "NOT", "uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
995+
PostScalarWhereInput: ["AND", "OR", "NOT", "uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "editorId", "kind", "metadata"],
996996
PostUpsertWithWhereUniqueWithoutEditorInput: ["where", "update", "create"],
997997
PostUpdateWithWhereUniqueWithoutEditorInput: ["where", "data"],
998998
PostUpdateManyWithWhereWithoutEditorInput: ["where", "data"],
@@ -1041,10 +1041,10 @@ const inputsInfo = {
10411041
ProblemUpsertWithWhereUniqueWithoutCreatorInput: ["where", "update", "create"],
10421042
ProblemUpdateWithWhereUniqueWithoutCreatorInput: ["where", "data"],
10431043
ProblemUpdateManyWithWhereWithoutCreatorInput: ["where", "data"],
1044-
PostCreateManyAuthorInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "editorId", "kind", "metadata"],
1045-
PostCreateManyEditorInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "authorId", "kind", "metadata"],
1046-
PostUpdateWithoutAuthorInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata", "editor"],
1047-
PostUpdateWithoutEditorInput: ["uuid", "createdAt", "updatedAt", "published", "title", "subtitle", "content", "kind", "metadata", "author"],
1044+
PostCreateManyAuthorInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "editorId", "kind", "metadata"],
1045+
PostCreateManyEditorInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "authorId", "kind", "metadata"],
1046+
PostUpdateWithoutAuthorInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata", "editor"],
1047+
PostUpdateWithoutEditorInput: ["uuid", "createdAt", "updatedAt", "isPublished", "title", "subtitle", "content", "kind", "metadata", "author"],
10481048
MovieCreateManyDirectorInput: ["title"],
10491049
MovieUpdateWithoutDirectorInput: ["title"],
10501050
CreatorUpdateWithoutLikesInput: ["name", "problems"],

experiments/postgres/prisma/generated/type-graphql/models/Post.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export class Post {
2828
})
2929
updatedAt!: Date;
3030

31-
@TypeGraphQL.Field(_type => Boolean, {
32-
nullable: false
33-
})
3431
published!: boolean;
3532

3633
@TypeGraphQL.Field(_type => String, {
@@ -65,4 +62,11 @@ export class Post {
6562
nullable: false
6663
})
6764
metadata!: Prisma.JsonValue;
65+
66+
@TypeGraphQL.Field(_type => Boolean, {
67+
nullable: false
68+
})
69+
get isPublished(): boolean {
70+
return this.published;
71+
}
6872
}

experiments/postgres/prisma/generated/type-graphql/prisma-client-dmmf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
"default": false,
268268
"isGenerated": false,
269269
"isUpdatedAt": false,
270-
"documentation": "@TypeGraphQL.omit(input: true)"
270+
"documentation": "@TypeGraphQL.omit(input: true)\n@TypeGraphQL.field(name: \"isPublished\")"
271271
},
272272
{
273273
"name": "title",

experiments/postgres/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ model post {
7272
/// @TypeGraphQL.omit(input: ["create", "update"])
7373
updatedAt DateTime @updatedAt
7474
/// @TypeGraphQL.omit(input: true)
75+
/// @TypeGraphQL.field(name: "isPublished")
7576
published Boolean @default(false)
7677
title String
7778
/// @TypeGraphQL.omit(output: true)

src/generator/dmmf/helpers.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export const modelAttributeRegex = /(@@TypeGraphQL\.)+([A-z])+(\()+(.+)+(\))+/;
2-
export const fieldAttributeRegex = /(@TypeGraphQL\.)+([A-z])+(\()+(.+)+(\))+/;
1+
export const modelAttributeRegex = /(@@TypeGraphQL\.)+([A-z])+(\()+(.+)+(\))+/g;
2+
export const fieldAttributeRegex = /(@TypeGraphQL\.)+([A-z])+(\()+(.+)+(\))+/g;
33
export const attributeNameRegex = /(?:\.)+([A-Za-z])+(?:\()+/;
44
export const attributeArgsRegex = /(?:\()+([A-Za-z])+\:+(.+)+(?:\))+/;
55

@@ -12,28 +12,35 @@ export function parseDocumentationAttributes<TData extends object = object>(
1212
expectedAttributeKind === "model"
1313
? modelAttributeRegex
1414
: fieldAttributeRegex;
15-
const attribute = documentation?.match(attributeRegex)?.[0];
16-
const attributeName = attribute?.match(attributeNameRegex)?.[0]?.slice(1, -1);
17-
if (attributeName !== expectedAttributeName) {
18-
return {};
19-
}
20-
const rawAttributeArgs = attribute
21-
?.match(attributeArgsRegex)?.[0]
22-
?.slice(1, -1);
23-
const parsedAttributeArgs: Record<string, unknown> = {};
24-
if (rawAttributeArgs) {
25-
const rawAttributeArgsParts = rawAttributeArgs
26-
.split(":")
27-
.map(it => it.trim())
28-
.map(part => (part.startsWith("[") ? part : part.split(",")))
29-
.flat()
30-
.map(it => it.trim());
15+
const matchResults = documentation?.matchAll(attributeRegex) ?? [];
16+
17+
for (const [attribute] of matchResults) {
18+
const attributeName = attribute
19+
?.match(attributeNameRegex)?.[0]
20+
?.slice(1, -1);
21+
if (attributeName !== expectedAttributeName) {
22+
continue;
23+
}
24+
const rawAttributeArgs = attribute
25+
?.match(attributeArgsRegex)?.[0]
26+
?.slice(1, -1);
27+
const parsedAttributeArgs: Record<string, unknown> = {};
28+
if (rawAttributeArgs) {
29+
const rawAttributeArgsParts = rawAttributeArgs
30+
.split(":")
31+
.map(it => it.trim())
32+
.map(part => (part.startsWith("[") ? part : part.split(",")))
33+
.flat()
34+
.map(it => it.trim());
3135

32-
for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {
33-
const key = rawAttributeArgsParts[i];
34-
const value = rawAttributeArgsParts[i + 1];
35-
parsedAttributeArgs[key] = JSON.parse(value);
36+
for (let i = 0; i < rawAttributeArgsParts.length; i += 2) {
37+
const key = rawAttributeArgsParts[i];
38+
const value = rawAttributeArgsParts[i + 1];
39+
parsedAttributeArgs[key] = JSON.parse(value);
40+
}
3641
}
42+
return parsedAttributeArgs as Partial<TData>;
3743
}
38-
return parsedAttributeArgs as Partial<TData>;
44+
45+
return {};
3946
}

0 commit comments

Comments
 (0)