graphql-engine/server/src-lib/Hasura/GraphQL/Execute/Remote.hs
Karthikeyan Chinnakonda 3ea611f9fd
Server: Validate remote schema queries (#5938)
* [skip ci] use the args while making the fieldParser

* modify the execution part of the remote queries

* parse union queries deeply

* add test for remote schema field validation

* add tests for validating remote query arguments


Co-authored-by: Auke Booij <auke@hasura.io>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-13 14:03:11 +05:30

37 lines
1.2 KiB
Haskell

module Hasura.GraphQL.Execute.Remote
( buildExecStepRemote
) where
import Hasura.Prelude
import qualified Data.HashMap.Strict as Map
import qualified Language.GraphQL.Draft.Syntax as G
import qualified Data.HashSet as Set
import qualified Hasura.GraphQL.Transport.HTTP.Protocol as GH
import Hasura.GraphQL.Execute.Prepare
import Hasura.RQL.Types
collectVariables
:: forall fragments var
. (Foldable fragments, Hashable var, Eq var)
=> G.SelectionSet fragments var
-> Set.HashSet var
collectVariables =
Set.unions . fmap (foldMap Set.singleton)
buildExecStepRemote
:: forall db
. RemoteSchemaInfo
-> G.OperationType
-> [G.VariableDefinition]
-> G.SelectionSet G.NoFragments G.Name
-> Maybe GH.VariableValues
-> ExecutionStep db
buildExecStepRemote remoteSchemaInfo tp varDefs selSet varValsM =
let requiredVars = collectVariables selSet
restrictedDefs = filter (\varDef -> G._vdName varDef `Set.member` requiredVars) varDefs
restrictedValsM = flip Map.intersection (Set.toMap requiredVars) <$> varValsM
in ExecStepRemote (remoteSchemaInfo, G.TypedOperationDefinition tp Nothing restrictedDefs [] selSet, restrictedValsM)