Skip to content

Commit

Permalink
Fixes Prisma array expr for empty arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Mihovil Ilakovac <[email protected]>
  • Loading branch information
infomiho committed Aug 23, 2024
1 parent 6ca8446 commit d174f47
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
3 changes: 1 addition & 2 deletions waspc/src/Wasp/Psl/Parser/Argument.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Wasp.Psl.Parser.Common
( brackets,
colon,
commaSep,
commaSep1,
float,
identifier,
integer,
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions waspc/test/Psl/Common/ModelTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
|]
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions waspc/test/Psl/Parser/ArgumentTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
6 changes: 6 additions & 0 deletions waspc/test/Psl/Parser/AttributeTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ spec_parseAttributePslPart = do
]
)
]
),
( "@default([])",
Psl.Attribute.Attribute
"default"
[ Psl.Argument.ArgUnnamed $ Psl.Argument.ArrayExpr []
]
)
]
runTestsFor attribute tests
Expand Down
12 changes: 11 additions & 1 deletion waspc/test/Psl/Parser/SchemaTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ spec_parsePslSchema = do
user User @relation(fields: [userId], references: [id])
userId Int
votes TaskVote[]
someField String[] @default([])
}

model TaskVote {
Expand Down Expand Up @@ -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 $
Expand Down

0 comments on commit d174f47

Please sign in to comment.