Skip to content

Commit

Permalink
remove hasura_fields from API
Browse files Browse the repository at this point in the history
  • Loading branch information
tirumaraiselvan committed Oct 8, 2019
1 parent 9433aa5 commit 2d9b323
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 48 deletions.
27 changes: 26 additions & 1 deletion server/src-lib/Hasura/RQL/DDL/RemoteRelationship/Validate.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}

-- | Validate input queries against remote schemas.
Expand All @@ -21,6 +23,7 @@ import Hasura.SQL.Types

import qualified Data.HashMap.Strict as HM
import qualified Data.List.NonEmpty as NE
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Hasura.GraphQL.Context as GC
import qualified Language.GraphQL.Draft.Syntax as G
Expand Down Expand Up @@ -57,7 +60,7 @@ validateRelationship remoteRel rGCtx tableInfo = do
fieldInfos <-
fmap
HM.fromList
(flip traverse (toList (rrHasuraFields remoteRel)) $ \fieldName ->
(flip traverse (Set.toList $ extractVariables remoteRel) $ \fieldName ->
case HM.lookup fieldName (_tiFieldInfoMap tableInfo) of
Nothing -> Left . pure $ TableFieldNotFound tableName fieldName
Just fieldInfo -> pure (fieldName, fieldInfo))
Expand Down Expand Up @@ -129,6 +132,28 @@ validateRelationship remoteRel rGCtx tableInfo = do
typeMap)
pure (objFldInfo, (newParamMap, newTypeMap))

extractVariables :: RemoteRelationship -> Set.Set FieldName
extractVariables RemoteRelationship {rrRemoteFields} =
foldl' accumVariables Set.empty rrRemoteFields
where
accumVariables accumSet FieldCall {..} =
let tableFields =
map
(getVariablesFromValue . G._ofValue)
(getRemoteArguments fcArguments)
tableFieldSet = Set.fromList $ concat tableFields
in Set.union accumSet tableFieldSet
getVariablesFromValue :: G.Value -> [FieldName]
getVariablesFromValue gValue =
case gValue of
G.VVariable (G.Variable v) -> [fromName v]
G.VList (G.ListValueG list) -> concat $ map getVariablesFromValue list
G.VObject (G.ObjectValueG kv) ->
concat $ map (getVariablesFromValue . G._ofValue) kv
_ -> []
where
fromName (G.Name name) = FieldName name

-- Return a new param map with keys deleted from join arguments
stripInMap ::
RemoteRelationship
Expand Down
9 changes: 3 additions & 6 deletions server/src-lib/Hasura/RQL/Types/RemoteRelationship.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Data.Aeson.Casing
import Data.Aeson.TH
import Hasura.Prelude
import Hasura.RQL.Instances ()
import Hasura.RQL.Types.Common
import Hasura.SQL.Types

import Data.Aeson as A
Expand All @@ -24,7 +23,6 @@ import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import Data.List.NonEmpty (NonEmpty (..))
import Data.Scientific
import Data.Set (Set)

import qualified Data.Text as T
import qualified Database.PG.Query as Q
Expand All @@ -48,7 +46,6 @@ data RemoteRelationship =
RemoteRelationship
{ rrName :: RemoteRelationshipName
, rrTable :: QualifiedTable
, rrHasuraFields :: Set FieldName -- change to PGCol
, rrRemoteSchema :: RemoteSchemaName
, rrRemoteFields :: NonEmpty FieldCall
} deriving (Show, Eq, Lift)
Expand Down Expand Up @@ -107,9 +104,11 @@ parseRemoteArguments j =
A.Object hashMap -> fmap RemoteArguments (parseObjectFieldsToGValue hashMap)
_ -> fail "Remote arguments should be an object of keys."


-- G.ObjectField has the right representation but may not be the best name for this type as RemoteArgument might be scalar
newtype RemoteArguments =
RemoteArguments
{ getRemoteArguments :: [G.ObjectFieldG G.Value]
{ getRemoteArguments :: [G.ObjectField]
} deriving (Show, Eq, Lift)

instance ToJSON RemoteArguments where
Expand Down Expand Up @@ -143,7 +142,6 @@ instance ToJSON RemoteRelationship where
object
[ "name" .= rrName
, "table" .= rrTable
, "hasura_fields" .= rrHasuraFields
, "remote_schema" .= rrRemoteSchema
, "remote_field" .= remoteFieldsJson rrRemoteFields
]
Expand All @@ -153,7 +151,6 @@ instance FromJSON RemoteRelationship where
o <- parseJSON value
rrName <- o .: "name"
rrTable <- o .: "table"
rrHasuraFields <- o .: "hasura_fields"
rrRemoteSchema <- o .: "remote_schema"
rrRemoteFields <- o .: "remote_field" >>= parseRemoteFields
pure RemoteRelationship {..}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: messages
table: profiles
hasura_fields:
- id
remote_schema: my-remote-schema
remote_field:
messages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: InvalidHasuraField
table: profiles
hasura_fields:
- id_wrong
remote_schema: user
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ type: create_remote_relationship
args:
name: message
table: profiles
hasura_fields:
- id
- name
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_messages_by_pk:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: messagesNested
table: profiles
hasura_fields:
- id
remote_schema: my-remote-schema
remote_field:
messages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: invalRemoteArg
table: profiles
hasura_fields:
- id
remote_schema: user
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: invalideRemoteFld
table: profiles
hasura_fields:
- id
remote_schema: user
remote_field:
user_wrong:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: invalidRemoteSchema
table: profiles
hasura_fields:
- id
remote_schema: user-wrong
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: invalideRemoteRelType
table: profiles
hasura_fields:
- id
remote_schema: user
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: invalidVariable
table: profiles
hasura_fields:
- id
remote_schema: user
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ type: create_remote_relationship
args:
name: messagesMultiFields
table: authors
hasura_fields:
- user_id
- alias
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_messages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: usersNestedArr
table: messages
hasura_fields:
- profile_id
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_users:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: userBasic
table: profiles
hasura_fields:
- id
remote_schema: user
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ type: create_remote_relationship
args:
name: messagesAndBoolExp
table: authors
hasura_fields:
- user_id
- alias
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_messages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ query:
args:
name: userBasic
table: profiles
hasura_fields:
- id
remote_schema: user
remote_field:
user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ args:
field:
profile:
arguments: {}
hasura_fields:
- author_id
- id
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ type: create_remote_relationship
args:
name: messagesMultipleFields
table: authors
hasura_fields:
- user_id
- alias
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_messages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: usersNestedArgs
table: profiles
hasura_fields:
- id
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_users:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type: create_remote_relationship
args:
name: authorsNestedMessages
table: authors
hasura_fields:
- user_id
remote_schema: prefixer-proxy
remote_field:
prefixer_proxy_profiles_by_pk:
Expand Down

0 comments on commit 2d9b323

Please sign in to comment.