graphql-engine/server/src-lib/Hasura/RQL/DDL/RemoteRelationship.hs
Rakesh Emmadi 9ef603360c server: generalize schema cache building (#496)
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Vladimir Ciobanu <admin@cvlad.info>
Co-authored-by: Antoine Leblanc <antoine@hasura.io>
Co-authored-by: Stylish Haskell Bot <stylish-haskell@users.noreply.github.com>
GitOrigin-RevId: 9d631878037637f3ed2994b5d0525efd978f7b8f
2021-02-14 06:08:46 +00:00

60 lines
2.4 KiB
Haskell

{-# LANGUAGE RecordWildCards #-}
module Hasura.RQL.DDL.RemoteRelationship
( runCreateRemoteRelationship
, runDeleteRemoteRelationship
, runUpdateRemoteRelationship
, dropRemoteRelationshipInMetadata
) where
import Hasura.Prelude
import qualified Data.HashMap.Strict.InsOrd as OMap
import Hasura.EncJSON
import Hasura.RQL.Types
runCreateRemoteRelationship
:: (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) => RemoteRelationship b -> m EncJSON
runCreateRemoteRelationship RemoteRelationship{..} = do
void $ askTabInfo rtrSource rtrTable
let metadataObj = MOSourceObjId rtrSource $
SMOTableObj rtrTable $ MTORemoteRelationship rtrName
metadata = RemoteRelationshipMetadata rtrName $
RemoteRelationshipDef rtrRemoteSchema rtrHasuraFields rtrRemoteField
buildSchemaCacheFor metadataObj
$ MetadataModifier
$ tableMetadataSetter rtrSource rtrTable.tmRemoteRelationships
%~ OMap.insert rtrName metadata
pure successMsg
runUpdateRemoteRelationship :: (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) => RemoteRelationship b -> m EncJSON
runUpdateRemoteRelationship RemoteRelationship{..} = do
fieldInfoMap <- askFieldInfoMap rtrSource rtrTable
void $ askRemoteRel fieldInfoMap rtrName
let metadataObj = MOSourceObjId rtrSource $
SMOTableObj rtrTable $ MTORemoteRelationship rtrName
metadata = RemoteRelationshipMetadata rtrName $
RemoteRelationshipDef rtrRemoteSchema rtrHasuraFields rtrRemoteField
buildSchemaCacheFor metadataObj
$ MetadataModifier
$ tableMetadataSetter rtrSource rtrTable.tmRemoteRelationships
%~ OMap.insert rtrName metadata
pure successMsg
runDeleteRemoteRelationship
:: (MonadError QErr m, CacheRWM m, MetadataM m) => DeleteRemoteRelationship -> m EncJSON
runDeleteRemoteRelationship (DeleteRemoteRelationship source table relName)= do
fieldInfoMap <- askFieldInfoMap source table
void $ askRemoteRel fieldInfoMap relName
let metadataObj = MOSourceObjId source $
SMOTableObj table $ MTORemoteRelationship relName
buildSchemaCacheFor metadataObj
$ MetadataModifier
$ tableMetadataSetter source table %~ dropRemoteRelationshipInMetadata relName
pure successMsg
dropRemoteRelationshipInMetadata
:: RemoteRelationshipName -> TableMetadata b -> TableMetadata b
dropRemoteRelationshipInMetadata name =
tmRemoteRelationships %~ OMap.delete name