2020-05-27 18:02:58 +03:00
|
|
|
module Hasura.RQL.DDL.RemoteRelationship
|
|
|
|
( runCreateRemoteRelationship
|
|
|
|
, runDeleteRemoteRelationship
|
|
|
|
, runUpdateRemoteRelationship
|
2020-12-08 17:22:31 +03:00
|
|
|
, dropRemoteRelationshipInMetadata
|
2020-05-27 18:02:58 +03:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
2020-10-27 16:53:49 +03:00
|
|
|
|
2021-02-14 09:07:52 +03:00
|
|
|
import qualified Data.HashMap.Strict.InsOrd as OMap
|
2021-01-19 23:56:53 +03:00
|
|
|
|
2021-03-15 16:02:58 +03:00
|
|
|
import qualified Hasura.SQL.AnyBackend as AB
|
|
|
|
|
2020-10-27 16:53:49 +03:00
|
|
|
import Hasura.EncJSON
|
|
|
|
import Hasura.RQL.Types
|
2020-05-27 18:02:58 +03:00
|
|
|
|
2021-04-16 09:55:04 +03:00
|
|
|
|
2020-05-27 18:02:58 +03:00
|
|
|
runCreateRemoteRelationship
|
2021-04-22 00:44:37 +03:00
|
|
|
:: forall b m
|
2021-03-15 16:02:58 +03:00
|
|
|
. (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b)
|
|
|
|
=> RemoteRelationship b
|
|
|
|
-> m EncJSON
|
2020-12-08 17:22:31 +03:00
|
|
|
runCreateRemoteRelationship RemoteRelationship{..} = do
|
2021-04-22 00:44:37 +03:00
|
|
|
void $ askTabInfo @b rtrSource rtrTable
|
2021-03-15 16:02:58 +03:00
|
|
|
let metadataObj = MOSourceObjId rtrSource
|
|
|
|
$ AB.mkAnyBackend
|
2021-04-22 00:44:37 +03:00
|
|
|
$ SMOTableObj @b rtrTable
|
2021-03-15 16:02:58 +03:00
|
|
|
$ MTORemoteRelationship rtrName
|
2020-12-08 17:22:31 +03:00
|
|
|
metadata = RemoteRelationshipMetadata rtrName $
|
|
|
|
RemoteRelationshipDef rtrRemoteSchema rtrHasuraFields rtrRemoteField
|
|
|
|
buildSchemaCacheFor metadataObj
|
|
|
|
$ MetadataModifier
|
2021-04-22 00:44:37 +03:00
|
|
|
$ tableMetadataSetter @b rtrSource rtrTable.tmRemoteRelationships
|
2020-12-08 17:22:31 +03:00
|
|
|
%~ OMap.insert rtrName metadata
|
2020-05-27 18:02:58 +03:00
|
|
|
pure successMsg
|
|
|
|
|
2021-03-15 16:02:58 +03:00
|
|
|
runUpdateRemoteRelationship
|
2021-04-22 00:44:37 +03:00
|
|
|
:: forall b m
|
2021-03-15 16:02:58 +03:00
|
|
|
. (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b)
|
|
|
|
=> RemoteRelationship b
|
|
|
|
-> m EncJSON
|
2020-12-08 17:22:31 +03:00
|
|
|
runUpdateRemoteRelationship RemoteRelationship{..} = do
|
2021-04-22 00:44:37 +03:00
|
|
|
fieldInfoMap <- askFieldInfoMap @b rtrSource rtrTable
|
2020-12-08 17:22:31 +03:00
|
|
|
void $ askRemoteRel fieldInfoMap rtrName
|
2021-03-15 16:02:58 +03:00
|
|
|
let metadataObj = MOSourceObjId rtrSource
|
|
|
|
$ AB.mkAnyBackend
|
2021-04-22 00:44:37 +03:00
|
|
|
$ SMOTableObj @b rtrTable
|
2021-03-15 16:02:58 +03:00
|
|
|
$ MTORemoteRelationship rtrName
|
2020-12-08 17:22:31 +03:00
|
|
|
metadata = RemoteRelationshipMetadata rtrName $
|
|
|
|
RemoteRelationshipDef rtrRemoteSchema rtrHasuraFields rtrRemoteField
|
|
|
|
buildSchemaCacheFor metadataObj
|
|
|
|
$ MetadataModifier
|
2021-04-22 00:44:37 +03:00
|
|
|
$ tableMetadataSetter @b rtrSource rtrTable.tmRemoteRelationships
|
2020-12-08 17:22:31 +03:00
|
|
|
%~ OMap.insert rtrName metadata
|
2020-05-27 18:02:58 +03:00
|
|
|
pure successMsg
|
|
|
|
|
2020-12-08 17:22:31 +03:00
|
|
|
runDeleteRemoteRelationship
|
2021-04-22 00:44:37 +03:00
|
|
|
:: forall b m
|
|
|
|
. (BackendMetadata b, MonadError QErr m, CacheRWM m, MetadataM m)
|
|
|
|
=> DeleteRemoteRelationship b
|
2021-03-15 16:02:58 +03:00
|
|
|
-> m EncJSON
|
2020-12-28 15:56:00 +03:00
|
|
|
runDeleteRemoteRelationship (DeleteRemoteRelationship source table relName)= do
|
2021-04-22 00:44:37 +03:00
|
|
|
fieldInfoMap <- askFieldInfoMap @b source table
|
2020-05-27 18:02:58 +03:00
|
|
|
void $ askRemoteRel fieldInfoMap relName
|
2021-03-15 16:02:58 +03:00
|
|
|
let metadataObj = MOSourceObjId source
|
|
|
|
$ AB.mkAnyBackend
|
2021-04-22 00:44:37 +03:00
|
|
|
$ SMOTableObj @b table
|
2021-03-15 16:02:58 +03:00
|
|
|
$ MTORemoteRelationship relName
|
2020-12-08 17:22:31 +03:00
|
|
|
buildSchemaCacheFor metadataObj
|
|
|
|
$ MetadataModifier
|
2021-04-22 00:44:37 +03:00
|
|
|
$ tableMetadataSetter @b source table %~ dropRemoteRelationshipInMetadata relName
|
2020-05-27 18:02:58 +03:00
|
|
|
pure successMsg
|
|
|
|
|
2020-12-08 17:22:31 +03:00
|
|
|
dropRemoteRelationshipInMetadata
|
2021-02-14 09:07:52 +03:00
|
|
|
:: RemoteRelationshipName -> TableMetadata b -> TableMetadata b
|
2020-12-08 17:22:31 +03:00
|
|
|
dropRemoteRelationshipInMetadata name =
|
|
|
|
tmRemoteRelationships %~ OMap.delete name
|