diff --git a/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs b/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs index 7e9e48465e2..17be2c7f032 100644 --- a/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs +++ b/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs @@ -16,6 +16,7 @@ where -------------------------------------------------------------------------------- +import Control.Lens ((^?), _Just) import Control.Lens qualified as Lens import Data.Aeson qualified as J import Data.Aeson.KeyMap qualified as KM @@ -355,7 +356,7 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w |] describe "_track_table" $ do - it "success" $ \(testEnvironment, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do + it "success - track Album" $ \(testEnvironment, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do case (backendTypeString &&& backendSourceName) <$> TestEnvironment.getBackendTypeConfig testEnvironment of Nothing -> pendingWith "Backend Type not found in testEnvironment" Just (backendType, sourceName) -> do @@ -376,28 +377,42 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w message: success |] - describe "_create_object_relationship" $ do - it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do - let foreignKeySupport = (getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities) <&> API._dscSupportsForeignKeys . API._cDataSchema - case (backendTypeString &&& backendSourceName) <$> getBackendTypeConfig testEnvironment of + it "success - track Artist" $ \(testEnvironment, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do + case (backendTypeString &&& backendSourceName) <$> TestEnvironment.getBackendTypeConfig testEnvironment of Nothing -> pendingWith "Backend Type not found in testEnvironment" Just (backendType, sourceName) -> do let actionType = backendType <> "_track_table" - artistTable = _nfFormatTableName ["Artist"] - albumTable = _nfFormatTableName ["Album"] - artistId = _nfFormatColumnName "ArtistId" - GraphqlEngine.postMetadata_ + artist = _nfFormatTableName ["Artist"] + shouldReturnYaml testEnvironment + ( GraphqlEngine.postMetadata + testEnvironment + [yaml| + type: *actionType + args: + source: *sourceName + table: *artist + |] + ) [yaml| - type: *actionType - args: - source: *sourceName - table: *artistTable - |] + message: success + |] - when - (foreignKeySupport == Just False) - (pendingWith "Backend does not support Foreign Key constraints") + describe "_create_object_relationship" $ do + it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do + let capabilities = getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities + let foreignKeySupport = fromMaybe False $ capabilities ^? _Just . API.cDataSchema . API.dscSupportsForeignKeys + let relationshipsSupport = isJust $ capabilities ^? _Just . API.cRelationships . _Just + unless relationshipsSupport $ + pendingWith "Backend does not support local relationships" + unless foreignKeySupport $ + pendingWith "Backend does not support Foreign Key constraints" + + case (backendTypeString &&& backendSourceName) <$> getBackendTypeConfig testEnvironment of + Nothing -> pendingWith "Backend Type not found in testEnvironment" + Just (backendType, sourceName) -> do + let albumTable = _nfFormatTableName ["Album"] + artistId = _nfFormatColumnName "ArtistId" let createObjectRelationAction = backendType <> "_create_object_relationship" shouldReturnYaml @@ -421,10 +436,14 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w describe "_create_array_relationship" $ do it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do - let foreignKeySupport = (getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities) <&> API._dscSupportsForeignKeys . API._cDataSchema - when - (foreignKeySupport == Just False) - (pendingWith "Backend does not support Foreign Key constraints") + let capabilities = getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities + let foreignKeySupport = fromMaybe False $ capabilities ^? _Just . API.cDataSchema . API.dscSupportsForeignKeys + let relationshipsSupport = isJust $ capabilities ^? _Just . API.cRelationships . _Just + unless relationshipsSupport $ + pendingWith "Backend does not support local relationships" + unless foreignKeySupport $ + pendingWith "Backend does not support Foreign Key constraints" + case (backendTypeString &&& backendSourceName) <$> TestEnvironment.getBackendTypeConfig testEnvironment of Nothing -> pendingWith "Backend Type not found in testEnvironment" Just (backendType, sourceName) -> do @@ -458,7 +477,9 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w case ((fold . backendServerUrl) &&& backendTypeString &&& backendSourceName) <$> TestEnvironment.getBackendTypeConfig testEnvironment of Nothing -> pendingWith "Backend Type not found in testEnvironment" Just (agentUrl, (backendType, sourceName)) -> do - let foreignKeySupport = (getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities) <&> API._dscSupportsForeignKeys . API._cDataSchema + let capabilities = getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities + let foreignKeySupport = fromMaybe False $ capabilities ^? _Just . API.cDataSchema . API.dscSupportsForeignKeys + let relationshipsSupport = isJust $ capabilities ^? _Just . API.cRelationships . _Just albumTable = _nfFormatTableName ["Album"] artistTable = _nfFormatTableName ["Artist"] artistId = _nfFormatColumnName "ArtistId" @@ -471,7 +492,7 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w args: {} |] ) - if foreignKeySupport == Just True + if foreignKeySupport && relationshipsSupport then [yaml| backend_configs: @@ -515,10 +536,14 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w describe "_drop_relationship" $ do it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do - let foreignKeySupport = (getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities) <&> API._dscSupportsForeignKeys . API._cDataSchema - when - (foreignKeySupport == Just False) - (pendingWith "Backend does not support Foreign Key constraints") + let capabilities = getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities + let foreignKeySupport = fromMaybe False $ capabilities ^? _Just . API.cDataSchema . API.dscSupportsForeignKeys + let relationshipsSupport = isJust $ capabilities ^? _Just . API.cRelationships . _Just + unless relationshipsSupport $ + pendingWith "Backend does not support local relationships" + unless foreignKeySupport $ + pendingWith "Backend does not support Foreign Key constraints" + case (backendTypeString &&& backendSourceName) <$> TestEnvironment.getBackendTypeConfig testEnvironment of Nothing -> pendingWith "Backend Type not found in testEnvironment" Just (backendType, sourceName) -> do @@ -542,10 +567,6 @@ schemaCrudTests = describe "A series of actions to setup and teardown a source w describe "_untrack_table" $ do it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do - let foreignKeySupport = (getBackendTypeConfig testEnvironment >>= BackendType.parseCapabilities) <&> API._dscSupportsForeignKeys . API._cDataSchema - when - (foreignKeySupport == Just False) - (pendingWith "Backend does not support Foreign Key constraints") case (backendTypeString &&& backendSourceName) <$> TestEnvironment.getBackendTypeConfig testEnvironment of Nothing -> pendingWith "Backend Type not found in testEnvironment" Just (backendType, sourceName) -> do diff --git a/server/lib/dc-api/src/Hasura/Backends/DataConnector/API/V0/Capabilities.hs b/server/lib/dc-api/src/Hasura/Backends/DataConnector/API/V0/Capabilities.hs index 0795733043a..995b5500832 100644 --- a/server/lib/dc-api/src/Hasura/Backends/DataConnector/API/V0/Capabilities.hs +++ b/server/lib/dc-api/src/Hasura/Backends/DataConnector/API/V0/Capabilities.hs @@ -23,6 +23,9 @@ module Hasura.Backends.DataConnector.API.V0.Capabilities cDatasets, defaultCapabilities, DataSchemaCapabilities (..), + dscSupportsPrimaryKeys, + dscSupportsForeignKeys, + dscColumnNullability, defaultDataSchemaCapabilities, ColumnNullability (..), QueryCapabilities (..), @@ -560,3 +563,4 @@ instance HasCodec Licensing where $(makeLenses ''CapabilitiesResponse) $(makeLenses ''Capabilities) $(makeLenses ''QueryCapabilities) +$(makeLenses ''DataSchemaCapabilities)