graphql-engine/server/src-lib/Hasura/RQL/DDL/Relationship/Rename.hs
Samir Talwar 342391f39d Upgrade Ormolu to v0.5.
This upgrades the version of Ormolu required by the HGE repository to v0.5.0.1, and reformats all code accordingly.

Ormolu v0.5 reformats code that uses infix operators. This is mostly useful, adding newlines and indentation to make it clear which operators are applied first, but in some cases, it's unpleasant. To make this easier on the eyes, I had to do the following:

* Add a few fixity declarations (search for `infix`)
* Add parentheses to make precedence clear, allowing Ormolu to keep everything on one line
* Rename `relevantEq` to `(==~)` in #6651 and set it to `infix 4`
* Add a few _.ormolu_ files (thanks to @hallettj for helping me get started), mostly for Autodocodec operators that don't have explicit fixity declarations

In general, I think these changes are quite reasonable. They mostly affect indentation.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6675
GitOrigin-RevId: cd47d87f1d089fb0bc9dcbbe7798dbceedcd7d83
2022-11-02 20:55:13 +00:00

76 lines
2.1 KiB
Haskell

module Hasura.RQL.DDL.Relationship.Rename
( RenameRel,
runRenameRel,
)
where
import Data.Aeson
import Data.HashMap.Strict qualified as Map
import Data.Text.Extended
import Hasura.Base.Error
import Hasura.EncJSON
import Hasura.Prelude
import Hasura.RQL.DDL.Schema (renameRelationshipInMetadata)
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.Metadata
import Hasura.RQL.Types.Metadata.Backend
import Hasura.RQL.Types.Relationships.Local
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.SchemaCache.Build
import Hasura.RQL.Types.Table
data RenameRel b = RenameRel
{ _rrSource :: SourceName,
_rrTable :: TableName b,
_rrName :: RelName,
_rrNewName :: RelName
}
instance (Backend b) => FromJSON (RenameRel b) where
parseJSON = withObject "RenameRel" $ \o ->
RenameRel
<$> o .:? "source" .!= defaultSource
<*> o .: "table"
<*> o .: "name"
<*> o .: "new_name"
renameRelP2 ::
forall b m.
(QErrM m, CacheRM m, BackendMetadata b) =>
SourceName ->
TableName b ->
RelName ->
RelInfo b ->
m MetadataModifier
renameRelP2 source qt newRN relInfo = withNewInconsistentObjsCheck $ do
tabInfo <- askTableCoreInfo @b source qt
-- check for conflicts in fieldInfoMap
case Map.lookup (fromRel newRN) $ _tciFieldInfoMap tabInfo of
Nothing -> return ()
Just _ ->
throw400 AlreadyExists $
"cannot rename relationship "
<> oldRN
<<> " to "
<> newRN
<<> " in table "
<> qt
<<> " as a column/relationship with the name already exists"
-- update metadata
execWriterT $ renameRelationshipInMetadata @b source qt oldRN (riType relInfo) newRN
where
oldRN = riName relInfo
runRenameRel ::
forall b m.
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
RenameRel b ->
m EncJSON
runRenameRel (RenameRel source qt rn newRN) = do
tabInfo <- askTableCoreInfo @b source qt
ri <- askRelType (_tciFieldInfoMap tabInfo) rn ""
withNewInconsistentObjsCheck $
renameRelP2 source qt newRN ri >>= buildSchemaCache
pure successMsg