2022-08-29 06:38:24 +03:00
|
|
|
module Test.ExplainSpec (spec) where
|
|
|
|
|
|
|
|
import Control.Lens ((&), (?~))
|
|
|
|
import Hasura.Backends.DataConnector.API (Capabilities (..), Config, ExplainResponse (..), QueryRequest (..), Routes (..), SourceName, qFields)
|
|
|
|
import Servant.API (NamedRoutes)
|
|
|
|
import Servant.Client (Client, (//))
|
2022-09-28 02:41:21 +03:00
|
|
|
import Test.Data (TestData (..))
|
2022-08-29 06:38:24 +03:00
|
|
|
import Test.Data qualified as Data
|
|
|
|
import Test.Hspec (Spec, describe, it, shouldNotBe)
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
-- Note:
|
|
|
|
-- We currently simply check that for a basic query the explain plan is not empty.
|
|
|
|
-- There may be additional tests for explain-plans in HGE that we can leverage.
|
|
|
|
--
|
2022-09-28 02:41:21 +03:00
|
|
|
spec :: TestData -> Client IO (NamedRoutes Routes) -> SourceName -> Config -> Capabilities -> Spec
|
|
|
|
spec TestData {..} api sourceName config _ = do
|
2022-08-29 06:38:24 +03:00
|
|
|
describe "Explain API" do
|
|
|
|
it "can generate an explain plan a query for a list of artists" $ do
|
|
|
|
let query = artistsQueryRequest
|
|
|
|
ExplainResponse {..} <- (api // _explain) sourceName config query
|
|
|
|
_erQuery `shouldNotBe` ""
|
|
|
|
_erLines `shouldNotBe` []
|
2022-09-28 02:41:21 +03:00
|
|
|
where
|
|
|
|
artistsQueryRequest :: QueryRequest
|
|
|
|
artistsQueryRequest =
|
2022-10-06 02:23:49 +03:00
|
|
|
let fields = Data.mkFieldsMap [("ArtistId", _tdColumnField "ArtistId"), ("Name", _tdColumnField "Name")]
|
2022-09-28 02:41:21 +03:00
|
|
|
query = Data.emptyQuery & qFields ?~ fields
|
|
|
|
in QueryRequest _tdArtistsTableName [] query
|