mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
da8f6981d4
Fixes https://github.com/hasura/graphql-engine-mono/issues/712 Main point of interest: the `Hasura.SQL.Backend` module. This PR creates an `Exists` type indexed by indexed type and packed constraint while hiding all of its complexity by not exporting the constructor. Existential constructors/types which are no longer (directly) existential: - [X] BackendSourceInfo :: BackendSourceInfo - [x] BackendSourceMetadata :: BackendSourceMetadata - [x] MOSourceObjId :: MetadatObjId - [x] SOSourceObj :: SchemaObjId - [x] RFDB :: RootField - [x] LQP :: LiveQueryPlan - [x] ExecutionStep :: ExecStepDB This PR also removes ALL usages of `Typeable.cast` from our codebase. We still need to derive `Typeable` in a few places in order to be able to derive `Data` in one place. I have not dug deeper to see why this is needed. GitOrigin-RevId: bb47e957192e4bb0af4c4116aee7bb92f7983445
77 lines
2.7 KiB
Haskell
77 lines
2.7 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 qualified Hasura.SQL.AnyBackend as AB
|
|
|
|
import Hasura.EncJSON
|
|
import Hasura.RQL.Types
|
|
|
|
runCreateRemoteRelationship
|
|
:: forall m b
|
|
. (MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b)
|
|
=> RemoteRelationship b
|
|
-> m EncJSON
|
|
runCreateRemoteRelationship RemoteRelationship{..} = do
|
|
void $ askTabInfo rtrSource rtrTable
|
|
let metadataObj = MOSourceObjId rtrSource
|
|
$ AB.mkAnyBackend
|
|
$ 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
|
|
:: forall m b
|
|
. (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
|
|
$ AB.mkAnyBackend
|
|
$ 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
|
|
$ AB.mkAnyBackend
|
|
$ 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
|