mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
Add support for explain in CockroachDB
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6415 GitOrigin-RevId: d60363d6f466a764b79c887631f9e3f094946440
This commit is contained in:
parent
346640fdf1
commit
d81571f928
@ -113,6 +113,7 @@ executable api-tests
|
||||
Test.Queries.Directives.IncludeSpec
|
||||
Test.Queries.Directives.SkipSpec
|
||||
Test.Queries.DirectivesSpec
|
||||
Test.Queries.ExplainSpec
|
||||
Test.Queries.FilterSearchSpec
|
||||
Test.Queries.FragmentsSpec
|
||||
Test.Queries.MultiColumnObjectRelationshipsSpec
|
||||
|
77
server/lib/api-tests/test/Test/Queries/ExplainSpec.hs
Normal file
77
server/lib/api-tests/test/Test/Queries/ExplainSpec.hs
Normal file
@ -0,0 +1,77 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
-- | Test that backend which support it are able to explain queries.
|
||||
module Test.Queries.ExplainSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Cockroach qualified as Cockroach
|
||||
import Harness.Backend.Mysql qualified as Mysql
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine
|
||||
import Harness.Quoter.Graphql
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment (..))
|
||||
import Harness.Yaml (shouldReturnYaml)
|
||||
import Hasura.Prelude
|
||||
import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Fixture.run
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Citus.setupTablesAction schema testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Cockroach)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Cockroach.setupTablesAction schema testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Mysql.setupTablesAction schema testEnvironment
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Schema
|
||||
|
||||
schema :: [Schema.Table]
|
||||
schema =
|
||||
[ (Schema.table "example")
|
||||
{ Schema.tableColumns =
|
||||
[ Schema.column "id" Schema.TInt,
|
||||
Schema.column "name" Schema.TStr
|
||||
],
|
||||
Schema.tablePrimaryKey = ["id"],
|
||||
Schema.tableData = []
|
||||
}
|
||||
]
|
||||
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests _opts = do
|
||||
describe "Explaining queries" do
|
||||
it "Works as expected" \testEnvironment -> do
|
||||
-- All that matters to this test is that the call completes without error.
|
||||
_ <- postExplain testEnvironment [graphql|query{hasura_example{id}}|]
|
||||
return ()
|
@ -155,7 +155,7 @@ pgDBQueryExplain fieldName userInfo sourceName sourceConfig rootSelection = do
|
||||
textSQL = PG.getQueryText querySQL
|
||||
-- CAREFUL!: an `EXPLAIN ANALYZE` here would actually *execute* this
|
||||
-- query, maybe resulting in privilege escalation:
|
||||
withExplain = "EXPLAIN (FORMAT TEXT) " <> textSQL
|
||||
withExplain = "EXPLAIN " <> textSQL
|
||||
let action =
|
||||
liftTx $
|
||||
PG.withQE dmlTxErrorHandler (PG.fromText withExplain) () True <&> \planList ->
|
||||
@ -177,7 +177,7 @@ pgDBSubscriptionExplain plan = do
|
||||
queryText = PG.getQueryText . PGL.unMultiplexedQuery $ _plqpQuery parameterizedPlan
|
||||
-- CAREFUL!: an `EXPLAIN ANALYZE` here would actually *execute* this
|
||||
-- query, maybe resulting in privilege escalation:
|
||||
explainQuery = PG.fromText $ "EXPLAIN (FORMAT TEXT) " <> queryText
|
||||
explainQuery = PG.fromText $ "EXPLAIN " <> queryText
|
||||
cohortId <- newCohortId
|
||||
explanationLines <-
|
||||
liftEitherM $
|
||||
|
Loading…
Reference in New Issue
Block a user