-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation for @default attribute on userEntity #2311
Conversation
@@ -54,18 +52,15 @@ getPslModelBody = pslModelBody | |||
getIdField :: Entity -> Maybe Psl.Model.Field | |||
getIdField = findIdField . getPslModelBody | |||
|
|||
isFieldUnique :: String -> Entity -> Maybe Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was unused.
waspc/src/Wasp/AppSpec/Valid.hs
Outdated
[ GenericValidationError $ "Entity '" ++ userEntityName ++ "' (referenced by app.auth.userEntity) must have an ID field (specified with the '@id' attribute)" | ||
| isNothing idFieldType | ||
] | ||
concat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP: I'll rewrite this to be nicer
b581339
to
b43e4ad
Compare
b43e4ad
to
1c3e228
Compare
isFieldUnique :: String -> Entity -> Maybe Bool | ||
isFieldUnique fieldName = doesFieldHaveAttribute fieldName "unique" | ||
|
||
doesFieldHaveAttribute :: String -> String -> Entity -> Maybe Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a weirdly specific function which I tried to rewrite but in the end it was easier just to use the lower level helper doesPslFieldHaveAttribute
directly in the one place where we needed to check if a field has an attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Left one tiny comment.
case Entity.getIdField userEntity of | ||
Nothing -> [userEntityMissingIdFieldError] | ||
Just idField -> | ||
if Psl.Util.doesPslFieldHaveAttribute "default" idField | ||
then [] | ||
else [userEntityIdFieldMissingDefaultAttrError] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Might be tempting to use Either here as a monad? Btw there is even this thing: https://hackage.haskell.org/package/validation .
But probably just not to complicate, it is simple enough for now, I am writing this just to give ideas for the future!
Closes #2308