mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-17 13:37:26 +03:00
bulk_keep_going
[NDAT-604]: https://hasurahq.atlassian.net/browse/NDAT-604?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8770 GitOrigin-RevId: 597dbb1448794c0ac25496d6b6f759d5aaccc2fb
This commit is contained in:
parent
a5a76b565b
commit
4c25eafc52
@ -95,6 +95,7 @@ library
|
||||
Test.API.ConcurrentBulkSpec
|
||||
Test.API.ExplainSpec
|
||||
Test.API.GraphQL.ContentLengthSpec
|
||||
Test.API.Metadata.BulkKeepGoingSpec
|
||||
Test.API.Metadata.ComputedFieldsSpec
|
||||
Test.API.Metadata.CustomTypeSpec
|
||||
Test.API.Metadata.InconsistentSpec
|
||||
|
116
server/lib/api-tests/src/Test/API/Metadata/BulkKeepGoingSpec.hs
Normal file
116
server/lib/api-tests/src/Test/API/Metadata/BulkKeepGoingSpec.hs
Normal file
@ -0,0 +1,116 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
-- | Tests of the newly separated Custom Return Types feature
|
||||
module Test.API.Metadata.BulkKeepGoingSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
import Harness.Schema qualified as Schema
|
||||
import Harness.Test.BackendType qualified as BackendType
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.TestEnvironment (GlobalTestEnvironment, TestEnvironment, getBackendTypeConfig)
|
||||
import Harness.Yaml (shouldAtLeastBe)
|
||||
import Hasura.Prelude
|
||||
import Test.Hspec (SpecWith, it)
|
||||
|
||||
-- ** Preamble
|
||||
|
||||
spec :: SpecWith GlobalTestEnvironment
|
||||
spec =
|
||||
Fixture.runClean
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnvironment
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
-- ** Setup and teardown
|
||||
|
||||
schema :: [Schema.Table]
|
||||
schema = []
|
||||
|
||||
tests :: SpecWith TestEnvironment
|
||||
tests = do
|
||||
it "returns successes when the /last/ query fails" \testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
|
||||
GraphqlEngine.postV2Query_
|
||||
testEnvironment
|
||||
[interpolateYaml|
|
||||
type: run_sql
|
||||
args:
|
||||
source: #{sourceName}
|
||||
sql: CREATE TABLE test_table (id int);
|
||||
cascade: false
|
||||
read_only: false
|
||||
|]
|
||||
|
||||
actual <-
|
||||
GraphqlEngine.postMetadata
|
||||
testEnvironment
|
||||
[interpolateYaml|
|
||||
type: bulk_keep_going
|
||||
args:
|
||||
- type: pg_track_table
|
||||
args:
|
||||
source: #{sourceName}
|
||||
table:
|
||||
name: test_table
|
||||
- type: pg_track_table
|
||||
args:
|
||||
source: #{sourceName}
|
||||
table:
|
||||
name: unknown_table
|
||||
|]
|
||||
|
||||
actual
|
||||
`shouldAtLeastBe` [interpolateYaml|
|
||||
- message: success
|
||||
- code: invalid-configuration
|
||||
|]
|
||||
|
||||
it "returns successes when the /first/ query fails" \testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
|
||||
GraphqlEngine.postV2Query_
|
||||
testEnvironment
|
||||
[interpolateYaml|
|
||||
type: run_sql
|
||||
args:
|
||||
source: #{sourceName}
|
||||
sql: CREATE TABLE test_table (id int);
|
||||
cascade: false
|
||||
read_only: false
|
||||
|]
|
||||
|
||||
actual <-
|
||||
GraphqlEngine.postMetadata
|
||||
testEnvironment
|
||||
[interpolateYaml|
|
||||
type: bulk_keep_going
|
||||
args:
|
||||
- type: pg_track_table
|
||||
args:
|
||||
source: #{sourceName}
|
||||
table:
|
||||
name: unknown_table
|
||||
- type: pg_track_table
|
||||
args:
|
||||
source: #{sourceName}
|
||||
table:
|
||||
name: test_table
|
||||
|]
|
||||
|
||||
actual
|
||||
`shouldAtLeastBe` [interpolateYaml|
|
||||
- code: invalid-configuration
|
||||
- message: success
|
||||
|]
|
@ -234,6 +234,9 @@ data RQLMetadataV1
|
||||
RMGetFeatureFlag !GetFeatureFlag
|
||||
| -- Bulk metadata queries
|
||||
RMBulk [RQLMetadataRequest]
|
||||
| -- Bulk metadata queries, but don't stop if something fails - return all
|
||||
-- successes and failures as separate items
|
||||
RMBulkKeepGoing [RQLMetadataRequest]
|
||||
deriving (Generic)
|
||||
|
||||
-- NOTE! If you add a new request type here that is read-only, make sure to
|
||||
@ -312,6 +315,7 @@ instance FromJSON RQLMetadataV1 where
|
||||
"set_opentelemetry_status" -> RMSetOpenTelemetryStatus <$> args
|
||||
"get_feature_flag" -> RMGetFeatureFlag <$> args
|
||||
"bulk" -> RMBulk <$> args
|
||||
"bulk_keep_going" -> RMBulkKeepGoing <$> args
|
||||
-- Backend prefixed metadata actions:
|
||||
_ -> do
|
||||
-- 1) Parse the backend source kind and metadata command:
|
||||
@ -517,6 +521,7 @@ queryModifiesMetadata = \case
|
||||
RMCreateSelectCustomReturnTypePermission _ -> True
|
||||
RMDropSelectCustomReturnTypePermission _ -> True
|
||||
RMBulk qs -> any queryModifiesMetadata qs
|
||||
RMBulkKeepGoing qs -> any queryModifiesMetadata qs
|
||||
-- We used to assume that the fallthrough was True,
|
||||
-- but it is better to be explicit here to warn when new constructors are added.
|
||||
RMAddSource _ -> True
|
||||
@ -805,6 +810,13 @@ runMetadataQueryV1M env checkFeatureFlag remoteSchemaPerms currentResourceVersio
|
||||
RMSetOpenTelemetryStatus q -> runSetOpenTelemetryStatus q
|
||||
RMGetFeatureFlag q -> runGetFeatureFlag checkFeatureFlag q
|
||||
RMBulk q -> encJFromList <$> indexedMapM (runMetadataQueryM env checkFeatureFlag remoteSchemaPerms currentResourceVersion) q
|
||||
RMBulkKeepGoing commands -> do
|
||||
results <-
|
||||
commands & indexedMapM \command ->
|
||||
runMetadataQueryM env checkFeatureFlag remoteSchemaPerms currentResourceVersion command
|
||||
`catchError` \qerr -> pure (encJFromJValue qerr)
|
||||
|
||||
pure (encJFromList results)
|
||||
where
|
||||
dispatchMetadata ::
|
||||
(forall b. BackendMetadata b => i b -> a) ->
|
||||
|
@ -186,6 +186,9 @@ data RQLMetadataV1
|
||||
RMGetFeatureFlag !GetFeatureFlag
|
||||
| -- Bulk metadata queries
|
||||
RMBulk [RQLMetadataRequest]
|
||||
| -- Bulk metadata queries, but don't stop if something fails - return all
|
||||
-- successes and failures as separate items
|
||||
RMBulkKeepGoing [RQLMetadataRequest]
|
||||
|
||||
data RQLMetadataV2
|
||||
= RMV2ReplaceMetadata !ReplaceMetadataV2
|
||||
|
Loading…
Reference in New Issue
Block a user