Skip to content

Commit

Permalink
use multiwayif instead of nested if-else
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkarthik committed Aug 21, 2020
1 parent d4e2955 commit 22d563c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions server/src-lib/Hasura/RQL/DDL/RemoteRelationship/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,13 @@ isTypeCoercible actualType expectedType =
let (actualBaseType, actualNestingLevel) = getBaseTyWithNestedLevelsCount actualType
(expectedBaseType, expectedNestingLevel) = getBaseTyWithNestedLevelsCount expectedType
in
if actualBaseType == expectedBaseType
then if (actualNestingLevel == expectedNestingLevel || actualNestingLevel == 0)
-- The check of 'actualNestedCount == 0' is the case of coercing a singleton type
-- into an array type
then pure ()
else Failure (pure $ ExpectedTypeButGot expectedType actualType)
-- we cannot coerce two types with different nesting levels,
if | actualBaseType /= expectedBaseType -> raiseValidationError
-- we cannot coerce two types with different nesting levels,
-- for example, we cannot coerce [Int] to [[Int]]
else Failure (pure $ ExpectedTypeButGot expectedType actualType)
| (actualNestingLevel == expectedNestingLevel || actualNestingLevel == 0) -> pure ()
| otherwise -> raiseValidationError
where
raiseValidationError = Failure (pure $ ExpectedTypeButGot expectedType actualType)

assertListType :: G.GType -> Validation (NonEmpty ValidationError) ()
assertListType actualType =
Expand Down

0 comments on commit 22d563c

Please sign in to comment.