mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
d52bfcda4e
* move user info related code to Hasura.User module
* the RFC #4120 implementation; insert permissions with admin secret
* revert back to old RoleName based schema maps
An attempt made to avoid duplication of schema contexts in types
if any role doesn't possess any admin secret specific schema
* fix compile errors in haskell test
* keep 'user_vars' for session variables in http-logs
* no-op refacto
* tests for admin only inserts
* update docs for admin only inserts
* updated CHANGELOG.md
* default behaviour when admin secret is not set
* fix x-hasura-role to X-Hasura-Role in pytests
* introduce effective timeout in actions async tests
* update docs for admin-secret not configured case
* Update docs/graphql/manual/api-reference/schema-metadata-api/permission.rst
Co-Authored-By: Marion Schleifer <marion@hasura.io>
* Apply suggestions from code review
Co-Authored-By: Marion Schleifer <marion@hasura.io>
* a complete iteration
backend insert permissions accessable via 'x-hasura-backend-privilege'
session variable
* console changes for backend-only permissions
* provide tooltip id; update labels and tooltips;
* requested changes
* requested changes
- remove className from Toggle component
- use appropriate function name (capitalizeFirstChar -> capitalize)
* use toggle props from definitelyTyped
* fix accidental commit
* Revert "introduce effective timeout in actions async tests"
This reverts commit b7a59c19d6
.
* generate complete schema for both 'default' and 'backend' sessions
* Apply suggestions from code review
Co-Authored-By: Marion Schleifer <marion@hasura.io>
* remove unnecessary import, export Toggle as is
* update session variable in tooltip
* 'x-hasura-use-backend-only-permissions' variable to switch
* update help texts
* update docs
* update docs
* update console help text
* regenerate package-lock
* serve no backend schema when backend_only: false and header set to true
- Few type name refactor as suggested by @0x777
* update CHANGELOG.md
* Update CHANGELOG.md
* Update CHANGELOG.md
* fix a merge bug where a certain entity didn't get removed
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Rishichandra Wawhal <rishi@hasura.io>
Co-authored-by: rikinsk <rikin.kachhia@gmail.com>
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
99 lines
2.8 KiB
Haskell
99 lines
2.8 KiB
Haskell
module Hasura.GraphQL.Execute.Plan
|
|
( ReusablePlan(..)
|
|
, PlanCache
|
|
, PlanCacheOptions
|
|
, mkPlanCacheOptions
|
|
, getPlan
|
|
, addPlan
|
|
, initPlanCache
|
|
, clearPlanCache
|
|
, dumpPlanCache
|
|
) where
|
|
|
|
import Hasura.Prelude
|
|
import Hasura.Session
|
|
|
|
import qualified Data.Aeson as J
|
|
import qualified Data.Aeson.Casing as J
|
|
import qualified Data.Aeson.TH as J
|
|
|
|
import qualified Hasura.Cache as Cache
|
|
import qualified Hasura.GraphQL.Execute.LiveQuery as LQ
|
|
import qualified Hasura.GraphQL.Execute.Query as EQ
|
|
import qualified Hasura.GraphQL.Transport.HTTP.Protocol as GH
|
|
import Hasura.RQL.Types
|
|
|
|
data PlanId
|
|
= PlanId
|
|
{ _piSchemaCacheVersion :: !SchemaCacheVer
|
|
, _piRole :: !RoleName
|
|
, _piOperationName :: !(Maybe GH.OperationName)
|
|
, _piQuery :: !GH.GQLQueryText
|
|
} deriving (Show, Eq, Ord, Generic)
|
|
|
|
instance Hashable PlanId
|
|
|
|
instance J.ToJSON PlanId where
|
|
toJSON (PlanId scVer rn opNameM query) =
|
|
J.object
|
|
[ "schema_cache_version" J..= scVer
|
|
, "role" J..= rn
|
|
, "operation" J..= opNameM
|
|
, "query" J..= query
|
|
]
|
|
|
|
newtype PlanCache
|
|
= PlanCache {_unPlanCache :: Cache.Cache PlanId ReusablePlan}
|
|
|
|
data ReusablePlan
|
|
= RPQuery !EQ.ReusableQueryPlan
|
|
| RPSubs !LQ.ReusableLiveQueryPlan
|
|
|
|
instance J.ToJSON ReusablePlan where
|
|
toJSON = \case
|
|
RPQuery queryPlan -> J.toJSON queryPlan
|
|
RPSubs subsPlan -> J.toJSON subsPlan
|
|
|
|
newtype PlanCacheOptions
|
|
= PlanCacheOptions { unPlanCacheSize :: Maybe Cache.CacheSize }
|
|
deriving (Show, Eq)
|
|
$(J.deriveJSON (J.aesonDrop 2 J.snakeCase) ''PlanCacheOptions)
|
|
|
|
mkPlanCacheOptions :: Maybe Cache.CacheSize -> PlanCacheOptions
|
|
mkPlanCacheOptions = PlanCacheOptions
|
|
|
|
initPlanCache :: PlanCacheOptions -> IO PlanCache
|
|
initPlanCache options =
|
|
PlanCache <$>
|
|
Cache.initialise (Cache.mkCacheOptions $ unPlanCacheSize options)
|
|
|
|
getPlan
|
|
:: SchemaCacheVer -> RoleName -> Maybe GH.OperationName -> GH.GQLQueryText
|
|
-> PlanCache -> IO (Maybe ReusablePlan)
|
|
getPlan schemaVer rn opNameM q (PlanCache planCache) =
|
|
Cache.lookup planId planCache
|
|
where
|
|
planId = PlanId schemaVer rn opNameM q
|
|
|
|
addPlan
|
|
:: SchemaCacheVer -> RoleName -> Maybe GH.OperationName -> GH.GQLQueryText
|
|
-> ReusablePlan -> PlanCache -> IO ()
|
|
addPlan schemaVer rn opNameM q queryPlan (PlanCache planCache) =
|
|
Cache.insert planId queryPlan planCache
|
|
where
|
|
planId = PlanId schemaVer rn opNameM q
|
|
|
|
clearPlanCache :: PlanCache -> IO ()
|
|
clearPlanCache (PlanCache planCache) =
|
|
Cache.clear planCache
|
|
|
|
dumpPlanCache :: PlanCache -> IO J.Value
|
|
dumpPlanCache (PlanCache cache) =
|
|
J.toJSON . map (map dumpEntry) <$> Cache.getEntries cache
|
|
where
|
|
dumpEntry (planId, plan) =
|
|
J.object
|
|
[ "id" J..= planId
|
|
, "plan" J..= plan
|
|
]
|