2021-01-29 04:02:34 +03:00
|
|
|
module Hasura.RQL.DDL.Endpoint
|
2021-09-24 01:56:37 +03:00
|
|
|
( runCreateEndpoint,
|
|
|
|
runDropEndpoint,
|
|
|
|
dropEndpointInMetadata,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
|
|
|
import Data.Text.Extended
|
|
|
|
import Hasura.Base.Error
|
|
|
|
import Hasura.EncJSON
|
|
|
|
import Hasura.Metadata.Class
|
|
|
|
import Hasura.Prelude
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Common
|
2022-03-13 10:40:06 +03:00
|
|
|
import Hasura.RQL.Types.Endpoint
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Metadata
|
|
|
|
import Hasura.RQL.Types.Metadata.Object
|
|
|
|
import Hasura.RQL.Types.SchemaCache.Build
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
|
|
runCreateEndpoint ::
|
|
|
|
( CacheRWM m,
|
|
|
|
MetadataM m,
|
|
|
|
MonadMetadataStorageQueryAPI m
|
|
|
|
) =>
|
|
|
|
CreateEndpoint ->
|
|
|
|
m EncJSON
|
|
|
|
runCreateEndpoint endpoint@EndpointMetadata {..} = do
|
2021-01-29 04:02:34 +03:00
|
|
|
endpointsMap <- _metaRestEndpoints <$> getMetadata
|
|
|
|
|
|
|
|
OMap.lookup _ceName endpointsMap `for_` \_ ->
|
2021-09-24 01:56:37 +03:00
|
|
|
throw400 AlreadyExists $
|
|
|
|
"Endpoint with name: " <> toTxt _ceName <> " already exists"
|
2021-01-29 04:02:34 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
withNewInconsistentObjsCheck $
|
|
|
|
buildSchemaCacheFor (MOEndpoint _ceName) $
|
|
|
|
MetadataModifier $
|
|
|
|
metaRestEndpoints %~ OMap.insert _ceName endpoint
|
2021-01-29 04:02:34 +03:00
|
|
|
return successMsg
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runDropEndpoint ::
|
|
|
|
( CacheRWM m,
|
|
|
|
MetadataM m,
|
|
|
|
MonadMetadataStorageQueryAPI m
|
|
|
|
) =>
|
|
|
|
DropEndpoint ->
|
|
|
|
m EncJSON
|
|
|
|
runDropEndpoint DropEndpoint {..} = do
|
2021-01-29 04:02:34 +03:00
|
|
|
checkExists _deName
|
2021-09-24 01:56:37 +03:00
|
|
|
withNewInconsistentObjsCheck $
|
|
|
|
buildSchemaCache $
|
|
|
|
dropEndpointInMetadata _deName
|
2021-01-29 04:02:34 +03:00
|
|
|
return successMsg
|
|
|
|
|
|
|
|
dropEndpointInMetadata :: EndpointName -> MetadataModifier
|
|
|
|
dropEndpointInMetadata name =
|
|
|
|
MetadataModifier $ metaRestEndpoints %~ OMap.delete name
|
|
|
|
|
|
|
|
checkExists :: (MetadataM m, MonadError QErr m) => EndpointName -> m ()
|
|
|
|
checkExists name = do
|
|
|
|
endpointsMap <- _metaRestEndpoints <$> getMetadata
|
2021-09-24 01:56:37 +03:00
|
|
|
void $
|
|
|
|
onNothing (OMap.lookup name endpointsMap) $
|
|
|
|
throw400 NotExists $
|
|
|
|
"endpoint with name: " <> toTxt name <> " does not exist"
|