Fixes Prisma array expr for empty arrays (#2249)

This commit is contained in:
Mihovil Ilakovac 2024-08-26 14:03:40 +02:00 committed by GitHub
parent eb5f6703fc
commit 0aabddaa75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 3 deletions

View File

@ -18,7 +18,6 @@ import Wasp.Psl.Parser.Common
( brackets,
colon,
commaSep,
commaSep1,
float,
identifier,
integer,
@ -69,7 +68,7 @@ funcCallExpr =
arrayExpr :: Parser Psl.Argument.Expression
arrayExpr =
Psl.Argument.ArrayExpr
<$> brackets (commaSep1 expression)
<$> brackets (commaSep expression)
-- NOTE: For now we are not supporting negative numbers.
-- I couldn't figure out from Prisma docs if there could be the case

View File

@ -15,6 +15,7 @@ sampleBodySchema =
posts Post[] @relation("UserPosts", references: [id]) @customattr
weirdType Unsupported("weird")
anotherId String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
someField String[] @default([])
@@someattr([id, username], [posts])
|]
@ -114,6 +115,20 @@ sampleBodyAst =
]
}
),
Psl.Model.ElementField
( Psl.Model.Field
{ Psl.Model._name = "someField",
Psl.Model._type = Psl.Model.String,
Psl.Model._typeModifiers = [Psl.Model.List],
Psl.Model._attrs =
[ Psl.Attribute.Attribute
{ Psl.Attribute._attrName = "default",
Psl.Attribute._attrArgs =
[Psl.Argument.ArgUnnamed (Psl.Argument.ArrayExpr [])]
}
]
}
),
Psl.Model.ElementBlockAttribute
( Psl.Attribute.Attribute
{ Psl.Attribute._attrName = "someattr",

View File

@ -36,6 +36,9 @@ spec_parseArgumentPslPart = do
Psl.Argument.IdentifierExpr "pg_trgm",
Psl.Argument.FuncExpr "postgis" [Psl.Argument.ArgNamed "version" (Psl.Argument.StringExpr "2.1")]
]
),
( "[]",
Psl.Argument.ArgUnnamed (Psl.Argument.ArrayExpr [])
)
]
let runTest (psl, expected) =

View File

@ -53,6 +53,12 @@ spec_parseAttributePslPart = do
]
)
]
),
( "@default([])",
Psl.Attribute.Attribute
"default"
[ Psl.Argument.ArgUnnamed $ Psl.Argument.ArrayExpr []
]
)
]
runTestsFor attribute tests

View File

@ -63,6 +63,7 @@ spec_parsePslSchema = do
user User @relation(fields: [userId], references: [id])
userId Int
votes TaskVote[]
someField String[] @default([])
}
model TaskVote {
@ -230,7 +231,16 @@ spec_parsePslSchema = do
"votes"
(Psl.Model.UserType "TaskVote")
[Psl.Model.List]
[]
[],
Psl.Model.ElementField $
Psl.Model.Field
"someField"
Psl.Model.String
[Psl.Model.List]
[ Psl.Attribute.Attribute
"default"
[Psl.Argument.ArgUnnamed $ Psl.Argument.ArrayExpr []]
]
]
),
Psl.Schema.ModelBlock $