graphql-engine/server/src-lib/Hasura/GraphQL/Context.hs
Karthikeyan Chinnakonda 2325755954 server: streaming subscriptions schema generation and tests (incremental PR - 3)
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4259
Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
Co-authored-by: Brandon Simmons <210815+jberryman@users.noreply.github.com>
Co-authored-by: paritosh-08 <85472423+paritosh-08@users.noreply.github.com>
GitOrigin-RevId: 4d1b4ec3c01f3a839f4392d3b77950fc3ab30236
2022-04-22 19:54:11 +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
-- 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 UnpreparedValue)),
gqlMutationParser :: Maybe (ParserFn (RootFieldMap (IR.MutationRootField UnpreparedValue))),
gqlSubscriptionParser :: Maybe (ParserFn (RootFieldMap (IR.QueryRootField 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