2022-05-11 09:14:25 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
|
|
|
-- | Data Connector helpers.
|
|
|
|
module Harness.Backend.DataConnector
|
2022-06-23 11:07:52 +03:00
|
|
|
( setup,
|
2022-05-11 09:14:25 +03:00
|
|
|
teardown,
|
|
|
|
defaultSourceMetadata,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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 Prelude
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
defaultSourceMetadata :: Value
|
|
|
|
defaultSourceMetadata =
|
|
|
|
let source = defaultSource DataConnector
|
|
|
|
backendType = defaultBackendTypeString DataConnector
|
|
|
|
in [yaml|
|
|
|
|
name : *source
|
|
|
|
kind: *backendType
|
|
|
|
tables:
|
2022-06-13 23:58:44 +03:00
|
|
|
- table: Album
|
|
|
|
configuration:
|
|
|
|
custom_root_fields:
|
|
|
|
select: albums
|
|
|
|
select_by_pk: albums_by_pk
|
|
|
|
column_config:
|
|
|
|
AlbumId:
|
|
|
|
custom_name: id
|
|
|
|
Title:
|
|
|
|
custom_name: title
|
|
|
|
ArtistId:
|
|
|
|
custom_name: artist_id
|
2022-05-11 09:14:25 +03:00
|
|
|
object_relationships:
|
2022-06-13 23:58:44 +03:00
|
|
|
- name: artist
|
2022-05-11 09:14:25 +03:00
|
|
|
using:
|
|
|
|
manual_configuration:
|
2022-06-13 23:58:44 +03:00
|
|
|
remote_table: Artist
|
2022-05-11 09:14:25 +03:00
|
|
|
column_mapping:
|
2022-06-13 23:58:44 +03:00
|
|
|
ArtistId: ArtistId
|
|
|
|
- table: Artist
|
|
|
|
configuration:
|
|
|
|
custom_root_fields:
|
|
|
|
select: artists
|
|
|
|
select_by_pk: artists_by_pk
|
|
|
|
column_config:
|
|
|
|
ArtistId:
|
|
|
|
custom_name: id
|
|
|
|
Name:
|
|
|
|
custom_name: name
|
2022-05-11 09:14:25 +03:00
|
|
|
array_relationships:
|
2022-06-13 23:58:44 +03:00
|
|
|
- name: albums
|
2022-05-11 09:14:25 +03:00
|
|
|
using:
|
|
|
|
manual_configuration:
|
2022-06-13 23:58:44 +03:00
|
|
|
remote_table: Album
|
2022-05-11 09:14:25 +03:00
|
|
|
column_mapping:
|
2022-06-13 23:58:44 +03:00
|
|
|
ArtistId: ArtistId
|
2022-05-11 09:14:25 +03:00
|
|
|
configuration: {}
|
|
|
|
|]
|
|
|
|
|
|
|
|
defaultBackendConfig :: Value
|
|
|
|
defaultBackendConfig =
|
|
|
|
let backendType = defaultBackendTypeString DataConnector
|
|
|
|
in [yaml|
|
|
|
|
dataconnector:
|
|
|
|
*backendType:
|
2022-06-23 11:07:52 +03:00
|
|
|
uri: "http://127.0.0.1:65005/"
|
2022-05-11 09:14:25 +03:00
|
|
|
|]
|
|
|
|
|
|
|
|
-- | Setup the schema in the most expected way.
|
2022-06-23 11:07:52 +03:00
|
|
|
setup :: (TestEnvironment, ()) -> IO ()
|
2022-05-11 09:14:25 +03:00
|
|
|
setup (testEnvironment, _) = do
|
|
|
|
-- Clear and reconfigure the metadata
|
|
|
|
GraphqlEngine.setSource testEnvironment defaultSourceMetadata (Just defaultBackendConfig)
|
|
|
|
|
|
|
|
-- | Teardown the schema and tracking in the most expected way.
|
2022-06-23 11:07:52 +03:00
|
|
|
teardown :: (TestEnvironment, ()) -> IO ()
|
|
|
|
teardown (testEnvironment, _) = do
|
2022-05-11 09:14:25 +03:00
|
|
|
GraphqlEngine.clearMetadata testEnvironment
|