mirror of
https://github.com/hasura/graphql-engine.git
synced 2025-01-05 22:34:22 +03:00
Apply HLint's new proposed fixes.
Upgrading HLint brought in a bunch of new suggestions for improvements to the code. I thought I'd go through them quickly and get them in. This is not all of them, just the ones I thought were reasonable. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10505 GitOrigin-RevId: cefd661e9dcb973843b421fd0e31a5c5ffe4720f
This commit is contained in:
parent
94f01cfbb0
commit
ae5279ccda
@ -41,6 +41,8 @@ import Hasura.Backends.DataConnector.API qualified as API
|
|||||||
import Hasura.Prelude
|
import Hasura.Prelude
|
||||||
import Test.Hspec (SpecWith, describe, it, pendingWith)
|
import Test.Hspec (SpecWith, describe, it, pendingWith)
|
||||||
|
|
||||||
|
{-# ANN module ("HLint: ignore Functor law" :: String) #-}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- DataConnector Agent Query Tests
|
-- DataConnector Agent Query Tests
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ createInsertPermissions testEnvironment server =
|
|||||||
{ insertPermissionTable = "user",
|
{ insertPermissionTable = "user",
|
||||||
insertPermissionRole = "user_1",
|
insertPermissionRole = "user_1",
|
||||||
insertPermissionColumns = (["id", "name", "email", "phone_number"] :: [Text]),
|
insertPermissionColumns = (["id", "name", "email", "phone_number"] :: [Text]),
|
||||||
insertPermissionValidationWebhook = Just $ (T.pack $ serverUrl server) <> "/validateUser"
|
insertPermissionValidationWebhook = Just $ T.pack (serverUrl server) <> "/validateUser"
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphqlEngine.postMetadata_ testEnvironment
|
GraphqlEngine.postMetadata_ testEnvironment
|
||||||
@ -104,7 +104,7 @@ createInsertPermissions testEnvironment server =
|
|||||||
{ insertPermissionTable = "tweet",
|
{ insertPermissionTable = "tweet",
|
||||||
insertPermissionRole = "user_1",
|
insertPermissionRole = "user_1",
|
||||||
insertPermissionColumns = (["id", "user_id", "content"] :: [Text]),
|
insertPermissionColumns = (["id", "user_id", "content"] :: [Text]),
|
||||||
insertPermissionValidationWebhook = Just $ (T.pack $ serverUrl server) <> "/validateTweet"
|
insertPermissionValidationWebhook = Just $ T.pack (serverUrl server) <> "/validateTweet"
|
||||||
},
|
},
|
||||||
Fixture.teardownAction = \_ -> pure ()
|
Fixture.teardownAction = \_ -> pure ()
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ createUpdatePermissions testEnvironment server =
|
|||||||
{ updatePermissionTable = "user",
|
{ updatePermissionTable = "user",
|
||||||
updatePermissionRole = "user",
|
updatePermissionRole = "user",
|
||||||
updatePermissionColumns = ["id", "name", "email", "phone_number"],
|
updatePermissionColumns = ["id", "name", "email", "phone_number"],
|
||||||
updatePermissionValidationWebhook = Just $ (T.pack $ serverUrl server) <> "/validateUpdateUser"
|
updatePermissionValidationWebhook = Just $ T.pack (serverUrl server) <> "/validateUpdateUser"
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphqlEngine.postMetadata_ testEnvironment
|
GraphqlEngine.postMetadata_ testEnvironment
|
||||||
@ -173,7 +173,7 @@ createUpdatePermissions testEnvironment server =
|
|||||||
{ updatePermissionTable = "tweet",
|
{ updatePermissionTable = "tweet",
|
||||||
updatePermissionRole = "user",
|
updatePermissionRole = "user",
|
||||||
updatePermissionColumns = ["id", "user_id", "content", "email"],
|
updatePermissionColumns = ["id", "user_id", "content", "email"],
|
||||||
updatePermissionValidationWebhook = Just $ (T.pack $ serverUrl server) <> "/validateUpdateTweet"
|
updatePermissionValidationWebhook = Just $ T.pack (serverUrl server) <> "/validateUpdateTweet"
|
||||||
},
|
},
|
||||||
Fixture.teardownAction = \_ -> pure ()
|
Fixture.teardownAction = \_ -> pure ()
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,10 @@ import Test.Sandwich (describe)
|
|||||||
import Test.TestHelpers (AgentDatasetTestSpec, it)
|
import Test.TestHelpers (AgentDatasetTestSpec, it)
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
{-# ANN module ("HLint: ignore Functor law" :: String) #-}
|
||||||
|
|
||||||
|
{-# ANN module ("HLint: ignore Redundant <&>" :: String) #-}
|
||||||
|
|
||||||
spec :: TestData -> Capabilities -> AgentDatasetTestSpec
|
spec :: TestData -> Capabilities -> AgentDatasetTestSpec
|
||||||
spec TestData {..} Capabilities {..} = describe "Data Redaction in Queries" $ do
|
spec TestData {..} Capabilities {..} = describe "Data Redaction in Queries" $ do
|
||||||
describe "Column Field Redaction" $ do
|
describe "Column Field Redaction" $ do
|
||||||
|
@ -5,6 +5,7 @@ where
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import Control.Monad (replicateM)
|
||||||
import Data.Bifunctor (second)
|
import Data.Bifunctor (second)
|
||||||
import Data.ByteString.Builder qualified as BS
|
import Data.ByteString.Builder qualified as BS
|
||||||
import Data.Function ((&))
|
import Data.Function ((&))
|
||||||
@ -31,7 +32,7 @@ genDocs num =
|
|||||||
genTexts :: Int -> IO [(Int, [Text])]
|
genTexts :: Int -> IO [(Int, [Text])]
|
||||||
genTexts num =
|
genTexts num =
|
||||||
for [1 .. num] $ \n -> do
|
for [1 .. num] $ \n -> do
|
||||||
texts <- for [1 .. 500 :: Int] \_ -> generate genText
|
texts <- replicateM (500 :: Int) (generate genText)
|
||||||
pure (n, texts)
|
pure (n, texts)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{-# HLINT ignore "Use onLeft" #-}
|
{-# HLINT ignore "Use onLeft" #-}
|
||||||
{-# LANGUAGE InstanceSigs #-}
|
{-# LANGUAGE InstanceSigs #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskellQuotes #-}
|
||||||
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
||||||
|
|
||||||
-- | Description: The GraphQL AST
|
-- | Description: The GraphQL AST
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskellQuotes #-}
|
||||||
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
|
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
|
||||||
|
|
||||||
-- | Internal GraphQL AST functionality.
|
-- | Internal GraphQL AST functionality.
|
||||||
|
@ -245,7 +245,7 @@ initPQConn ci logger = do
|
|||||||
-- Retry if postgres connection error occurs
|
-- Retry if postgres connection error occurs
|
||||||
pgRetrying host resetFn retryP logger $ do
|
pgRetrying host resetFn retryP logger $ do
|
||||||
-- Initialise the connection
|
-- Initialise the connection
|
||||||
conn <- PQ.connectdb =<< (pgConnString $ ciDetails ci)
|
conn <- PQ.connectdb =<< pgConnString (ciDetails ci)
|
||||||
|
|
||||||
-- Check the status of the connection
|
-- Check the status of the connection
|
||||||
s <- liftIO $ PQ.status conn
|
s <- liftIO $ PQ.status conn
|
||||||
|
@ -228,10 +228,7 @@ safeSelectionSet name description fields =
|
|||||||
where
|
where
|
||||||
namesOrigins :: InsOrdHashMap Name [Maybe origin]
|
namesOrigins :: InsOrdHashMap Name [Maybe origin]
|
||||||
namesOrigins =
|
namesOrigins =
|
||||||
foldr
|
foldr (uncurry (InsOrdHashMap.insertWith (<>)) . (dName &&& (pure . dOrigin)) . fDefinition) InsOrdHashMap.empty fields
|
||||||
(uncurry (InsOrdHashMap.insertWith (<>)))
|
|
||||||
InsOrdHashMap.empty
|
|
||||||
((dName &&& (pure . dOrigin)) . fDefinition <$> fields)
|
|
||||||
duplicates :: InsOrdHashMap Name [Maybe origin]
|
duplicates :: InsOrdHashMap Name [Maybe origin]
|
||||||
duplicates = InsOrdHashMap.filter ((> 1) . length) namesOrigins
|
duplicates = InsOrdHashMap.filter ((> 1) . length) namesOrigins
|
||||||
uniques = S.toList . S.fromList
|
uniques = S.toList . S.fromList
|
||||||
|
@ -418,9 +418,7 @@ updateCustomOp (API.UpdateColumnOperatorName operatorName) operatorUsages = GS.U
|
|||||||
updateOperatorApplicableColumn :: RQL.ColumnInfo 'DataConnector -> Bool
|
updateOperatorApplicableColumn :: RQL.ColumnInfo 'DataConnector -> Bool
|
||||||
updateOperatorApplicableColumn columnInfo =
|
updateOperatorApplicableColumn columnInfo =
|
||||||
-- ColumnEnumReferences are not supported at this time
|
-- ColumnEnumReferences are not supported at this time
|
||||||
extractColumnScalarType columnInfo
|
maybe False (\columnScalarType -> HashMap.member columnScalarType operatorUsages) (extractColumnScalarType columnInfo)
|
||||||
<&> (\columnScalarType -> HashMap.member columnScalarType operatorUsages)
|
|
||||||
& fromMaybe False
|
|
||||||
|
|
||||||
-- Prepend the operator name with underscore
|
-- Prepend the operator name with underscore
|
||||||
operatorGraphqlFieldIdentifier :: GQLNameIdentifier
|
operatorGraphqlFieldIdentifier :: GQLNameIdentifier
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
|
||||||
|
|
||||||
-- | MSSQL DDL RunSQL
|
-- | MSSQL DDL RunSQL
|
||||||
--
|
--
|
||||||
|
@ -182,9 +182,10 @@ mkMSSQLTxErrorHandler isExpectedError = \case
|
|||||||
"exception" .= odbcExceptionToJSONValue exception
|
"exception" .= odbcExceptionToJSONValue exception
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
in fromMaybe unexpectedQueryError
|
in maybe
|
||||||
$ asExpectedError exception
|
unexpectedQueryError
|
||||||
<&> \err -> err {Error.qeInternal = Just $ Error.ExtraInternal $ object ["query" .= ODBC.renderQuery query]}
|
(\err -> err {Error.qeInternal = Just $ Error.ExtraInternal $ object ["query" .= ODBC.renderQuery query]})
|
||||||
|
(asExpectedError exception)
|
||||||
MSSQLConnError exception ->
|
MSSQLConnError exception ->
|
||||||
let unexpectedConnError =
|
let unexpectedConnError =
|
||||||
(Error.internalError "mssql connection error")
|
(Error.internalError "mssql connection error")
|
||||||
|
@ -415,10 +415,9 @@ convertFunction sourceName modelSourceType userInfo jsonAggSelect unpreparedQuer
|
|||||||
modelNames <- irToModelInfoGen sourceName modelSourceType $ queryResultFn preparedQuery
|
modelNames <- irToModelInfoGen sourceName modelSourceType $ queryResultFn preparedQuery
|
||||||
let preparedSQLWithQueryTags = appendPreparedSQLWithQueryTags rootFieldPlan queryTags
|
let preparedSQLWithQueryTags = appendPreparedSQLWithQueryTags rootFieldPlan queryTags
|
||||||
pure
|
pure
|
||||||
$! ( fst
|
( fst (mkCurPlanTx userInfo preparedSQLWithQueryTags), -- forget (Maybe PreparedSql)
|
||||||
$ mkCurPlanTx userInfo preparedSQLWithQueryTags, -- forget (Maybe PreparedSql)
|
modelNames
|
||||||
modelNames
|
)
|
||||||
)
|
|
||||||
|
|
||||||
pgDBMutationPlan ::
|
pgDBMutationPlan ::
|
||||||
forall pgKind m.
|
forall pgKind m.
|
||||||
|
@ -168,7 +168,7 @@ defaultAggregationPredicatesParser aggFns ti = runMaybeT do
|
|||||||
|
|
||||||
-- Collect all the non-failed branches, failing if all branches failed.
|
-- Collect all the non-failed branches, failing if all branches failed.
|
||||||
succeedingBranchesNE :: forall f a. (Applicative f) => NonEmpty (MaybeT f a) -> MaybeT f (NonEmpty a)
|
succeedingBranchesNE :: forall f a. (Applicative f) => NonEmpty (MaybeT f a) -> MaybeT f (NonEmpty a)
|
||||||
succeedingBranchesNE xs = MaybeT $ NE.nonEmpty . catMaybes . NE.toList <$> sequenceA (xs <&> runMaybeT)
|
succeedingBranchesNE xs = MaybeT $ NE.nonEmpty . catMaybes . NE.toList <$> traverse runMaybeT xs
|
||||||
|
|
||||||
-- Collect a non-empty list of input field parsers into one input field
|
-- Collect a non-empty list of input field parsers into one input field
|
||||||
-- parser parsing a non-empty list of the specified values.
|
-- parser parsing a non-empty list of the specified values.
|
||||||
|
@ -947,7 +947,7 @@ remoteField sdoc remoteRelationships parentTypeName fieldName description argsDe
|
|||||||
remoteSchemaObjFields <- remoteSchemaObject sdoc remoteRelationships objTypeDefn
|
remoteSchemaObjFields <- remoteSchemaObject sdoc remoteRelationships objTypeDefn
|
||||||
-- converting [Field NoFragments Name] to (SelectionSet NoFragments G.Name)
|
-- converting [Field NoFragments Name] to (SelectionSet NoFragments G.Name)
|
||||||
let remoteSchemaObjSelSet = IR.SelectionSetObject <$> remoteSchemaObjFields
|
let remoteSchemaObjSelSet = IR.SelectionSetObject <$> remoteSchemaObjFields
|
||||||
pure remoteSchemaObjSelSet <&> mkFieldParserWithSelectionSet customizedFieldName argsParser
|
pure $ mkFieldParserWithSelectionSet customizedFieldName argsParser remoteSchemaObjSelSet
|
||||||
G.TypeDefinitionScalar scalarTypeDefn ->
|
G.TypeDefinitionScalar scalarTypeDefn ->
|
||||||
pure $ mkFieldParserWithoutSelectionSet customizedFieldName argsParser $ void $ remoteFieldScalarParser customizeTypename scalarTypeDefn
|
pure $ mkFieldParserWithoutSelectionSet customizedFieldName argsParser $ void $ remoteFieldScalarParser customizeTypename scalarTypeDefn
|
||||||
G.TypeDefinitionEnum enumTypeDefn ->
|
G.TypeDefinitionEnum enumTypeDefn ->
|
||||||
|
@ -263,7 +263,7 @@ instance OnlyRelevantEq G.Name where
|
|||||||
instance (OnlyRelevantEq a) => OnlyRelevantEq [a] where
|
instance (OnlyRelevantEq a) => OnlyRelevantEq [a] where
|
||||||
l ==~ r =
|
l ==~ r =
|
||||||
(length r == length r)
|
(length r == length r)
|
||||||
&& (all (== True) (zipWith (==~) l r))
|
&& and (zipWith (==~) l r)
|
||||||
|
|
||||||
instance OnlyRelevantEq G.ScalarTypeDefinition where
|
instance OnlyRelevantEq G.ScalarTypeDefinition where
|
||||||
G.ScalarTypeDefinition _descL nameL directivesL
|
G.ScalarTypeDefinition _descL nameL directivesL
|
||||||
|
@ -53,7 +53,7 @@ execPGDump b ci = do
|
|||||||
throwException text err = throwError (RTE.err500 RTE.Unexpected text) {RTE.qeInternal = Just (RTE.ExtraInternal (toJSON err))}
|
throwException text err = throwError (RTE.err500 RTE.Unexpected text) {RTE.qeInternal = Just (RTE.ExtraInternal (toJSON err))}
|
||||||
|
|
||||||
execProcess = do
|
execProcess = do
|
||||||
connString <- T.unpack . bsToTxt <$> (PG.pgConnString $ PG.ciDetails ci)
|
connString <- T.unpack . bsToTxt <$> PG.pgConnString (PG.ciDetails ci)
|
||||||
let opts = connString : "--encoding=utf8" : prbOpts b
|
let opts = connString : "--encoding=utf8" : prbOpts b
|
||||||
(exitCode, stdOut, stdErr) <- readProcessWithExitCode "pg_dump" opts ""
|
(exitCode, stdOut, stdErr) <- readProcessWithExitCode "pg_dump" opts ""
|
||||||
return $ case exitCode of
|
return $ case exitCode of
|
||||||
|
@ -122,7 +122,7 @@ checkMemoization = do
|
|||||||
_ -> (+) <$> fibo (n - 2) <*> fibo (n - 1)
|
_ -> (+) <$> fibo (n - 2) <*> fibo (n - 1)
|
||||||
traverse fibo [0 .. 20]
|
traverse fibo [0 .. 20]
|
||||||
fibos !! 20 `shouldBe` (6765 :: Int)
|
fibos !! 20 `shouldBe` (6765 :: Int)
|
||||||
count `shouldBe` HashMap.fromList (zip [0 .. 20] (repeat 1))
|
count `shouldBe` HashMap.fromList (map (,1) [0 .. 20])
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Failure
|
-- Failure
|
||||||
|
Loading…
Reference in New Issue
Block a user