server: fix MySQL connection pool settings getting swapped on parse

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6063
GitOrigin-RevId: 90f6f8485aa6a9d073edc56dcba5530f5cf787c4
This commit is contained in:
Jesse Hallett 2022-09-28 17:10:09 -04:00 committed by hasura-bot
parent cbdacd1c6c
commit d32dc881e3
3 changed files with 33 additions and 2 deletions

View File

@ -988,6 +988,7 @@ test-suite graphql-engine-tests
Hasura.Backends.DataConnector.API.V0.TableSpec
Hasura.Backends.MSSQL.ErrorSpec
Hasura.Backends.MySQL.DataLoader.ExecuteTests
Hasura.Backends.MySQL.TypesSpec
Hasura.Backends.Postgres.Execute.PrepareSpec
Hasura.Backends.Postgres.RQLGenerator
Hasura.Backends.Postgres.RQLGenerator.GenAnnSelectG

View File

@ -199,8 +199,8 @@ instance Semigroup Top where
instance J.FromJSON ConnPoolSettings where
parseJSON = J.withObject "MySQL pool settings" $ \o ->
ConnPoolSettings
<$> o J..:? "max_connections" J..!= _cscMaxConnections defaultConnPoolSettings
<*> o J..:? "idle_timeout" J..!= _cscIdleTimeout defaultConnPoolSettings
<$> o J..:? "idle_timeout" J..!= _cscIdleTimeout defaultConnPoolSettings
<*> o J..:? "max_connections" J..!= _cscMaxConnections defaultConnPoolSettings
$(J.deriveToJSON hasuraJSON ''ConnPoolSettings)

View File

@ -0,0 +1,30 @@
{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.MySQL.TypesSpec (spec) where
import Data.Aeson (parseJSON, toJSON)
import Data.Aeson.QQ (aesonQQ)
import Data.Aeson.Types (parseEither)
import Hasura.Backends.MySQL.Types (ConnPoolSettings (..))
import Hasura.Prelude
import Test.Hspec
spec :: Spec
spec = do
describe "MySQL" do
describe "ConnPoolSettings" do
it "should parse idle timeout and max connections" do
let input =
[aesonQQ|
{ "idle_timeout": 100,
"max_connections": 10
}
|]
let decoded = parseEither parseJSON input
let expected = ConnPoolSettings {_cscIdleTimeout = 100, _cscMaxConnections = 10}
decoded `shouldBe` Right expected
it "should round-trip" do
let expected = ConnPoolSettings {_cscIdleTimeout = 100, _cscMaxConnections = 10}
let actual = parseEither parseJSON $ toJSON expected
actual `shouldBe` Right expected