graphql-engine/server/src-lib/Hasura/GraphQL/Context.hs
Naveen Naidu 11867b50a4 server: extend backend_only setting for update and delete permissions
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4530
Co-authored-by: Karthikeyan Chinnakonda <15602904+codingkarthik@users.noreply.github.com>
Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
GitOrigin-RevId: c4c1a3bd9736ec275e77c6f55c76049c550443f9
2022-05-31 14:42:14 +00:00

43 lines
1.3 KiB
Haskell

{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Context
( RoleContext (..),
GQLContext (..),
ParserFn,
)
where
import Data.Aeson qualified as J
import Data.Aeson.TH
import Hasura.GraphQL.Namespace
import Hasura.GraphQL.Parser
import Hasura.Prelude
import Hasura.RQL.IR qualified as IR
import Language.GraphQL.Draft.Syntax qualified as G
-- | For storing both a normal GQLContext and one for the backend variant.
-- Currently, this is to enable the backend variant to have certain insert/update/delete
-- permissions which the frontend variant does not.
data RoleContext a = RoleContext
{ -- | The default context for normal sessions
_rctxDefault :: !a,
-- | The context for sessions with backend privilege.
_rctxBackend :: !(Maybe a)
}
deriving (Show, Eq, Functor, Foldable, Traversable)
$(deriveToJSON hasuraJSON ''RoleContext)
data GQLContext = GQLContext
{ gqlQueryParser :: ParserFn (RootFieldMap (IR.QueryRootField IR.UnpreparedValue)),
gqlMutationParser :: Maybe (ParserFn (RootFieldMap (IR.MutationRootField IR.UnpreparedValue))),
gqlSubscriptionParser :: Maybe (ParserFn (RootFieldMap (IR.QueryRootField IR.UnpreparedValue)))
}
instance J.ToJSON GQLContext where
toJSON GQLContext {} = J.String "The GraphQL schema parsers"
type ParserFn a =
G.SelectionSet G.NoFragments Variable ->
Either (NESeq ParseError) a