graphql-engine/server/tests/integration/Hasura/Test/Requests.hs
jkachmar 647231b685 Yeet some default-extensions
Manually enables:
* EmptyCase
* ExistentialQuantification
* QuantifiedConstraints
* QuasiQuotes
* TemplateHaskell
* TypeFamilyDependencies

...in the following components:
* 'graphql-engine' library
* 'graphql-engine' 'src-test'
* 'graphql-engine' 'tests/integration'
* 'graphql-engine' tests-hspec'

Additionally, performs some light refactoring and documentation.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3991
GitOrigin-RevId: 514477d3466b01f60eca8935d0fef60dd0756838
2022-03-16 00:40:17 +00:00

50 lines
1.2 KiB
Haskell

{-# LANGUAGE QuasiQuotes #-}
-- | A module collecting common HTTP requests to graphql-engine for testing.
module Hasura.Test.Requests
( replaceMetadata,
postgresRunSql,
v1graphql,
)
where
import Data.Aeson (encode)
import Data.Aeson.QQ (aesonQQ)
import Hasura.Prelude
import Hasura.RQL.Types.Metadata (Metadata)
import Network.HTTP.Types.Header (Header)
import Network.HTTP.Types.Method (methodPost)
import Network.Wai.Test (SResponse)
import Test.Hspec.Wai (WaiSession)
import Test.Hspec.Wai qualified as HW
--------------------------------------------------------------------------------
replaceMetadata :: Metadata -> WaiSession st SResponse
replaceMetadata metadata =
HW.post "/v1/metadata" $
encode
[aesonQQ|
{ type: "replace_metadata"
, args: { metadata: #{metadata} }
}
|]
postgresRunSql :: Text -> WaiSession st SResponse
postgresRunSql rawSql =
HW.post "/v2/query" $
encode
[aesonQQ|
{ type: "run_sql"
, args: { sql: #{rawSql} }
}
|]
v1graphql :: [Header] -> String -> WaiSession st SResponse
v1graphql headers graphqlQuery =
HW.request methodPost "/v1/graphql" headers $
encode
[aesonQQ|
{ query: #{graphqlQuery} }
|]