Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote relationship create api #2850

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/graphql-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ library
, wai
, postgresql-binary
, process
, validation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monad-validate might remove some boilerplate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing this and TBH it didn't make much of a difference. So just leaving this as is atm.


-- Encoder related
, uuid
Expand Down Expand Up @@ -184,6 +185,7 @@ library
, Hasura.RQL.Types.Permission
, Hasura.RQL.Types.QueryCollection
, Hasura.RQL.Types.RemoteSchema
, Hasura.RQL.Types.RemoteRelationship
, Hasura.RQL.DDL.Deps
, Hasura.RQL.DDL.Permission.Internal
, Hasura.RQL.DDL.Permission.Triggers
Expand All @@ -204,6 +206,8 @@ library
, Hasura.RQL.DDL.EventTrigger
, Hasura.RQL.DDL.Headers
, Hasura.RQL.DDL.RemoteSchema
, Hasura.RQL.DDL.RemoteRelationship
, Hasura.RQL.DDL.RemoteRelationship.Validate
, Hasura.RQL.DDL.QueryCollection
, Hasura.RQL.DML.Delete
, Hasura.RQL.DML.Internal
Expand Down
42 changes: 42 additions & 0 deletions server/src-lib/Hasura/RQL/DDL/RemoteRelationship.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{-# LANGUAGE ViewPatterns #-}

module Hasura.RQL.DDL.RemoteRelationship
( runCreateRemoteRelationship
, runCreateRemoteRelationshipP1
)
where

import Hasura.GraphQL.Validate.Types

import Hasura.EncJSON
import Hasura.Prelude
import Hasura.RQL.DDL.RemoteRelationship.Validate
import Hasura.RQL.Types

import qualified Data.HashMap.Strict as HM
import qualified Data.Text as T
import Instances.TH.Lift ()

runCreateRemoteRelationship ::
(MonadTx m, CacheRWM m, UserInfoM m) => RemoteRelationship -> m EncJSON
runCreateRemoteRelationship remoteRelationship = do
adminOnly
(_remoteField, _additionalTypesMap) <-
runCreateRemoteRelationshipP1 remoteRelationship
pure successMsg

runCreateRemoteRelationshipP1 ::
(MonadTx m, CacheRM m) => RemoteRelationship -> m (RemoteField, TypeMap)
runCreateRemoteRelationshipP1 remoteRelationship = do
sc <- askSchemaCache
case HM.lookup
(rtrRemoteSchema remoteRelationship)
(scRemoteSchemas sc) of
Just {} -> do
validation <-
getCreateRemoteRelationshipValidation remoteRelationship
case validation of
Left err -> throw400 RemoteSchemaError (T.pack (show err))
Right (remoteField, additionalTypesMap) ->
pure (remoteField, additionalTypesMap)
Nothing -> throw400 RemoteSchemaError "No such remote schema"
Loading