2021-11-04 19:08:33 +03:00
|
|
|
module Hasura.GraphQL.Execute.Common
|
|
|
|
( MonadGQLExecutionCheck (..),
|
|
|
|
)
|
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-06-11 06:26:50 +03:00
|
|
|
import Data.Aeson.Ordered qualified as JO
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Base.Error
|
2021-06-11 06:26:50 +03:00
|
|
|
import Hasura.GraphQL.Execute.Backend
|
2021-05-05 15:25:27 +03:00
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
2020-11-18 21:04:57 +03:00
|
|
|
import Hasura.Prelude
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.GraphqlSchemaIntrospection
|
|
|
|
import Hasura.RQL.Types.SchemaCache
|
2023-02-08 06:35:19 +03:00
|
|
|
import Hasura.Server.Init (AllowListStatus)
|
2022-04-05 10:18:21 +03:00
|
|
|
import Hasura.Server.Types (RequestId)
|
2020-11-18 21:04:57 +03:00
|
|
|
import Hasura.Session
|
2021-06-11 06:26:50 +03:00
|
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
import Network.HTTP.Types qualified as HTTP
|
|
|
|
import Network.Wai.Extended qualified as Wai
|
2020-11-18 21:04:57 +03:00
|
|
|
|
2021-05-05 15:25:27 +03:00
|
|
|
-- | Typeclass representing safety checks (if any) that need to be performed
|
|
|
|
-- before a GraphQL query should be allowed to be executed. In OSS, the safety
|
|
|
|
-- check is to check in the query is in the allow list.
|
|
|
|
--
|
|
|
|
-- the `executeIntrospection` function has different implementations in OSS and
|
|
|
|
-- Pro. In Pro, the GraphQL schema introspection can be disabled for specified
|
|
|
|
-- roles and in OSS there is no restrictions.
|
|
|
|
--
|
|
|
|
-- | TODO (from master): Limitation: This parses the query, which is not ideal if we already
|
|
|
|
-- have the query cached. The parsing happens unnecessary. But getting this to
|
|
|
|
-- either return a plan or parse was tricky and complicated.
|
|
|
|
class Monad m => MonadGQLExecutionCheck m where
|
|
|
|
checkGQLExecution ::
|
|
|
|
UserInfo ->
|
|
|
|
([HTTP.Header], Wai.IpAddress) ->
|
|
|
|
-- | allow list enabled?
|
2023-02-08 06:35:19 +03:00
|
|
|
AllowListStatus ->
|
2021-05-05 15:25:27 +03:00
|
|
|
-- | needs allow list
|
|
|
|
SchemaCache ->
|
|
|
|
-- | the unparsed GraphQL query string (and related values)
|
|
|
|
GQLReqUnparsed ->
|
2022-04-05 10:18:21 +03:00
|
|
|
RequestId ->
|
2021-05-05 15:25:27 +03:00
|
|
|
m (Either QErr GQLReqParsed)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-05-05 15:25:27 +03:00
|
|
|
executeIntrospection ::
|
|
|
|
UserInfo ->
|
2021-05-19 19:37:47 +03:00
|
|
|
JO.Value ->
|
2021-05-05 15:25:27 +03:00
|
|
|
SetGraphqlIntrospectionOptions ->
|
|
|
|
m (Either QErr ExecutionStep)
|
|
|
|
|
2022-10-13 19:50:05 +03:00
|
|
|
checkGQLBatchedReqs ::
|
|
|
|
UserInfo ->
|
|
|
|
RequestId ->
|
|
|
|
[GQLReq GQLQueryText] ->
|
|
|
|
SchemaCache ->
|
|
|
|
m (Either QErr ())
|
|
|
|
|
2021-05-05 15:25:27 +03:00
|
|
|
instance MonadGQLExecutionCheck m => MonadGQLExecutionCheck (ReaderT r m) where
|
2022-04-05 10:18:21 +03:00
|
|
|
checkGQLExecution ui det enableAL sc req requestId =
|
|
|
|
lift $ checkGQLExecution ui det enableAL sc req requestId
|
2021-05-05 15:25:27 +03:00
|
|
|
|
|
|
|
executeIntrospection userInfo introspectionQuery rolesDisabled =
|
|
|
|
lift $ executeIntrospection userInfo introspectionQuery rolesDisabled
|
|
|
|
|
2022-10-13 19:50:05 +03:00
|
|
|
checkGQLBatchedReqs userInfo requestId reqs sc =
|
|
|
|
lift $ checkGQLBatchedReqs userInfo requestId reqs sc
|
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance MonadGQLExecutionCheck m => MonadGQLExecutionCheck (ExceptT e m) where
|
2022-04-05 10:18:21 +03:00
|
|
|
checkGQLExecution ui det enableAL sc req requestId =
|
|
|
|
lift $ checkGQLExecution ui det enableAL sc req requestId
|
2021-05-05 15:25:27 +03:00
|
|
|
|
|
|
|
executeIntrospection userInfo introspectionQuery rolesDisabled =
|
|
|
|
lift $ executeIntrospection userInfo introspectionQuery rolesDisabled
|
|
|
|
|
2022-10-13 19:50:05 +03:00
|
|
|
checkGQLBatchedReqs userInfo requestId reqs sc =
|
|
|
|
lift $ checkGQLBatchedReqs userInfo requestId reqs sc
|
|
|
|
|
2023-02-03 04:03:23 +03:00
|
|
|
instance MonadGQLExecutionCheck m => MonadGQLExecutionCheck (Tracing.TraceT m) where
|
2022-04-05 10:18:21 +03:00
|
|
|
checkGQLExecution ui det enableAL sc req requestId =
|
|
|
|
lift $ checkGQLExecution ui det enableAL sc req requestId
|
2021-05-05 15:25:27 +03:00
|
|
|
|
|
|
|
executeIntrospection userInfo introspectionQuery rolesDisabled =
|
|
|
|
lift $ executeIntrospection userInfo introspectionQuery rolesDisabled
|
2022-10-13 19:50:05 +03:00
|
|
|
|
|
|
|
checkGQLBatchedReqs userInfo requestId reqs sc =
|
|
|
|
lift $ checkGQLBatchedReqs userInfo requestId reqs sc
|