mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
b4f89569c8
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4467 GitOrigin-RevId: 5e81d8581197c90ad2de9106e724c63d7592ae72
75 lines
2.1 KiB
Haskell
75 lines
2.1 KiB
Haskell
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
-- | Data Connector helpers.
|
|
module Harness.Backend.DataConnector
|
|
( mkLocalTestEnvironment,
|
|
setup,
|
|
teardown,
|
|
defaultSourceMetadata,
|
|
)
|
|
where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Control.Concurrent (ThreadId, forkIO, killThread)
|
|
import Data.Aeson (Value)
|
|
import Harness.GraphqlEngine qualified as GraphqlEngine
|
|
import Harness.Quoter.Yaml (yaml)
|
|
import Harness.Test.Context (BackendType (DataConnector), defaultBackendTypeString, defaultSource)
|
|
import Harness.TestEnvironment (TestEnvironment)
|
|
import Hasura.Backends.DataConnector.Agent.Server (runDcServer)
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
defaultSourceMetadata :: Value
|
|
defaultSourceMetadata =
|
|
let source = defaultSource DataConnector
|
|
backendType = defaultBackendTypeString DataConnector
|
|
in [yaml|
|
|
name : *source
|
|
kind: *backendType
|
|
tables:
|
|
- table: "albums"
|
|
object_relationships:
|
|
- name: "artist"
|
|
using:
|
|
manual_configuration:
|
|
remote_table: "artists"
|
|
column_mapping:
|
|
artist_id: "id"
|
|
- table: "artists"
|
|
array_relationships:
|
|
- name: "albums"
|
|
using:
|
|
manual_configuration:
|
|
remote_table: "albums"
|
|
column_mapping:
|
|
id: "artist_id"
|
|
configuration: {}
|
|
|]
|
|
|
|
defaultBackendConfig :: Value
|
|
defaultBackendConfig =
|
|
let backendType = defaultBackendTypeString DataConnector
|
|
in [yaml|
|
|
dataconnector:
|
|
*backendType:
|
|
uri: "http://localhost:8100/"
|
|
|]
|
|
|
|
mkLocalTestEnvironment :: TestEnvironment -> IO ThreadId
|
|
mkLocalTestEnvironment _ = forkIO runDcServer
|
|
|
|
-- | Setup the schema in the most expected way.
|
|
setup :: (TestEnvironment, ThreadId) -> IO ()
|
|
setup (testEnvironment, _) = do
|
|
-- Clear and reconfigure the metadata
|
|
GraphqlEngine.setSource testEnvironment defaultSourceMetadata (Just defaultBackendConfig)
|
|
|
|
-- | Teardown the schema and tracking in the most expected way.
|
|
teardown :: (TestEnvironment, ThreadId) -> IO ()
|
|
teardown (testEnvironment, agentThread) = do
|
|
GraphqlEngine.clearMetadata testEnvironment
|
|
killThread agentThread
|