graphql-engine/server/tests-hspec/Harness/GraphqlEngine.hs
Abby Sassel 1f14781d15 Create integration testing environment (close hasura/graphql-engine#7752)
dupe of @chrisdone's work https://github.com/hasura/graphql-engine-mono/pull/2829 with a branch rename

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2901
Co-authored-by: Chris Done <11019+chrisdone@users.noreply.github.com>
GitOrigin-RevId: 8381e53a18242b75d7e17b18a2ba3b2d99dd1322
2021-11-17 19:51:47 +00:00

34 lines
1.0 KiB
Haskell

-- | Helpers for talking to graphql engine.
module Harness.GraphqlEngine
( post,
post_,
postGraphql,
postGraphqlYaml,
)
where
import Data.Aeson
import Data.Functor
import GHC.Stack
import Harness.Constants qualified as Constants
import Harness.Http qualified as Http
import Prelude
-- | Post some JSON to graphql-engine, getting back more
-- JSON. Optimistically assumes success. Use another function if you
-- want to test for failure.
post :: HasCallStack => String -> Value -> IO Value
post path = Http.postValue_ (Constants.graphqlEngineUrlPrefix ++ path)
-- | Same as post, but ignores the value.
post_ :: HasCallStack => String -> Value -> IO ()
post_ path = void . post path
-- | Same as post, but defaults to the graphql end-point.
postGraphqlYaml :: HasCallStack => Value -> IO Value
postGraphqlYaml = post "/v1/graphql"
-- | Same as 'postGraphqlYaml', but adds the {query:..} wrapper.
postGraphql :: HasCallStack => Value -> IO Value
postGraphql value = postGraphqlYaml (object ["query" .= value])