2021-09-24 01:56:37 +03:00
|
|
|
|
{-# LANGUAGE Arrows #-}
|
|
|
|
|
{-# LANGUAGE OverloadedLabels #-}
|
2020-12-28 15:56:00 +03:00
|
|
|
|
{-# LANGUAGE UndecidableInstances #-}
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
-- | Top-level functions concerned specifically with operations on the schema cache, such as
|
|
|
|
|
-- rebuilding it from the catalog and incorporating schema changes. See the module documentation for
|
|
|
|
|
-- "Hasura.RQL.DDL.Schema" for more details.
|
|
|
|
|
--
|
|
|
|
|
-- __Note__: this module is __mutually recursive__ with other @Hasura.RQL.DDL.Schema.*@ modules, which
|
|
|
|
|
-- both define pieces of the implementation of building the schema cache and define handlers that
|
|
|
|
|
-- trigger schema cache rebuilds.
|
2019-08-14 02:34:37 +03:00
|
|
|
|
module Hasura.RQL.DDL.Schema.Cache
|
2021-09-24 01:56:37 +03:00
|
|
|
|
( RebuildableSchemaCache,
|
|
|
|
|
lastBuiltSchemaCache,
|
|
|
|
|
buildRebuildableSchemaCache,
|
|
|
|
|
buildRebuildableSchemaCacheWithReason,
|
|
|
|
|
CacheRWT,
|
|
|
|
|
runCacheRWT,
|
|
|
|
|
mkBooleanPermissionMap,
|
|
|
|
|
)
|
|
|
|
|
where
|
|
|
|
|
|
|
|
|
|
import Control.Arrow.Extended
|
2021-11-09 17:21:48 +03:00
|
|
|
|
import Control.Concurrent.Async.Lifted.Safe qualified as LA
|
2021-09-24 01:56:37 +03:00
|
|
|
|
import Control.Lens hiding ((.=))
|
|
|
|
|
import Control.Monad.Trans.Control (MonadBaseControl)
|
|
|
|
|
import Control.Retry qualified as Retry
|
|
|
|
|
import Data.Aeson
|
|
|
|
|
import Data.Align (align)
|
|
|
|
|
import Data.Dependent.Map qualified as DMap
|
|
|
|
|
import Data.Either (isLeft)
|
|
|
|
|
import Data.Environment qualified as Env
|
|
|
|
|
import Data.HashMap.Strict.Extended qualified as M
|
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
|
|
|
|
import Data.HashSet qualified as HS
|
|
|
|
|
import Data.Proxy
|
|
|
|
|
import Data.Set qualified as S
|
|
|
|
|
import Data.Text.Extended
|
|
|
|
|
import Data.These (These (..))
|
|
|
|
|
import Data.Time.Clock (getCurrentTime)
|
|
|
|
|
import Database.PG.Query qualified as Q
|
|
|
|
|
import Hasura.Backends.Postgres.Connection
|
2021-11-09 17:21:48 +03:00
|
|
|
|
import Hasura.Backends.Postgres.DDL.Source (initCatalogForSource, logPGSourceCatalogMigrationLockedQueries)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
import Hasura.Base.Error
|
|
|
|
|
import Hasura.GraphQL.Execute.Types
|
2022-02-08 07:46:57 +03:00
|
|
|
|
import Hasura.GraphQL.RemoteServer (getSchemaIntrospection)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
import Hasura.GraphQL.Schema (buildGQLContext)
|
|
|
|
|
import Hasura.Incremental qualified as Inc
|
2021-11-09 17:21:48 +03:00
|
|
|
|
import Hasura.Logging
|
2021-09-24 01:56:37 +03:00
|
|
|
|
import Hasura.Metadata.Class
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
import Hasura.RQL.DDL.Action
|
|
|
|
|
import Hasura.RQL.DDL.CustomTypes
|
|
|
|
|
import Hasura.RQL.DDL.EventTrigger (buildEventTriggerInfo)
|
|
|
|
|
import Hasura.RQL.DDL.InheritedRoles (resolveInheritedRole)
|
2022-02-03 21:58:37 +03:00
|
|
|
|
import Hasura.RQL.DDL.RemoteRelationship (CreateRemoteSchemaRemoteRelationship (..), PartiallyResolvedSource (..), buildRemoteFieldInfo, getRemoteSchemaEntityJoinColumns)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
import Hasura.RQL.DDL.RemoteSchema
|
|
|
|
|
import Hasura.RQL.DDL.RemoteSchema.Permission (resolveRoleBasedRemoteSchema)
|
|
|
|
|
import Hasura.RQL.DDL.ScheduledTrigger
|
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache.Common
|
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache.Dependencies
|
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache.Fields
|
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache.Permission
|
|
|
|
|
import Hasura.RQL.DDL.Schema.Function
|
|
|
|
|
import Hasura.RQL.DDL.Schema.Table
|
|
|
|
|
import Hasura.RQL.Types hiding (fmFunction, tmTable)
|
|
|
|
|
import Hasura.RQL.Types.Eventing.Backend
|
|
|
|
|
import Hasura.RQL.Types.Roles.Internal (CheckPermission (..))
|
|
|
|
|
import Hasura.SQL.AnyBackend qualified as AB
|
|
|
|
|
import Hasura.SQL.Tag
|
|
|
|
|
import Hasura.SQL.Tag qualified as Tag
|
|
|
|
|
import Hasura.Server.Types
|
2021-10-05 15:28:38 +03:00
|
|
|
|
( MaintenanceMode (..),
|
2021-12-08 09:26:46 +03:00
|
|
|
|
ReadOnlyMode (..),
|
2021-09-24 01:56:37 +03:00
|
|
|
|
)
|
|
|
|
|
import Hasura.Session
|
|
|
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
|
|
|
import Network.HTTP.Client.Manager (HasHttpManagerM (..))
|
2020-12-21 12:11:37 +03:00
|
|
|
|
|
2021-08-09 13:20:04 +03:00
|
|
|
|
{- Note [Roles Inheritance]
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Roles may have parent roles defined from which they can inherit permission and this is
|
|
|
|
|
called as roles inheritance. Roles which have parents can also be parents of other roles.
|
|
|
|
|
So, cycle in roles should be disallowed and this is done in the `orderRoles` function.
|
|
|
|
|
|
|
|
|
|
When the metadata contains a permission for a role for a entity, then it will override the
|
|
|
|
|
inherited permission, if any.
|
|
|
|
|
|
|
|
|
|
Roles inheritance work differently for different features:
|
|
|
|
|
|
|
|
|
|
1. Select permissions
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
See note [Inherited roles architecture for read queries]
|
|
|
|
|
|
|
|
|
|
2. Mutation permissions and remote schema permissions
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
For mutation and remote schema permissions, an inherited role can only inherit permission
|
|
|
|
|
from its parent roles when the relevant parts of the permissions are equal i.e. the non-relevant
|
|
|
|
|
parts are discarded for the equality, for example, in two remote schema permissions the order
|
|
|
|
|
of the fields in an Object type is discarded.
|
|
|
|
|
|
|
|
|
|
When an inherited role cannot inherit permission from its parents due to a conflict, then we mark
|
|
|
|
|
the inherited role and the entity (remote schema or table) combination as inconsistent in the metadata.
|
|
|
|
|
|
|
|
|
|
3. Actions and Custom function permissions
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Currently, actions and custom function permissions can be thought of as a boolean. Either a role has
|
|
|
|
|
permission to the entity or it doesn't, so in these cases there's no possiblity of a conflict. An inherited
|
|
|
|
|
role will have access to the action/function if any one of the parents have permission to access the
|
|
|
|
|
action/function.
|
|
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
buildRebuildableSchemaCache ::
|
2021-11-09 17:21:48 +03:00
|
|
|
|
Logger Hasura ->
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Env.Environment ->
|
|
|
|
|
Metadata ->
|
|
|
|
|
CacheBuild RebuildableSchemaCache
|
2021-01-07 12:04:22 +03:00
|
|
|
|
buildRebuildableSchemaCache =
|
|
|
|
|
buildRebuildableSchemaCacheWithReason CatalogSync
|
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
buildRebuildableSchemaCacheWithReason ::
|
|
|
|
|
BuildReason ->
|
2021-11-09 17:21:48 +03:00
|
|
|
|
Logger Hasura ->
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Env.Environment ->
|
|
|
|
|
Metadata ->
|
|
|
|
|
CacheBuild RebuildableSchemaCache
|
2021-11-09 17:21:48 +03:00
|
|
|
|
buildRebuildableSchemaCacheWithReason reason logger env metadata = do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
result <-
|
|
|
|
|
flip runReaderT reason $
|
2021-11-09 17:21:48 +03:00
|
|
|
|
Inc.build (buildSchemaCacheRule logger env) (metadata, initialInvalidationKeys)
|
2021-08-24 10:36:32 +03:00
|
|
|
|
|
2020-01-29 23:15:53 +03:00
|
|
|
|
pure $ RebuildableSchemaCache (Inc.result result) initialInvalidationKeys (Inc.rebuildRule result)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
|
|
|
|
newtype CacheRWT m a
|
2021-09-24 01:56:37 +03:00
|
|
|
|
= -- The CacheInvalidations component of the state could actually be collected using WriterT, but
|
|
|
|
|
-- WriterT implementations prior to transformers-0.5.6.0 (which added
|
|
|
|
|
-- Control.Monad.Trans.Writer.CPS) are leaky, and we don’t have that yet.
|
|
|
|
|
CacheRWT (StateT (RebuildableSchemaCache, CacheInvalidations) m a)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
deriving
|
2021-09-24 01:56:37 +03:00
|
|
|
|
( Functor,
|
|
|
|
|
Applicative,
|
|
|
|
|
Monad,
|
|
|
|
|
MonadIO,
|
|
|
|
|
MonadReader r,
|
|
|
|
|
MonadError e,
|
|
|
|
|
MonadTx,
|
|
|
|
|
UserInfoM,
|
|
|
|
|
HasHttpManagerM,
|
|
|
|
|
HasSystemDefined,
|
|
|
|
|
MonadMetadataStorage,
|
|
|
|
|
MonadMetadataStorageQueryAPI,
|
|
|
|
|
Tracing.MonadTrace,
|
|
|
|
|
HasServerConfigCtx
|
|
|
|
|
)
|
2020-12-28 15:56:00 +03:00
|
|
|
|
|
|
|
|
|
deriving instance (MonadBase IO m) => MonadBase IO (CacheRWT m)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
|
deriving instance (MonadBaseControl IO m) => MonadBaseControl IO (CacheRWT m)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
runCacheRWT ::
|
|
|
|
|
Functor m =>
|
|
|
|
|
RebuildableSchemaCache ->
|
|
|
|
|
CacheRWT m a ->
|
|
|
|
|
m (a, RebuildableSchemaCache, CacheInvalidations)
|
2020-01-30 02:03:49 +03:00
|
|
|
|
runCacheRWT cache (CacheRWT m) =
|
|
|
|
|
runStateT m (cache, mempty) <&> \(v, (newCache, invalidations)) -> (v, newCache, invalidations)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
|
|
|
|
instance MonadTrans CacheRWT where
|
|
|
|
|
lift = CacheRWT . lift
|
|
|
|
|
|
|
|
|
|
instance (Monad m) => CacheRM (CacheRWT m) where
|
2020-12-28 15:56:00 +03:00
|
|
|
|
askSchemaCache = CacheRWT $ gets (lastBuiltSchemaCache . (^. _1))
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
instance
|
|
|
|
|
( MonadIO m,
|
|
|
|
|
MonadError QErr m,
|
|
|
|
|
HasHttpManagerM m,
|
|
|
|
|
MonadResolveSource m,
|
|
|
|
|
HasServerConfigCtx m
|
|
|
|
|
) =>
|
|
|
|
|
CacheRWM (CacheRWT m)
|
|
|
|
|
where
|
2020-12-08 17:22:31 +03:00
|
|
|
|
buildSchemaCacheWithOptions buildReason invalidations metadata = CacheRWT do
|
2021-04-06 06:25:02 +03:00
|
|
|
|
(RebuildableSchemaCache lastBuiltSC invalidationKeys rule, oldInvalidations) <- get
|
|
|
|
|
let metadataVersion = scMetadataResourceVersion lastBuiltSC
|
|
|
|
|
newInvalidationKeys = invalidateKeys invalidations invalidationKeys
|
2021-09-24 01:56:37 +03:00
|
|
|
|
result <-
|
|
|
|
|
lift $
|
|
|
|
|
runCacheBuildM $
|
|
|
|
|
flip runReaderT buildReason $
|
|
|
|
|
Inc.build rule (metadata, newInvalidationKeys)
|
|
|
|
|
let schemaCache = (Inc.result result) {scMetadataResourceVersion = metadataVersion}
|
2020-01-30 02:03:49 +03:00
|
|
|
|
prunedInvalidationKeys = pruneInvalidationKeys schemaCache newInvalidationKeys
|
|
|
|
|
!newCache = RebuildableSchemaCache schemaCache prunedInvalidationKeys (Inc.rebuildRule result)
|
|
|
|
|
!newInvalidations = oldInvalidations <> invalidations
|
|
|
|
|
put (newCache, newInvalidations)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
where
|
2020-01-29 23:15:53 +03:00
|
|
|
|
-- Prunes invalidation keys that no longer exist in the schema to avoid leaking memory by
|
|
|
|
|
-- hanging onto unnecessary keys.
|
|
|
|
|
pruneInvalidationKeys schemaCache = over ikRemoteSchemas $ M.filterWithKey \name _ ->
|
2020-03-26 14:52:20 +03:00
|
|
|
|
-- see Note [Keep invalidation keys for inconsistent objects]
|
|
|
|
|
name `elem` getAllRemoteSchemas schemaCache
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-04-06 06:25:02 +03:00
|
|
|
|
setMetadataResourceVersionInSchemaCache resourceVersion = CacheRWT $ do
|
|
|
|
|
(rebuildableSchemaCache, invalidations) <- get
|
2021-09-24 01:56:37 +03:00
|
|
|
|
put
|
|
|
|
|
( rebuildableSchemaCache
|
|
|
|
|
{ lastBuiltSchemaCache =
|
|
|
|
|
(lastBuiltSchemaCache rebuildableSchemaCache)
|
|
|
|
|
{ scMetadataResourceVersion = Just resourceVersion
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
invalidations
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
buildSchemaCacheRule ::
|
2019-11-20 21:21:30 +03:00
|
|
|
|
-- Note: by supplying BuildReason via MonadReader, it does not participate in caching, which is
|
|
|
|
|
-- what we want!
|
2021-10-13 19:38:56 +03:00
|
|
|
|
( ArrowChoice arr,
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
|
MonadError QErr m,
|
|
|
|
|
MonadReader BuildReason m,
|
|
|
|
|
HasHttpManagerM m,
|
|
|
|
|
MonadResolveSource m,
|
|
|
|
|
HasServerConfigCtx m
|
|
|
|
|
) =>
|
2021-11-09 17:21:48 +03:00
|
|
|
|
Logger Hasura ->
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Env.Environment ->
|
|
|
|
|
(Metadata, InvalidationKeys) `arr` SchemaCache
|
2021-11-09 17:21:48 +03:00
|
|
|
|
buildSchemaCacheRule logger env = proc (metadata, invalidationKeys) -> do
|
2020-01-29 23:15:53 +03:00
|
|
|
|
invalidationKeysDep <- Inc.newDependency -< invalidationKeys
|
|
|
|
|
|
|
|
|
|
-- Step 1: Process metadata and collect dependency information.
|
|
|
|
|
(outputs, collectedInfo) <-
|
2020-12-08 17:22:31 +03:00
|
|
|
|
runWriterA buildAndCollectInfo -< (metadata, invalidationKeysDep)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
let (inconsistentObjects, unresolvedDependencies) = partitionCollectedInfo collectedInfo
|
2020-01-29 23:15:53 +03:00
|
|
|
|
|
|
|
|
|
-- Step 2: Resolve dependency information and drop dangling dependents.
|
|
|
|
|
(resolvedOutputs, dependencyInconsistentObjects, resolvedDependencies) <-
|
2019-11-20 21:21:30 +03:00
|
|
|
|
resolveDependencies -< (outputs, unresolvedDependencies)
|
2020-01-29 23:15:53 +03:00
|
|
|
|
|
|
|
|
|
-- Step 3: Build the GraphQL schema.
|
2022-02-03 21:58:37 +03:00
|
|
|
|
(gqlContext, gqlContextUnauth, inconsistentRemoteSchemas) <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
bindA
|
|
|
|
|
-<
|
|
|
|
|
buildGQLContext
|
|
|
|
|
QueryHasura
|
|
|
|
|
(_boSources resolvedOutputs)
|
|
|
|
|
(_boRemoteSchemas resolvedOutputs)
|
|
|
|
|
(_boActions resolvedOutputs)
|
2021-12-16 02:51:52 +03:00
|
|
|
|
(_boCustomTypes resolvedOutputs)
|
2020-01-29 23:15:53 +03:00
|
|
|
|
|
2020-06-08 15:13:01 +03:00
|
|
|
|
-- Step 4: Build the relay GraphQL schema
|
2022-02-03 21:58:37 +03:00
|
|
|
|
(relayContext, relayContextUnauth, _) <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
bindA
|
|
|
|
|
-<
|
|
|
|
|
buildGQLContext
|
|
|
|
|
QueryRelay
|
|
|
|
|
(_boSources resolvedOutputs)
|
|
|
|
|
(_boRemoteSchemas resolvedOutputs)
|
|
|
|
|
(_boActions resolvedOutputs)
|
2021-12-16 02:51:52 +03:00
|
|
|
|
(_boCustomTypes resolvedOutputs)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
|
|
|
|
let duplicateVariables :: EndpointMetadata a -> Bool
|
|
|
|
|
duplicateVariables m = any ((> 1) . length) $ group $ sort $ catMaybes $ splitPath Just (const Nothing) (_ceUrl m)
|
|
|
|
|
|
|
|
|
|
endpointObjId :: EndpointMetadata q -> MetadataObjId
|
|
|
|
|
endpointObjId md = MOEndpoint (_ceName md)
|
|
|
|
|
|
|
|
|
|
endpointObject :: EndpointMetadata q -> MetadataObject
|
|
|
|
|
endpointObject md = MetadataObject (endpointObjId md) (toJSON $ OMap.lookup (_ceName md) $ _metaRestEndpoints metadata)
|
|
|
|
|
|
|
|
|
|
-- Cases of urls that generate invalid segments:
|
|
|
|
|
|
|
|
|
|
hasInvalidSegments :: EndpointMetadata query -> Bool
|
|
|
|
|
hasInvalidSegments m = any (`elem` ["", ":"]) (splitPath id id (_ceUrl m))
|
|
|
|
|
|
|
|
|
|
ceUrlTxt = toTxt . _ceUrl
|
|
|
|
|
|
|
|
|
|
endpoints = buildEndpointsTrie (M.elems $ _boEndpoints resolvedOutputs)
|
|
|
|
|
|
|
|
|
|
duplicateF md = DuplicateRestVariables (ceUrlTxt md) (endpointObject md)
|
|
|
|
|
duplicateRestVariables = map duplicateF $ filter duplicateVariables (M.elems $ _boEndpoints resolvedOutputs)
|
|
|
|
|
|
|
|
|
|
invalidF md = InvalidRestSegments (ceUrlTxt md) (endpointObject md)
|
|
|
|
|
invalidRestSegments = map invalidF $ filter hasInvalidSegments (M.elems $ _boEndpoints resolvedOutputs)
|
|
|
|
|
|
|
|
|
|
ambiguousF' ep = MetadataObject (endpointObjId ep) (toJSON ep)
|
|
|
|
|
ambiguousF mds = AmbiguousRestEndpoints (commaSeparated $ map _ceUrl mds) (map ambiguousF' mds)
|
|
|
|
|
ambiguousRestEndpoints = map (ambiguousF . S.elems . snd) $ ambiguousPathsGrouped endpoints
|
2022-02-08 07:46:57 +03:00
|
|
|
|
maybeRS = getSchemaIntrospection gqlContext
|
|
|
|
|
inconsistentRestQueries = getInconsistentRestQueries maybeRS endpoints endpointObject
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
|
|
|
|
returnA
|
|
|
|
|
-<
|
|
|
|
|
SchemaCache
|
|
|
|
|
{ scSources = _boSources resolvedOutputs,
|
|
|
|
|
scActions = _boActions resolvedOutputs,
|
|
|
|
|
-- TODO this is not the right value: we should track what part of the schema
|
|
|
|
|
-- we can stitch without consistencies, I think.
|
|
|
|
|
scRemoteSchemas = fmap fst (_boRemoteSchemas resolvedOutputs), -- remoteSchemaMap
|
|
|
|
|
scAllowlist = _boAllowlist resolvedOutputs,
|
|
|
|
|
-- , scCustomTypes = _boCustomTypes resolvedOutputs
|
|
|
|
|
scGQLContext = gqlContext,
|
|
|
|
|
scUnauthenticatedGQLContext = gqlContextUnauth,
|
|
|
|
|
scRelayContext = relayContext,
|
|
|
|
|
scUnauthenticatedRelayContext = relayContextUnauth,
|
|
|
|
|
-- , scGCtxMap = gqlSchema
|
|
|
|
|
-- , scDefaultRemoteGCtx = remoteGQLSchema
|
|
|
|
|
scDepMap = resolvedDependencies,
|
|
|
|
|
scCronTriggers = _boCronTriggers resolvedOutputs,
|
|
|
|
|
scEndpoints = endpoints,
|
|
|
|
|
scInconsistentObjs =
|
|
|
|
|
inconsistentObjects
|
|
|
|
|
<> dependencyInconsistentObjects
|
2022-02-03 21:58:37 +03:00
|
|
|
|
<> toList inconsistentRemoteSchemas
|
2021-09-24 01:56:37 +03:00
|
|
|
|
<> duplicateRestVariables
|
|
|
|
|
<> invalidRestSegments
|
2022-02-08 07:46:57 +03:00
|
|
|
|
<> ambiguousRestEndpoints
|
|
|
|
|
<> inconsistentRestQueries,
|
2021-09-24 01:56:37 +03:00
|
|
|
|
scApiLimits = _boApiLimits resolvedOutputs,
|
|
|
|
|
scMetricsConfig = _boMetricsConfig resolvedOutputs,
|
|
|
|
|
scMetadataResourceVersion = Nothing,
|
|
|
|
|
scSetGraphqlIntrospectionOptions = _metaSetGraphqlIntrospectionOptions metadata,
|
|
|
|
|
scTlsAllowlist = _boTlsAllowlist resolvedOutputs
|
|
|
|
|
}
|
2019-08-14 02:34:37 +03:00
|
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
|
getSourceConfigIfNeeded ::
|
|
|
|
|
forall b arr m.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
MonadResolveSource m,
|
|
|
|
|
BackendMetadata b
|
|
|
|
|
) =>
|
|
|
|
|
( Inc.Dependency (HashMap SourceName Inc.InvalidationKey),
|
|
|
|
|
SourceName,
|
|
|
|
|
SourceConnConfiguration b
|
|
|
|
|
)
|
|
|
|
|
`arr` Maybe (SourceConfig b)
|
2021-02-22 10:52:42 +03:00
|
|
|
|
getSourceConfigIfNeeded = Inc.cache proc (invalidationKeys, sourceName, sourceConfig) -> do
|
|
|
|
|
let metadataObj = MetadataObject (MOSource sourceName) $ toJSON sourceName
|
|
|
|
|
Inc.dependOn -< Inc.selectKeyD sourceName invalidationKeys
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( liftEitherA <<< bindA -< resolveSourceConfig @b sourceName sourceConfig env
|
|
|
|
|
)
|
|
|
|
|
|) metadataObj
|
|
|
|
|
|
|
|
|
|
resolveSourceIfNeeded ::
|
|
|
|
|
forall b arr m.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
|
MonadResolveSource m,
|
|
|
|
|
BackendMetadata b
|
|
|
|
|
) =>
|
|
|
|
|
( Inc.Dependency (HashMap SourceName Inc.InvalidationKey),
|
|
|
|
|
SourceMetadata b
|
|
|
|
|
)
|
|
|
|
|
`arr` Maybe (ResolvedSource b)
|
2021-01-07 12:04:22 +03:00
|
|
|
|
resolveSourceIfNeeded = Inc.cache proc (invalidationKeys, sourceMetadata) -> do
|
2020-12-28 15:56:00 +03:00
|
|
|
|
let sourceName = _smName sourceMetadata
|
|
|
|
|
metadataObj = MetadataObject (MOSource sourceName) $ toJSON sourceName
|
2022-02-09 08:13:32 +03:00
|
|
|
|
logAndResolveDatabaseMetadata :: SourceConfig b -> SourceTypeCustomization -> m (Either QErr (ResolvedSource b))
|
|
|
|
|
logAndResolveDatabaseMetadata scConfig sType = do
|
|
|
|
|
resSource <- resolveDatabaseMetadata scConfig sType
|
|
|
|
|
for_ resSource $ liftIO . unLogger logger
|
|
|
|
|
pure resSource
|
|
|
|
|
|
2021-04-22 00:44:37 +03:00
|
|
|
|
maybeSourceConfig <- getSourceConfigIfNeeded @b -< (invalidationKeys, sourceName, _smConfiguration sourceMetadata)
|
2021-02-22 10:52:42 +03:00
|
|
|
|
case maybeSourceConfig of
|
|
|
|
|
Nothing -> returnA -< Nothing
|
|
|
|
|
Just sourceConfig ->
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
2022-02-09 08:13:32 +03:00
|
|
|
|
( liftEitherA <<< bindA -< logAndResolveDatabaseMetadata sourceConfig (getSourceTypeCustomization $ _smCustomization sourceMetadata)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
)
|
2021-02-22 10:52:42 +03:00
|
|
|
|
|) metadataObj
|
2020-12-28 15:56:00 +03:00
|
|
|
|
|
2021-05-25 09:50:13 +03:00
|
|
|
|
-- impl notes (swann):
|
|
|
|
|
--
|
|
|
|
|
-- as our cache invalidation key (in a sense) we use the number of event triggers
|
|
|
|
|
-- present, rerunning catalog init when this changes. this is correct, because we
|
|
|
|
|
-- only care about the transition from zero event triggers to nonzero (not
|
|
|
|
|
-- necessarily one, as Anon has observed, because replace_metadata can add multiple
|
|
|
|
|
-- event triggers in one go)
|
|
|
|
|
--
|
|
|
|
|
-- a future optimisation would be to cache, on a per-source basis, whether or not
|
|
|
|
|
-- the event catalog itself exists, and to then trigger catalog init when an event
|
|
|
|
|
-- trigger is created _but only if_ this cached information says the event catalog
|
|
|
|
|
-- doesn't already exist.
|
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
initCatalogIfNeeded ::
|
|
|
|
|
forall b arr m.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
BackendMetadata b,
|
|
|
|
|
HasServerConfigCtx m,
|
|
|
|
|
MonadError QErr m
|
|
|
|
|
) =>
|
|
|
|
|
(Int, SourceConfig b) `arr` RecreateEventTriggers
|
2021-11-09 17:21:48 +03:00
|
|
|
|
initCatalogIfNeeded = Inc.cache proc (numEventTriggers, sourceConfig) -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
arrM id
|
|
|
|
|
-< do
|
|
|
|
|
if numEventTriggers > 0
|
|
|
|
|
then do
|
|
|
|
|
case backendTag @b of
|
|
|
|
|
Tag.PostgresVanillaTag -> do
|
|
|
|
|
migrationTime <- liftIO getCurrentTime
|
|
|
|
|
maintenanceMode <- _sccMaintenanceMode <$> askServerConfigCtx
|
2021-11-30 15:31:27 +03:00
|
|
|
|
eventingMode <- _sccEventingMode <$> askServerConfigCtx
|
2021-12-08 09:26:46 +03:00
|
|
|
|
readOnlyMode <- _sccReadOnlyMode <$> askServerConfigCtx
|
2021-11-09 17:21:48 +03:00
|
|
|
|
liftEitherM $
|
|
|
|
|
liftIO $
|
|
|
|
|
LA.withAsync (logPGSourceCatalogMigrationLockedQueries logger sourceConfig) $
|
|
|
|
|
const $ do
|
|
|
|
|
let initCatalogAction =
|
2021-12-08 09:26:46 +03:00
|
|
|
|
runExceptT $ runTx (_pscExecCtx sourceConfig) Q.ReadWrite (initCatalogForSource maintenanceMode eventingMode readOnlyMode migrationTime)
|
2021-11-09 17:21:48 +03:00
|
|
|
|
-- The `initCatalogForSource` action is retried here because
|
|
|
|
|
-- in cloud there will be multiple workers (graphql-engine instances)
|
|
|
|
|
-- trying to migrate the source catalog, when needed. This introduces
|
|
|
|
|
-- a race condition as both the workers try to migrate the source catalog
|
|
|
|
|
-- concurrently and when one of them succeeds the other ones will fail
|
|
|
|
|
-- and be in an inconsistent state. To avoid the inconsistency, we retry
|
|
|
|
|
-- migrating the catalog on error and in the retry `initCatalogForSource`
|
|
|
|
|
-- will see that the catalog is already migrated, so it won't attempt the
|
|
|
|
|
-- migration again
|
|
|
|
|
Retry.retrying
|
|
|
|
|
( Retry.constantDelay (fromIntegral $ diffTimeToMicroSeconds $ seconds $ Seconds 10)
|
|
|
|
|
<> Retry.limitRetries 3
|
|
|
|
|
)
|
|
|
|
|
(const $ return . isLeft)
|
|
|
|
|
(const initCatalogAction)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
-- TODO: When event triggers are supported on new databases,
|
|
|
|
|
-- the initialization of the source catalog should also return
|
|
|
|
|
-- if the event triggers are to be re-created or not, essentially
|
|
|
|
|
-- replacing the `RETDoNothing` below
|
|
|
|
|
_ -> pure RETDoNothing
|
|
|
|
|
else pure RETDoNothing
|
|
|
|
|
|
|
|
|
|
buildSource ::
|
|
|
|
|
forall b arr m.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
|
HasServerConfigCtx m,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
MonadError QErr m,
|
|
|
|
|
MonadReader BuildReason m,
|
|
|
|
|
BackendMetadata b,
|
|
|
|
|
BackendEventTrigger b
|
|
|
|
|
) =>
|
|
|
|
|
( HashMap SourceName (AB.AnyBackend PartiallyResolvedSource),
|
|
|
|
|
SourceMetadata b,
|
|
|
|
|
SourceConfig b,
|
|
|
|
|
HashMap (TableName b) (TableCoreInfoG b (ColumnInfo b) (ColumnInfo b)),
|
|
|
|
|
DBTablesMetadata b,
|
|
|
|
|
DBFunctionsMetadata b,
|
|
|
|
|
RemoteSchemaMap,
|
|
|
|
|
Inc.Dependency InvalidationKeys,
|
|
|
|
|
OrderedRoles
|
|
|
|
|
)
|
|
|
|
|
`arr` BackendSourceInfo
|
2021-07-23 02:06:10 +03:00
|
|
|
|
buildSource = proc (allSources, sourceMetadata, sourceConfig, tablesRawInfo, _dbTables, dbFunctions, remoteSchemaMap, invalidationKeys, orderedRoles) -> do
|
2021-11-10 17:34:22 +03:00
|
|
|
|
let SourceMetadata sourceName tables functions _ queryTagsConfig sourceCustomization = sourceMetadata
|
2021-02-14 09:07:52 +03:00
|
|
|
|
tablesMetadata = OMap.elems tables
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(_, nonColumnInputs, permissions) = unzip3 $ map mkTableInputs tablesMetadata
|
2021-08-09 13:20:04 +03:00
|
|
|
|
eventTriggers = map (_tmTable &&& OMap.elems . _tmEventTriggers) tablesMetadata
|
2021-02-14 09:07:52 +03:00
|
|
|
|
alignTableMap :: HashMap (TableName b) a -> HashMap (TableName b) c -> HashMap (TableName b) (a, c)
|
2020-12-08 17:22:31 +03:00
|
|
|
|
alignTableMap = M.intersectionWith (,)
|
2021-01-07 12:04:22 +03:00
|
|
|
|
metadataInvalidationKey = Inc.selectD #_ikMetadata invalidationKeys
|
2021-05-25 09:50:13 +03:00
|
|
|
|
numEventTriggers = sum $ map (length . snd) eventTriggers
|
|
|
|
|
|
2021-06-07 16:57:24 +03:00
|
|
|
|
recreateEventTriggers <- initCatalogIfNeeded @b -< (numEventTriggers, sourceConfig)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
|
|
|
|
-- relationships and computed fields
|
2020-12-08 17:22:31 +03:00
|
|
|
|
let nonColumnsByTable = mapFromL _nctiTable nonColumnInputs
|
2021-02-14 09:07:52 +03:00
|
|
|
|
tableCoreInfos :: HashMap (TableName b) (TableCoreInfo b) <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
Inc.keyed
|
|
|
|
|
( \_ (tableRawInfo, nonColumnInput) -> do
|
|
|
|
|
let columns = _tciFieldInfoMap tableRawInfo
|
2021-11-10 17:34:22 +03:00
|
|
|
|
allFields :: FieldInfoMap (FieldInfo b) <- addNonColumnFields -< (allSources, sourceName, tablesRawInfo, columns, remoteSchemaMap, dbFunctions, nonColumnInput)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
returnA -< (tableRawInfo {_tciFieldInfoMap = allFields})
|
|
|
|
|
)
|
|
|
|
|
|) (tablesRawInfo `alignTableMap` nonColumnsByTable)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2019-12-15 19:07:08 +03:00
|
|
|
|
tableCoreInfosDep <- Inc.newDependency -< tableCoreInfos
|
2021-07-23 02:06:10 +03:00
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
|
-- permissions and event triggers
|
2020-12-08 17:22:31 +03:00
|
|
|
|
tableCache <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
Inc.keyed
|
|
|
|
|
( \_ ((tableCoreInfo, permissionInputs), (_, eventTriggerConfs)) -> do
|
|
|
|
|
let tableFields = _tciFieldInfoMap tableCoreInfo
|
|
|
|
|
permissionInfos <-
|
|
|
|
|
buildTablePermissions
|
|
|
|
|
-<
|
2021-11-10 17:34:22 +03:00
|
|
|
|
(Proxy :: Proxy b, sourceName, tableCoreInfosDep, tableFields, permissionInputs, orderedRoles)
|
|
|
|
|
eventTriggerInfos <- buildTableEventTriggers -< (sourceName, sourceConfig, tableCoreInfo, eventTriggerConfs, metadataInvalidationKey, recreateEventTriggers)
|
Role-invariant schema constructors
We build the GraphQL schema by combining building blocks such as `tableSelectionSet` and `columnParser`. These building blocks individually build `{InputFields,Field,}Parser` objects. Those object specify the valid GraphQL schema.
Since the GraphQL schema is role-dependent, at some point we need to know what fragment of the GraphQL schema a specific role is allowed to access, and this is stored in `{Sel,Upd,Ins,Del}PermInfo` objects.
We have passed around these permission objects as function arguments to the schema building blocks since we first started dealing with permissions during the PDV refactor - see hasura/graphql-engine@5168b99e463199b1934d8645bd6cd37eddb64ae1 in hasura/graphql-engine#4111. This means that, for instance, `tableSelectionSet` has as its type:
```haskell
tableSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
SourceName ->
TableInfo b ->
SelPermInfo b ->
m (Parser 'Output n (AnnotatedFields b))
```
There are three reasons to change this.
1. We often pass a `Maybe (xPermInfo b)` instead of a proper `xPermInfo b`, and it's not clear what the intended semantics of this is. Some potential improvements on the data types involved are discussed in issue hasura/graphql-engine-mono#3125.
2. In most cases we also already pass a `TableInfo b`, and together with the `MonadRole` that is usually also in scope, this means that we could look up the required permissions regardless: so passing the permissions explicitly undermines the "single source of truth" principle. Breaking this principle also makes the code more difficult to read.
3. We are working towards role-based parsers (see hasura/graphql-engine-mono#2711), where the `{InputFields,Field,}Parser` objects are constructed in a role-invariant way, so that we have a single object that can be used for all roles. In particular, this means that the schema building blocks _need_ to be constructed in a role-invariant way. While this PR doesn't accomplish that, it does reduce the amount of role-specific arguments being passed, thus fixing hasura/graphql-engine-mono#3068.
Concretely, this PR simply drops the `xPermInfo b` argument from almost all schema building blocks. Instead these objects are looked up from the `TableInfo b` as-needed. The resulting code is considerably simpler and shorter.
One way to interpret this change is as follows. Before this PR, we figured out permissions at the top-level in `Hasura.GraphQL.Schema`, passing down the obtained `xPermInfo` objects as required. After this PR, we have a bottom-up approach where the schema building blocks themselves decide whether they want to be included for a particular role.
So this moves some permission logic out of `Hasura.GraphQL.Schema`, which is very complex.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3608
GitOrigin-RevId: 51a744f34ec7d57bc8077667ae7f9cb9c4f6c962
2022-02-17 11:16:20 +03:00
|
|
|
|
returnA -< TableInfo tableCoreInfo permissionInfos eventTriggerInfos (mkAdminRolePermInfo tableCoreInfo)
|
2020-12-08 17:22:31 +03:00
|
|
|
|
)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|) (tableCoreInfos `alignTableMap` mapFromL _tpiTable permissions `alignTableMap` mapFromL fst eventTriggers)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
|
|
|
|
-- sql functions
|
2021-09-24 01:56:37 +03:00
|
|
|
|
functionCache <-
|
|
|
|
|
(mapFromL _fmFunction (OMap.elems functions) >- returnA)
|
|
|
|
|
>-> (|
|
|
|
|
|
Inc.keyed
|
2021-09-24 12:18:40 +03:00
|
|
|
|
( \_ (FunctionMetadata qf config functionPermissions comment) -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
let systemDefined = SystemDefined False
|
|
|
|
|
definition = toJSON $ TrackFunction @b qf
|
|
|
|
|
metadataObject =
|
|
|
|
|
MetadataObject
|
2021-11-10 17:34:22 +03:00
|
|
|
|
( MOSourceObjId sourceName $
|
2021-09-24 01:56:37 +03:00
|
|
|
|
AB.mkAnyBackend $
|
|
|
|
|
SMOFunction @b qf
|
|
|
|
|
)
|
|
|
|
|
definition
|
|
|
|
|
schemaObject =
|
2021-11-10 17:34:22 +03:00
|
|
|
|
SOSourceObj sourceName $
|
2021-09-24 01:56:37 +03:00
|
|
|
|
AB.mkAnyBackend $
|
|
|
|
|
SOIFunction @b qf
|
|
|
|
|
addFunctionContext e = "in function " <> qf <<> ": " <> e
|
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
( do
|
|
|
|
|
let funcDefs = fromMaybe [] $ M.lookup qf dbFunctions
|
|
|
|
|
rawfunctionInfo <- bindErrorA -< handleMultipleFunctions @b qf funcDefs
|
|
|
|
|
let metadataPermissions = mapFromL _fpmRole functionPermissions
|
|
|
|
|
permissionsMap = mkBooleanPermissionMap FunctionPermissionInfo metadataPermissions orderedRoles
|
2021-11-10 17:34:22 +03:00
|
|
|
|
(functionInfo, dep) <- bindErrorA -< buildFunctionInfo sourceName qf systemDefined config permissionsMap rawfunctionInfo comment
|
2021-09-24 01:56:37 +03:00
|
|
|
|
recordDependencies -< (metadataObject, schemaObject, [dep])
|
|
|
|
|
returnA -< functionInfo
|
|
|
|
|
)
|
|
|
|
|
|) addFunctionContext
|
|
|
|
|
)
|
|
|
|
|
|) metadataObject
|
|
|
|
|
)
|
|
|
|
|
|)
|
|
|
|
|
>-> (\infos -> M.catMaybes infos >- returnA)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-11-10 17:34:22 +03:00
|
|
|
|
returnA -< AB.mkAnyBackend $ SourceInfo sourceName tableCache functionCache sourceConfig queryTagsConfig sourceCustomization
|
2021-02-14 09:07:52 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
buildAndCollectInfo ::
|
|
|
|
|
forall arr m.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
MonadError QErr m,
|
|
|
|
|
MonadReader BuildReason m,
|
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
|
HasHttpManagerM m,
|
|
|
|
|
HasServerConfigCtx m,
|
|
|
|
|
MonadResolveSource m
|
|
|
|
|
) =>
|
|
|
|
|
(Metadata, Inc.Dependency InvalidationKeys) `arr` BuildOutputs
|
2020-12-28 15:56:00 +03:00
|
|
|
|
buildAndCollectInfo = proc (metadata, invalidationKeys) -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
let Metadata
|
|
|
|
|
sources
|
|
|
|
|
remoteSchemas
|
|
|
|
|
collections
|
2022-02-08 19:53:30 +03:00
|
|
|
|
metadataAllowlist
|
2021-09-24 01:56:37 +03:00
|
|
|
|
customTypes
|
|
|
|
|
actions
|
|
|
|
|
cronTriggers
|
|
|
|
|
endpoints
|
|
|
|
|
apiLimits
|
|
|
|
|
metricsConfig
|
|
|
|
|
inheritedRoles
|
|
|
|
|
_introspectionDisabledRoles
|
|
|
|
|
networkConfig = metadata
|
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
|
|
|
|
actionRoles = map _apmRole . _amPermissions =<< OMap.elems actions
|
|
|
|
|
remoteSchemaRoles = map _rspmRole . _rsmPermissions =<< OMap.elems remoteSchemas
|
|
|
|
|
sourceRoles =
|
2021-09-24 01:56:37 +03:00
|
|
|
|
HS.fromList $
|
|
|
|
|
concat $
|
|
|
|
|
OMap.elems sources >>= \e ->
|
2021-10-29 17:42:07 +03:00
|
|
|
|
AB.dispatchAnyBackend @Backend e \(SourceMetadata _ tables _functions _ _ _) -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
table <- OMap.elems tables
|
|
|
|
|
pure $
|
|
|
|
|
OMap.keys (_tmInsertPermissions table)
|
|
|
|
|
<> OMap.keys (_tmSelectPermissions table)
|
|
|
|
|
<> OMap.keys (_tmUpdatePermissions table)
|
|
|
|
|
<> OMap.keys (_tmDeletePermissions table)
|
2021-07-17 00:18:58 +03:00
|
|
|
|
inheritedRoleNames = OMap.keys inheritedRoles
|
|
|
|
|
allRoleNames = sourceRoles <> HS.fromList (remoteSchemaRoles <> actionRoles <> inheritedRoleNames)
|
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
|
remoteSchemaPermissions =
|
|
|
|
|
let remoteSchemaPermsList = OMap.toList $ _rsmPermissions <$> remoteSchemas
|
2021-09-24 01:56:37 +03:00
|
|
|
|
in concat $
|
|
|
|
|
flip map remoteSchemaPermsList $
|
|
|
|
|
( \(remoteSchemaName, remoteSchemaPerms) ->
|
|
|
|
|
flip map remoteSchemaPerms $ \(RemoteSchemaPermissionMetadata role defn comment) ->
|
|
|
|
|
AddRemoteSchemaPermission remoteSchemaName role defn comment
|
|
|
|
|
)
|
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
|
|
|
|
|
2021-07-17 00:18:58 +03:00
|
|
|
|
-- roles which have some kind of permission (action/remote schema/table/function) set in the metadata
|
2021-08-09 13:20:04 +03:00
|
|
|
|
let metadataRoles = mapFromL _rRoleName $ (`Role` ParentRoles mempty) <$> toList allRoleNames
|
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
|
|
|
|
|
2021-07-17 00:18:58 +03:00
|
|
|
|
resolvedInheritedRoles <- buildInheritedRoles -< (allRoleNames, OMap.elems inheritedRoles)
|
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
|
|
|
|
|
2021-07-17 00:18:58 +03:00
|
|
|
|
let allRoles = resolvedInheritedRoles `M.union` metadataRoles
|
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
|
|
|
|
|
2021-07-17 00:18:58 +03:00
|
|
|
|
orderedRoles <- bindA -< orderRoles $ M.elems allRoles
|
2020-12-28 15:56:00 +03:00
|
|
|
|
|
|
|
|
|
-- remote schemas
|
|
|
|
|
let remoteSchemaInvalidationKeys = Inc.selectD #_ikRemoteSchemas invalidationKeys
|
2021-08-09 13:20:04 +03:00
|
|
|
|
remoteSchemaMap <- buildRemoteSchemas -< (remoteSchemaInvalidationKeys, OMap.elems remoteSchemas)
|
2022-02-03 21:58:37 +03:00
|
|
|
|
let remoteSchemaCtxMap = M.map (fst . fst) remoteSchemaMap
|
2021-07-23 02:06:10 +03:00
|
|
|
|
|
|
|
|
|
-- sources are build in two steps
|
|
|
|
|
-- first we resolve them, and build the table cache
|
|
|
|
|
partiallyResolvedSources <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
Inc.keyed
|
|
|
|
|
( \_ exists ->
|
|
|
|
|
AB.dispatchAnyBackendArrow @BackendMetadata @BackendMetadata
|
|
|
|
|
( proc (sourceMetadata, invalidationKeys) -> do
|
|
|
|
|
let sourceName = _smName sourceMetadata
|
|
|
|
|
sourceInvalidationsKeys = Inc.selectD #_ikSources invalidationKeys
|
|
|
|
|
maybeResolvedSource <- resolveSourceIfNeeded -< (sourceInvalidationsKeys, sourceMetadata)
|
|
|
|
|
case maybeResolvedSource of
|
|
|
|
|
Nothing -> returnA -< Nothing
|
|
|
|
|
Just (source :: ResolvedSource b) -> do
|
|
|
|
|
let metadataInvalidationKey = Inc.selectD #_ikMetadata invalidationKeys
|
|
|
|
|
(tableInputs, _, _) = unzip3 $ map mkTableInputs $ OMap.elems $ _smTables sourceMetadata
|
|
|
|
|
tablesCoreInfo <-
|
|
|
|
|
buildTableCache
|
|
|
|
|
-<
|
|
|
|
|
( sourceName,
|
|
|
|
|
_rsConfig source,
|
|
|
|
|
_rsTables source,
|
|
|
|
|
tableInputs,
|
|
|
|
|
metadataInvalidationKey
|
|
|
|
|
)
|
|
|
|
|
returnA
|
|
|
|
|
-<
|
|
|
|
|
Just $
|
|
|
|
|
AB.mkAnyBackend @b $
|
|
|
|
|
PartiallyResolvedSource sourceMetadata source tablesCoreInfo
|
|
|
|
|
)
|
|
|
|
|
-<
|
|
|
|
|
(exists, invalidationKeys)
|
|
|
|
|
)
|
2021-02-14 09:07:52 +03:00
|
|
|
|
|) (M.fromList $ OMap.toList sources)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
>-> (\infos -> M.catMaybes infos >- returnA)
|
2020-12-28 15:56:00 +03:00
|
|
|
|
|
2021-07-23 02:06:10 +03:00
|
|
|
|
-- then we can build the entire source output
|
|
|
|
|
-- we need to have the table cache of all sources to build cross-sources relationships
|
|
|
|
|
sourcesOutput <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
Inc.keyed
|
|
|
|
|
( \_ exists ->
|
|
|
|
|
AB.dispatchAnyBackendArrow @BackendMetadata @BackendEventTrigger
|
|
|
|
|
( proc
|
|
|
|
|
( partiallyResolvedSource :: PartiallyResolvedSource b,
|
|
|
|
|
(allResolvedSources, invalidationKeys, remoteSchemaCtxMap, orderedRoles)
|
|
|
|
|
)
|
|
|
|
|
-> do
|
|
|
|
|
let PartiallyResolvedSource sourceMetadata resolvedSource tablesInfo = partiallyResolvedSource
|
2021-10-29 17:42:07 +03:00
|
|
|
|
ResolvedSource sourceConfig _sourceCustomization tablesMeta functionsMeta scalars = resolvedSource
|
2021-09-24 01:56:37 +03:00
|
|
|
|
so <-
|
|
|
|
|
buildSource
|
|
|
|
|
-<
|
|
|
|
|
( allResolvedSources,
|
|
|
|
|
sourceMetadata,
|
|
|
|
|
sourceConfig,
|
|
|
|
|
tablesInfo,
|
|
|
|
|
tablesMeta,
|
|
|
|
|
functionsMeta,
|
|
|
|
|
remoteSchemaCtxMap,
|
|
|
|
|
invalidationKeys,
|
|
|
|
|
orderedRoles
|
|
|
|
|
)
|
|
|
|
|
returnA -< (so, DMap.singleton (backendTag @b) $ ScalarSet scalars)
|
2021-07-23 02:06:10 +03:00
|
|
|
|
)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
-<
|
|
|
|
|
( exists,
|
|
|
|
|
(partiallyResolvedSources, invalidationKeys, remoteSchemaCtxMap, orderedRoles)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|) partiallyResolvedSources
|
2021-07-23 02:06:10 +03:00
|
|
|
|
|
2022-02-03 21:58:37 +03:00
|
|
|
|
remoteSchemaCache <-
|
|
|
|
|
(remoteSchemaMap >- returnA)
|
|
|
|
|
>-> ( \info ->
|
|
|
|
|
(info, M.groupOn _arspRemoteSchema remoteSchemaPermissions)
|
|
|
|
|
>-
|
|
|
|
|
alignExtraRemoteSchemaInfo mkRemoteSchemaPermissionMetadataObject
|
|
|
|
|
)
|
|
|
|
|
>-> (|
|
|
|
|
|
Inc.keyed
|
|
|
|
|
( \_ (((remoteSchemaCtx, relationships), metadataObj), remoteSchemaPerms) -> do
|
|
|
|
|
metadataPermissionsMap <-
|
|
|
|
|
buildRemoteSchemaPermissions -< (remoteSchemaCtx, remoteSchemaPerms)
|
|
|
|
|
-- convert to the intermediate form `CheckPermission` whose `Semigroup`
|
|
|
|
|
-- instance is used to combine permissions
|
|
|
|
|
let metadataCheckPermissionsMap = CPDefined <$> metadataPermissionsMap
|
|
|
|
|
allRolesUnresolvedPermissionsMap <-
|
|
|
|
|
bindA
|
|
|
|
|
-<
|
|
|
|
|
foldM
|
|
|
|
|
( \accumulatedRolePermMap (Role roleName (ParentRoles parentRoles)) -> do
|
|
|
|
|
rolePermission <- onNothing (M.lookup roleName accumulatedRolePermMap) $ do
|
|
|
|
|
parentRolePermissions <-
|
|
|
|
|
for (toList parentRoles) $ \role ->
|
|
|
|
|
onNothing (M.lookup role accumulatedRolePermMap) $
|
|
|
|
|
throw500 $
|
|
|
|
|
"remote schema permissions: bad ordering of roles, could not find the permission of role: " <>> role
|
|
|
|
|
let combinedPermission = sconcat <$> nonEmpty parentRolePermissions
|
|
|
|
|
pure $ fromMaybe CPUndefined combinedPermission
|
|
|
|
|
pure $ M.insert roleName rolePermission accumulatedRolePermMap
|
|
|
|
|
)
|
|
|
|
|
metadataCheckPermissionsMap
|
|
|
|
|
(_unOrderedRoles orderedRoles)
|
|
|
|
|
-- traverse through `allRolesUnresolvedPermissionsMap` to record any inconsistencies (if exists)
|
|
|
|
|
resolvedPermissions <-
|
|
|
|
|
(|
|
|
|
|
|
traverseA
|
|
|
|
|
( \(roleName, checkPermission) -> do
|
|
|
|
|
let inconsistentRoleEntity = InconsistentRemoteSchemaPermission $ _rscName remoteSchemaCtx
|
|
|
|
|
resolvedCheckPermission <- resolveCheckPermission -< (checkPermission, roleName, inconsistentRoleEntity)
|
|
|
|
|
returnA -< (roleName, resolvedCheckPermission)
|
|
|
|
|
)
|
|
|
|
|
|) (M.toList allRolesUnresolvedPermissionsMap)
|
|
|
|
|
let remoteSchemaIntrospection = irDoc $ _rscIntroOriginal remoteSchemaCtx
|
|
|
|
|
resolvedRelationships <-
|
|
|
|
|
(|
|
|
|
|
|
traverseA
|
|
|
|
|
( \(typeName, typeRelationships) -> do
|
|
|
|
|
resolvedRelationships <-
|
|
|
|
|
(|
|
|
|
|
|
traverseA
|
|
|
|
|
( \fromSchemaDef ->
|
|
|
|
|
buildRemoteSchemaRemoteRelationship
|
|
|
|
|
-<
|
|
|
|
|
( (partiallyResolvedSources, remoteSchemaCtxMap),
|
|
|
|
|
(_rscName remoteSchemaCtx, remoteSchemaIntrospection, typeName, fromSchemaDef)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|) (_rstrsRelationships typeRelationships)
|
|
|
|
|
returnA -< (typeName, resolvedRelationships)
|
|
|
|
|
)
|
|
|
|
|
|) (OMap.toList relationships)
|
|
|
|
|
returnA
|
|
|
|
|
-<
|
|
|
|
|
( remoteSchemaCtx
|
|
|
|
|
{ _rscPermissions = M.mapMaybe id $ M.fromList resolvedPermissions,
|
|
|
|
|
_rscRemoteRelationships = OMap.mapMaybe id <$> OMap.fromList resolvedRelationships
|
|
|
|
|
},
|
|
|
|
|
metadataObj
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|)
|
|
|
|
|
|
2022-02-08 19:53:30 +03:00
|
|
|
|
-- allowlist
|
|
|
|
|
let inlinedAllowlist = inlineAllowlist collections metadataAllowlist
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-01-29 04:02:34 +03:00
|
|
|
|
resolvedEndpoints <- buildInfoMap fst mkEndpointMetadataObject buildEndpoint -< (collections, OMap.toList endpoints)
|
|
|
|
|
|
2020-02-13 20:38:23 +03:00
|
|
|
|
-- custom types
|
2021-02-14 09:07:52 +03:00
|
|
|
|
let scalarsMap = mconcat $ map snd $ M.elems sourcesOutput
|
2020-12-28 15:56:00 +03:00
|
|
|
|
sourcesCache = M.map fst sourcesOutput
|
2020-04-15 15:03:13 +03:00
|
|
|
|
maybeResolvedCustomTypes <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( bindErrorA -< resolveCustomTypes sourcesCache customTypes scalarsMap
|
|
|
|
|
)
|
|
|
|
|
|) (MetadataObject MOCustomTypes $ toJSON customTypes)
|
2020-02-13 20:38:23 +03:00
|
|
|
|
|
2021-01-20 03:31:53 +03:00
|
|
|
|
-- actions
|
2020-12-08 17:22:31 +03:00
|
|
|
|
let actionList = OMap.elems actions
|
Rewrite GraphQL schema generation and query parsing (close #2801) (#4111)
Aka “the PDV refactor.” History is preserved on the branch 2801-graphql-schema-parser-refactor.
* [skip ci] remove stale benchmark commit from commit_diff
* [skip ci] Check for root field name conflicts between remotes
* [skip ci] Additionally check for conflicts between remotes and DB
* [skip ci] Check for conflicts in schema when tracking a table
* [skip ci] Fix equality checking in GraphQL AST
* server: fix mishandling of GeoJSON inputs in subscriptions (fix #3239) (#4551)
* Add support for multiple top-level fields in a subscription to improve testability of subscriptions
* Add an internal flag to enable multiple subscriptions
* Add missing call to withConstructorFn in live queries (fix #3239)
Co-authored-by: Alexis King <lexi.lambda@gmail.com>
* Scheduled triggers (close #1914) (#3553)
server: add scheduled triggers
Co-authored-by: Alexis King <lexi.lambda@gmail.com>
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Co-authored-by: Aleksandra Sikora <ola.zxcvbnm@gmail.com>
* dev.sh: bump version due to addition of croniter python dependency
* server: fix an introspection query caching issue (fix #4547) (#4661)
Introspection queries accept variables, but we need to make sure to
also touch the variables that we ignore, so that an introspection
query is marked not reusable if we are not able to build a correct
query plan for it.
A better solution here would be to deal with such unused variables
correctly, so that more introspection queries become reusable.
An even better solution would be to type-safely track *how* to reuse
which variables, rather than to split the reusage marking from the
planning.
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* flush log buffer on exception in mkWaiApp ( fix #4772 ) (#4801)
* flush log buffer on exception in mkWaiApp
* add comment to explain the introduced change
* add changelog
* allow logging details of a live query polling thread (#4959)
* changes for poller-log
add various multiplexed query info in poller-log
* minor cleanup, also fixes a bug which will return duplicate data
* Live query poller stats can now be logged
This also removes in-memory stats that are collected about batched
query execution as the log lines when piped into an monitoring tool
will give us better insights.
* allow poller-log to be configurable
* log minimal information in the livequery-poller-log
Other information can be retrieved from /dev/subscriptions/extended
* fix few review comments
* avoid marshalling and unmarshalling from ByteString to EncJSON
* separate out SubscriberId and SubscriberMetadata
Co-authored-by: Anon Ray <rayanon004@gmail.com>
* Don't compile in developer APIs by default
* Tighten up handling of admin secret, more docs
Store the admin secret only as a hash to prevent leaking the secret
inadvertently, and to prevent timing attacks on the secret.
NOTE: best practice for stored user passwords is a function with a
tunable cost like bcrypt, but our threat model is quite different (even
if we thought we could reasonably protect the secret from an attacker
who could read arbitrary regions of memory), and bcrypt is far too slow
(by design) to perform on each request. We'd have to rely on our
(technically savvy) users to choose high entropy passwords in any case.
Referencing #4736
* server/docs: add instructions to fix loss of float precision in PostgreSQL <= 11 (#5187)
This adds a server flag, --pg-connection-options, that can be used to set a PostgreSQL connection parameter, extra_float_digits, that needs to be used to avoid loss of data on older versions of PostgreSQL, which have odd default behavior when returning float values. (fixes #5092)
* [skip ci] Add new commits from master to the commit diff
* [skip ci] serve default directives (skip & include) over introspection
* [skip ci] Update non-Haskell assets with the version on master
* server: refactor GQL execution check and config API (#5094)
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] fix js issues in tests by pinning dependencies version
* [skip ci] bump graphql version
* [skip ci] Add note about memory usage
* generalize query execution logic on Postgres (#5110)
* generalize PGExecCtx to support specialized functions for various operations
* fix tests compilation
* allow customising PGExecCtx when starting the web server
* server: changes catalog initialization and logging for pro customization (#5139)
* new typeclass to abstract the logic of QueryLog-ing
* abstract the logic of logging websocket-server logs
introduce a MonadWSLog typeclass
* move catalog initialization to init step
expose a helper function to migrate catalog
create schema cache in initialiseCtx
* expose various modules and functions for pro
* [skip ci] cosmetic change
* [skip ci] fix test calling a mutation that does not exist
* [skip ci] minor text change
* [skip ci] refactored input values
* [skip ci] remove VString Origin
* server: fix updating of headers behaviour in the update cron trigger API and create future events immediately (#5151)
* server: fix bug to update headers in an existing cron trigger and create future events
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* Lower stack chunk size in RTS to reduce thread STACK memory (closes #5190)
This reduces memory consumption for new idle subscriptions significantly
(see linked ticket).
The hypothesis is: we fork a lot of threads per websocket, and some of
these use slightly more than the initial 1K stack size, so the first
overflow balloons to 32K, when significantly less is required.
However: running with `+RTS -K1K -xc` did not seem to show evidence of
any overflows! So it's a mystery why this improves things.
GHC should probably also be doubling the stack buffer at each overflow
or doing something even smarter; the knobs we have aren't so helpful.
* [skip ci] fix todo and schema generation for aggregate fields
* 5087 libpq pool leak (#5089)
Shrink libpq buffers to 1MB before returning connection to pool. Closes #5087
See: https://github.com/hasura/pg-client-hs/pull/19
Also related: #3388 #4077
* bump pg-client-hs version (fixes a build issue on some environments) (#5267)
* do not use prepared statements for mutations
* server: unlock scheduled events on graceful shutdown (#4928)
* Fix buggy parsing of new --conn-lifetime flag in 2b0e3774
* [skip ci] remove cherry-picked commit from commit_diff.txt
* server: include additional fields in scheduled trigger webhook payload (#5262)
* include scheduled triggers metadata in the webhook body
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* server: call the webhook asynchronously in event triggers (#5352)
* server: call the webhook asynchronosly in event triggers
* Expose all modules in Cabal file (#5371)
* [skip ci] update commit_diff.txt
* [skip ci] fix cast exp parser & few TODOs
* [skip ci] fix remote fields arguments
* [skip ci] fix few more TODO, no-op refactor, move resolve/action.hs to execute/action.hs
* Pass environment variables around as a data structure, via @sordina (#5374)
* Pass environment variables around as a data structure, via @sordina
* Resolving build error
* Adding Environment passing note to changelog
* Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge
* removing commented-out imports
* Language pragmas already set by project
* Linking async thread
* Apply suggestions from code review
Use `runQueryTx` instead of `runLazyTx` for queries.
* remove the non-user facing entry in the changelog
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] fix: restrict remote relationship field generation for hasura queries
* [skip ci] no-op refactor; move insert execution code from schema parser module
* server: call the webhook asynchronously in event triggers (#5352)
* server: call the webhook asynchronosly in event triggers
* Expose all modules in Cabal file (#5371)
* [skip ci] update commit_diff.txt
* Pass environment variables around as a data structure, via @sordina (#5374)
* Pass environment variables around as a data structure, via @sordina
* Resolving build error
* Adding Environment passing note to changelog
* Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge
* removing commented-out imports
* Language pragmas already set by project
* Linking async thread
* Apply suggestions from code review
Use `runQueryTx` instead of `runLazyTx` for queries.
* remove the non-user facing entry in the changelog
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] implement header checking
Probably closes #14 and #3659.
* server: refactor 'pollQuery' to have a hook to process 'PollDetails' (#5391)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* update pg-client (#5421)
* [skip ci] update commit_diff
* Fix latency buckets for telemetry data
These must have gotten messed up during a refactor. As a consequence
almost all samples received so far fall into the single erroneous 0 to
1K seconds (originally supposed to be 1ms?) bucket.
I also re-thought what the numbers should be, but these are still
arbitrary and might want adjusting in the future.
* [skip ci] include the latest commit compared against master in commit_diff
* [skip ci] include new commits from master in commit_diff
* [skip ci] improve description generation
* [skip ci] sort all introspect arrays
* [skip ci] allow parsers to specify error codes
* [skip ci] fix integer and float parsing error code
* [skip ci] scalar from json errors are now parse errors
* [skip ci] fixed negative integer error message and code
* [skip ci] Re-fix nullability in relationships
* [skip ci] no-op refactor and removed couple of FIXMEs
* [skip ci] uncomment code in 'deleteMetadataObject'
* [skip ci] Fix re-fix of nullability for relationships
* [skip ci] fix default arguments error code
* [skip ci] updated test error message
!!! WARNING !!!
Since all fields accept `null`, they all are technically optional in
the new schema. Meaning there's no such thing as a missing mandatory
field anymore: a field that doesn't have a default value, and which
therefore isn't labelled as "optional" in the schema, will be assumed
to be null if it's missing, meaning it isn't possible anymore to have
an error for a missing mandatory field. The only possible error is now
when a optional positional argument is omitted but is not the last
positional argument.
* [skip ci] cleanup of int scalar parser
* [skip ci] retro-compatibility of offset as string
* [skip ci] Remove commit from commit_diff.txt
Although strictly speaking we don't know if this will work correctly in PDV
if we would implement query plan caching, the fact is that in the theoretical
case that we would have the same issue in PDV, it would probably apply not just
to introspection, and the fix would be written completely differently. So this
old commit is of no value to us other than the heads-up "make sure query plan
caching works correctly even in the presence of unused variables", which is
already part of the test suite.
* Add MonadTrace and MonadExecuteQuery abstractions (#5383)
* [skip ci] Fix accumulation of input object types
Just like object types, interface types, and union types, we have to avoid
circularities when collecting input types from the GraphQL AST.
Additionally, this fixes equality checks for input object types (whose fields
are unordered, and hence should be compared as sets) and enum types (ditto).
* [skip ci] fix fragment error path
* [skip ci] fix node error code
* [skip ci] fix paths in insert queries
* [skip ci] fix path in objects
* [skip ci] manually alter node id path for consistency
* [skip ci] more node error fixups
* [skip ci] one last relay error message fix
* [skip ci] update commit_diff
* Propagate the trace context to event triggers (#5409)
* Propagate the trace context to event triggers
* Handle missing trace and span IDs
* Store trace context as one LOCAL
* Add migrations
* Documentation
* changelog
* Fix warnings
* Respond to code review suggestions
* Respond to code review
* Undo changelog
* Update CHANGELOG.md
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* server: log request/response sizes for event triggers (#5463)
* server: log request/response sizes for event triggers
event triggers (and scheduled triggers) now have request/response size
in their logs.
* add changelog entry
* Tracing: Simplify HTTP traced request (#5451)
Remove the Inversion of Control (SuspendRequest) and simplify
the tracing of HTTP Requests.
Co-authored-by: Phil Freeman <phil@hasura.io>
* Attach request ID as tracing metadata (#5456)
* Propagate the trace context to event triggers
* Handle missing trace and span IDs
* Store trace context as one LOCAL
* Add migrations
* Documentation
* Include the request ID as trace metadata
* changelog
* Fix warnings
* Respond to code review suggestions
* Respond to code review
* Undo changelog
* Update CHANGELOG.md
* Typo
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* server: add logging for action handlers (#5471)
* server: add logging for action handlers
* add changelog entry
* change action-handler log type from internal to non-internal
* fix action-handler-log name
* server: pass http and websocket request to logging context (#5470)
* pass request body to logging context in all cases
* add message size logging on the websocket API
this is required by graphql-engine-pro/#416
* message size logging on websocket API
As we need to log all messages recieved/sent by the websocket server,
it makes sense to log them as part of the websocket server event logs.
Previously message recieved were logged inside the onMessage handler,
and messages sent were logged only for "data" messages (as a server event log)
* fix review comments
Co-authored-by: Phil Freeman <phil@hasura.io>
* server: stop eventing subsystem threads when shutting down (#5479)
* server: stop eventing subsystem threads when shutting down
* Apply suggestions from code review
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
* [skip ci] update commit_diff with new commits added in master
* Bugfix to support 0-size HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE
Also some minor refactoring of bounded cache module:
- the maxBound check in `trim` was confusing and unnecessary
- consequently trim was unnecessary for lookupPure
Also add some basic tests
* Support only the bounded cache, with default HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE of 4000. Closes #5363
* [skip ci] remove merge commit from commit_diff
* server: Fix compiler warning caused by GHC upgrade (#5489)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] update all non server code from master
* [skip ci] aligned object field error message with master
* [skip ci] fix remaining undefined?
* [skip ci] remove unused import
* [skip ci] revert to previous error message, fix tests
* Move nullableType/nonNullableType to Schema.hs
These are functions on Types, not on Parsers.
* [skip ci] fix setup to fix backend only test
the order in which permission checks are performed on the branch is
slightly different than on master, resulting in a slightly different
error if there are no other mutations the user has access to. By
adding update permissions, we go back to the expected case.
* [skip ci] fix insert geojson tests to reflect new paths
* [skip ci] fix enum test for better error message
* [skip ci] fix header test for better error message
* [skip ci] fix fragment cycle test for better error message
* [skip ci] fix error message for type mismatch
* [skip ci] fix variable path in test
* [skip ci] adjust tests after bug fix
* [skip ci] more tests fixing
* Add hdb_catalog.current_setting abstraction for reading Hasura settings
As the comment in the function’s definition explains, this is needed to
work around an awkward Postgres behavior.
* [skip ci] Update CONTRIBUTING.md to mention Node setup for Python tests
* [skip ci] Add missing Python tests env var to CONTRIBUTING.md
* [skip ci] fix order of result when subscription is run with multiple nodes
* [skip ci] no-op refactor: fix a warning in Internal/Parser.hs
* [skip ci] throw error when a subscription contains remote joins
* [skip ci] Enable easier profiling by hiding AssertNF behind a flag
In order to compile a profiling build, run:
$ cabal new-build -f profiling --enable-profiling
* [skip ci] Fix two warnings
We used to lookup the objects that implement a given interface by filtering all
objects in the schema document. However, one of the tests expects us to
generate a warning if the provided `implements` field of an introspection query
specifies an object not implementing some interface. So we use that field
instead.
* [skip ci] Fix warnings by commenting out query plan caching
* [skip ci] improve masking/commenting query caching related code & few warning fixes
* [skip ci] Fixed compiler warnings in graphql-parser-hs
* Sync non-Haskell assets with master
* [skip ci] add a test inserting invalid GraphQL but valid JSON value in a jsonb column
* [skip ci] Avoid converting to/from Map
* [skip ci] Apply some hlint suggestions
* [skip ci] remove redundant constraints from buildLiveQueryPlan and explainGQLQuery
* [skip ci] add NOTEs about missing Tracing constraints in PDV from master
* Remove -fdefer-typed-holes, fix warnings
* Update cabal.project.freeze
* Limit GHC’s heap size to 8GB in CI to avoid the OOM killer
* Commit package-lock.json for Python tests’ remote schema server
* restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers
* update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* add test for table_by_pk node when roles doesn't have permission to PK
* [skip ci] fix introspection query if any enum column present in primary key (fix #5200) (#5522)
* [skip ci] test case fix for a6450e126bc2d98bcfd3791501986e4627ce6c6f
* [skip ci] add tests to agg queries when role doesn't have access to any cols
* fix backend test
* Simplify subscription execution
* [skip ci] add test to check if required headers are present while querying
* Suppose, table B is related to table A and to query B certain headers are
necessary, then the test checks that we are throwing error when the header
is not set when B is queried through A
* fix mutations not checking for view mutability
* [skip ci] add variable type checking and corresponding tests
* [skip ci] add test to check if update headers are present while doing an upsert
* [skip ci] add positive counterparts to some of the negative permission tests
* fix args missing their description in introspect
* [skip ci] Remove unused function; insert missing markNotReusable call
* [skip ci] Add a Note about InputValue
* [skip ci] Delete LegacySchema/ 🎉
* [skip ci] Delete GraphQL/{Resolve,Validate}/ 🎉
* [skip ci] Delete top-level Resolve/Validate modules; tidy .cabal file
* [skip ci] Delete LegacySchema top-level module
Somehow I missed this one.
* fix input value to json
* [skip ci] elaborate on JSON objects in GraphQL
* [skip ci] add missing file
* [skip ci] add a test with subscription containing remote joins
* add a test with remote joins in mutation output
* [skip ci] Add some comments to Schema/Mutation.hs
* [skip ci] Remove no longer needed code from RemoteServer.hs
* [skip ci] Use a helper function to generate conflict clause parsers
* [skip ci] fix type checker error in fields with default value
* capitalize the header keys in select_articles_without_required_headers
* Somehow, this was the reason the tests were failing. I have no idea, why!
* [skip ci] Add a long Note about optional fields and nullability
* Improve comments a bit; simplify Schema/Common.hs a bit
* [skip ci] full implementation of 5.8.5 type checking.
* [skip ci] fix validation test teardown
* [skip ci] fix schema stitching test
* fix remote schema ignoring enum nullability
* [skip ci] fix fieldOptional to not discard nullability
* revert nullability of use_spheroid
* fix comment
* add required remote fields with arguments for tests
* [skip ci] add missing docstrings
* [skip ci] fixed description of remote fields
* [skip ci] change docstring for consistency
* fix several schema inconsistencies
* revert behaviour change in function arguments parsing
* fix remaining nullability issues in new schema
* minor no-op refactor; use isListType from graphql-parser-hs
* use nullability of remote schema node, while creating a Remote reln
* fix 'ID' input coercing & action 'ID' type relationship mapping
* include ASTs in MonadExecuteQuery
* needed for PRO code-base
* Delete code for "interfaces implementing ifaces" (draft GraphQL spec)
Previously I started writing some code that adds support for a future GraphQL
feature where interfaces may themselves be sub-types of other interfaces.
However, this code was incomplete, and partially incorrect. So this commit
deletes support for that entirely.
* Ignore a remote schema test during the upgrade/downgrade test
The PDV refactor does a better job at exposing a minimal set of types through
introspection. In particular, not every type that is present in a remote schema
is re-exposed by Hasura. The test
test_schema_stitching.py::TestRemoteSchemaBasic::test_introspection assumed that
all types were re-exposed, which is not required for GraphQL compatibility, in
order to test some aspect of our support for remote schemas.
So while this particular test has been updated on PDV, the PDV branch now does
not pass the old test, which we argue to be incorrect. Hence this test is
disabled while we await a release, after which we can re-enable it.
This also re-enables a test that was previously disabled for similar, though
unrelated, reasons.
* add haddock documentation to the action's field parsers
* Deslecting some tests in server-upgrade
Some tests with current build are failing on server upgrade
which it should not. The response is more accurate than
what it was.
Also the upgrade tests were not throwing errors when the test is
expected to return an error, but succeeds. The test framework is
patched to catch this case.
* [skip ci] Add a long Note about interfaces and object types
* send the response headers back to client after running a query
* Deselect a few more tests during upgrade/downgrade test
* Update commit_diff.txt
* change log kind from db_migrate to catalog_migrate (#5531)
* Show method and complete URI in traced HTTP calls (#5525)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers
* update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* fix introspection query if any enum column present in primary key (fix #5200) (#5522)
* Fix telemetry reporting of transport (websocket was reported as http)
* add log kinds in cli-migrations image (#5529)
* add log kinds in cli-migrations image
* give hint to resolve timeout error
* minor changes and CHANGELOG
* server: set hasura.tracecontext in RQL mutations [#5542] (#5555)
* server: set hasura.tracecontext in RQL mutations [#5542]
* Update test suite
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* Add bulldozer auto-merge and -update configuration
We still need to add the github app (as of time of opening this PR)
Afterwards devs should be able to allow bulldozer to automatically
"update" the branch, merging in parent when it changes, as well as
automatically merge when all checks pass.
This is opt-in by adding the `auto-update-auto-merge` label to the PR.
* Remove 'bulldozer' config, try 'kodiak' for auto-merge
see: https://github.com/chdsbd/kodiak
The main issue that bit us was not being able to auto update forked
branches, also:
https://github.com/palantir/bulldozer/issues/66
https://github.com/palantir/bulldozer/issues/145
* Cherry-picked all commits
* [skip ci] Slightly improve formatting
* Revert "fix introspection query if any enum column present in primary key (fix #5200) (#5522)"
This reverts commit 0f9a5afa59a88f6824f4d63d58db246a5ba3fb03.
This undoes a cherry-pick of 34288e1eb5f2c5dad9e6d1e05453dd52397dc970 that was
already done previously in a6450e126bc2d98bcfd3791501986e4627ce6c6f, and
subsequently fixed for PDV in 70e89dc250f8ddc6e2b7930bbe2b3eeaa6dbe1db
* Do a small bit of tidying in Hasura.GraphQL.Parser.Collect
* Fix cherry-picking work
Some previous cherry-picks ended up modifying code that is commented out
* [skip ci] clarified comment regarding insert representation
* [skip ci] removed obsolete todos
* cosmetic change
* fix action error message
* [skip ci] remove obsolete comment
* [skip ci] synchronize stylish haskell extensions list
* use previously defined scalar names in parsers rather than ad-hoc literals
* Apply most syntax hlint hints.
* Clarify comment on update mutation.
* [skip ci] Clarify what fields should be specified for objects
* Update "_inc" description.
* Use record types rather than tuples fo IntrospectionResult and ParsedIntrospection
* Get rid of checkFieldNamesUnique (use Data.List.Extended.duplicates)
* Throw more errors when collecting query root names
* [skip ci] clean column parser comment
* Remove dead code inserted in ab65b39
* avoid converting to non-empty list where not needed
* add note and TODO about the disabled checks in PDV
* minor refactor in remoteField' function
* Unify two getObject methods
* Nitpicks in Remote.hs
* Update CHANGELOG.md
* Revert "Unify two getObject methods"
This reverts commit bd6bb40355b3d189a46c0312eb52225e18be57b3.
We do need two different getObject functions as the corresponding error message is different
* Fix error message in Remote.hs
* Update CHANGELOG.md
Co-authored-by: Auke Booij <auke@tulcod.com>
* Apply suggested Changelog fix.
Co-authored-by: Auke Booij <auke@tulcod.com>
* Fix typo in Changelog.
* [skip ci] Update changelog.
* reuse type names to avoid duplication
* Fix Hashable instance for Definition
The presence of `Maybe Unique`, and an optional description, as part of
`Definition`s, means that `Definition`s that are considered `Eq`ual may get
different hashes. This can happen, for instance, when one object is memoized
but another is not.
* [skip ci] Update commit_diff.txt
* Bump parser version.
* Bump freeze file after changes in parser.
* [skip ci] Incorporate commits from master
* Fix developer flag in server/cabal.project.freeze
Co-authored-by: Auke Booij <auke@tulcod.com>
* Deselect a changed ENUM test for upgrade/downgrade CI
* Deselect test here as well
* [skip ci] remove dead code
* Disable more tests for upgrade/downgrade
* Fix which test gets deselected
* Revert "Add hdb_catalog.current_setting abstraction for reading Hasura settings"
This reverts commit 66e85ab9fbd56cca2c28a80201f6604fbe811b85.
* Remove circular reference in cabal.project.freeze
Co-authored-by: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Co-authored-by: Auke Booij <auke@hasura.io>
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Aleksandra Sikora <ola.zxcvbnm@gmail.com>
Co-authored-by: Brandon Simmons <brandon.m.simmons@gmail.com>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
Co-authored-by: Anon Ray <rayanon004@gmail.com>
Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com>
Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com>
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Antoine Leblanc <antoine@hasura.io>
Co-authored-by: Brandon Simmons <brandon@hasura.io>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Lyndon Maydwell <lyndon@sordina.net>
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Naveen Naidu <naveennaidu479@gmail.com>
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
Co-authored-by: Nizar Malangadan <nizar-m@users.noreply.github.com>
Co-authored-by: Antoine Leblanc <crucuny@gmail.com>
Co-authored-by: Auke Booij <auke@tulcod.com>
2020-08-21 20:27:01 +03:00
|
|
|
|
(actionCache, annotatedCustomTypes) <- case maybeResolvedCustomTypes of
|
|
|
|
|
Just resolvedCustomTypes -> do
|
2021-08-09 13:20:04 +03:00
|
|
|
|
actionCache' <- buildActions -< ((resolvedCustomTypes, scalarsMap, orderedRoles), actionList)
|
Rewrite GraphQL schema generation and query parsing (close #2801) (#4111)
Aka “the PDV refactor.” History is preserved on the branch 2801-graphql-schema-parser-refactor.
* [skip ci] remove stale benchmark commit from commit_diff
* [skip ci] Check for root field name conflicts between remotes
* [skip ci] Additionally check for conflicts between remotes and DB
* [skip ci] Check for conflicts in schema when tracking a table
* [skip ci] Fix equality checking in GraphQL AST
* server: fix mishandling of GeoJSON inputs in subscriptions (fix #3239) (#4551)
* Add support for multiple top-level fields in a subscription to improve testability of subscriptions
* Add an internal flag to enable multiple subscriptions
* Add missing call to withConstructorFn in live queries (fix #3239)
Co-authored-by: Alexis King <lexi.lambda@gmail.com>
* Scheduled triggers (close #1914) (#3553)
server: add scheduled triggers
Co-authored-by: Alexis King <lexi.lambda@gmail.com>
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Co-authored-by: Aleksandra Sikora <ola.zxcvbnm@gmail.com>
* dev.sh: bump version due to addition of croniter python dependency
* server: fix an introspection query caching issue (fix #4547) (#4661)
Introspection queries accept variables, but we need to make sure to
also touch the variables that we ignore, so that an introspection
query is marked not reusable if we are not able to build a correct
query plan for it.
A better solution here would be to deal with such unused variables
correctly, so that more introspection queries become reusable.
An even better solution would be to type-safely track *how* to reuse
which variables, rather than to split the reusage marking from the
planning.
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* flush log buffer on exception in mkWaiApp ( fix #4772 ) (#4801)
* flush log buffer on exception in mkWaiApp
* add comment to explain the introduced change
* add changelog
* allow logging details of a live query polling thread (#4959)
* changes for poller-log
add various multiplexed query info in poller-log
* minor cleanup, also fixes a bug which will return duplicate data
* Live query poller stats can now be logged
This also removes in-memory stats that are collected about batched
query execution as the log lines when piped into an monitoring tool
will give us better insights.
* allow poller-log to be configurable
* log minimal information in the livequery-poller-log
Other information can be retrieved from /dev/subscriptions/extended
* fix few review comments
* avoid marshalling and unmarshalling from ByteString to EncJSON
* separate out SubscriberId and SubscriberMetadata
Co-authored-by: Anon Ray <rayanon004@gmail.com>
* Don't compile in developer APIs by default
* Tighten up handling of admin secret, more docs
Store the admin secret only as a hash to prevent leaking the secret
inadvertently, and to prevent timing attacks on the secret.
NOTE: best practice for stored user passwords is a function with a
tunable cost like bcrypt, but our threat model is quite different (even
if we thought we could reasonably protect the secret from an attacker
who could read arbitrary regions of memory), and bcrypt is far too slow
(by design) to perform on each request. We'd have to rely on our
(technically savvy) users to choose high entropy passwords in any case.
Referencing #4736
* server/docs: add instructions to fix loss of float precision in PostgreSQL <= 11 (#5187)
This adds a server flag, --pg-connection-options, that can be used to set a PostgreSQL connection parameter, extra_float_digits, that needs to be used to avoid loss of data on older versions of PostgreSQL, which have odd default behavior when returning float values. (fixes #5092)
* [skip ci] Add new commits from master to the commit diff
* [skip ci] serve default directives (skip & include) over introspection
* [skip ci] Update non-Haskell assets with the version on master
* server: refactor GQL execution check and config API (#5094)
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] fix js issues in tests by pinning dependencies version
* [skip ci] bump graphql version
* [skip ci] Add note about memory usage
* generalize query execution logic on Postgres (#5110)
* generalize PGExecCtx to support specialized functions for various operations
* fix tests compilation
* allow customising PGExecCtx when starting the web server
* server: changes catalog initialization and logging for pro customization (#5139)
* new typeclass to abstract the logic of QueryLog-ing
* abstract the logic of logging websocket-server logs
introduce a MonadWSLog typeclass
* move catalog initialization to init step
expose a helper function to migrate catalog
create schema cache in initialiseCtx
* expose various modules and functions for pro
* [skip ci] cosmetic change
* [skip ci] fix test calling a mutation that does not exist
* [skip ci] minor text change
* [skip ci] refactored input values
* [skip ci] remove VString Origin
* server: fix updating of headers behaviour in the update cron trigger API and create future events immediately (#5151)
* server: fix bug to update headers in an existing cron trigger and create future events
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* Lower stack chunk size in RTS to reduce thread STACK memory (closes #5190)
This reduces memory consumption for new idle subscriptions significantly
(see linked ticket).
The hypothesis is: we fork a lot of threads per websocket, and some of
these use slightly more than the initial 1K stack size, so the first
overflow balloons to 32K, when significantly less is required.
However: running with `+RTS -K1K -xc` did not seem to show evidence of
any overflows! So it's a mystery why this improves things.
GHC should probably also be doubling the stack buffer at each overflow
or doing something even smarter; the knobs we have aren't so helpful.
* [skip ci] fix todo and schema generation for aggregate fields
* 5087 libpq pool leak (#5089)
Shrink libpq buffers to 1MB before returning connection to pool. Closes #5087
See: https://github.com/hasura/pg-client-hs/pull/19
Also related: #3388 #4077
* bump pg-client-hs version (fixes a build issue on some environments) (#5267)
* do not use prepared statements for mutations
* server: unlock scheduled events on graceful shutdown (#4928)
* Fix buggy parsing of new --conn-lifetime flag in 2b0e3774
* [skip ci] remove cherry-picked commit from commit_diff.txt
* server: include additional fields in scheduled trigger webhook payload (#5262)
* include scheduled triggers metadata in the webhook body
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* server: call the webhook asynchronously in event triggers (#5352)
* server: call the webhook asynchronosly in event triggers
* Expose all modules in Cabal file (#5371)
* [skip ci] update commit_diff.txt
* [skip ci] fix cast exp parser & few TODOs
* [skip ci] fix remote fields arguments
* [skip ci] fix few more TODO, no-op refactor, move resolve/action.hs to execute/action.hs
* Pass environment variables around as a data structure, via @sordina (#5374)
* Pass environment variables around as a data structure, via @sordina
* Resolving build error
* Adding Environment passing note to changelog
* Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge
* removing commented-out imports
* Language pragmas already set by project
* Linking async thread
* Apply suggestions from code review
Use `runQueryTx` instead of `runLazyTx` for queries.
* remove the non-user facing entry in the changelog
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] fix: restrict remote relationship field generation for hasura queries
* [skip ci] no-op refactor; move insert execution code from schema parser module
* server: call the webhook asynchronously in event triggers (#5352)
* server: call the webhook asynchronosly in event triggers
* Expose all modules in Cabal file (#5371)
* [skip ci] update commit_diff.txt
* Pass environment variables around as a data structure, via @sordina (#5374)
* Pass environment variables around as a data structure, via @sordina
* Resolving build error
* Adding Environment passing note to changelog
* Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge
* removing commented-out imports
* Language pragmas already set by project
* Linking async thread
* Apply suggestions from code review
Use `runQueryTx` instead of `runLazyTx` for queries.
* remove the non-user facing entry in the changelog
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] implement header checking
Probably closes #14 and #3659.
* server: refactor 'pollQuery' to have a hook to process 'PollDetails' (#5391)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* update pg-client (#5421)
* [skip ci] update commit_diff
* Fix latency buckets for telemetry data
These must have gotten messed up during a refactor. As a consequence
almost all samples received so far fall into the single erroneous 0 to
1K seconds (originally supposed to be 1ms?) bucket.
I also re-thought what the numbers should be, but these are still
arbitrary and might want adjusting in the future.
* [skip ci] include the latest commit compared against master in commit_diff
* [skip ci] include new commits from master in commit_diff
* [skip ci] improve description generation
* [skip ci] sort all introspect arrays
* [skip ci] allow parsers to specify error codes
* [skip ci] fix integer and float parsing error code
* [skip ci] scalar from json errors are now parse errors
* [skip ci] fixed negative integer error message and code
* [skip ci] Re-fix nullability in relationships
* [skip ci] no-op refactor and removed couple of FIXMEs
* [skip ci] uncomment code in 'deleteMetadataObject'
* [skip ci] Fix re-fix of nullability for relationships
* [skip ci] fix default arguments error code
* [skip ci] updated test error message
!!! WARNING !!!
Since all fields accept `null`, they all are technically optional in
the new schema. Meaning there's no such thing as a missing mandatory
field anymore: a field that doesn't have a default value, and which
therefore isn't labelled as "optional" in the schema, will be assumed
to be null if it's missing, meaning it isn't possible anymore to have
an error for a missing mandatory field. The only possible error is now
when a optional positional argument is omitted but is not the last
positional argument.
* [skip ci] cleanup of int scalar parser
* [skip ci] retro-compatibility of offset as string
* [skip ci] Remove commit from commit_diff.txt
Although strictly speaking we don't know if this will work correctly in PDV
if we would implement query plan caching, the fact is that in the theoretical
case that we would have the same issue in PDV, it would probably apply not just
to introspection, and the fix would be written completely differently. So this
old commit is of no value to us other than the heads-up "make sure query plan
caching works correctly even in the presence of unused variables", which is
already part of the test suite.
* Add MonadTrace and MonadExecuteQuery abstractions (#5383)
* [skip ci] Fix accumulation of input object types
Just like object types, interface types, and union types, we have to avoid
circularities when collecting input types from the GraphQL AST.
Additionally, this fixes equality checks for input object types (whose fields
are unordered, and hence should be compared as sets) and enum types (ditto).
* [skip ci] fix fragment error path
* [skip ci] fix node error code
* [skip ci] fix paths in insert queries
* [skip ci] fix path in objects
* [skip ci] manually alter node id path for consistency
* [skip ci] more node error fixups
* [skip ci] one last relay error message fix
* [skip ci] update commit_diff
* Propagate the trace context to event triggers (#5409)
* Propagate the trace context to event triggers
* Handle missing trace and span IDs
* Store trace context as one LOCAL
* Add migrations
* Documentation
* changelog
* Fix warnings
* Respond to code review suggestions
* Respond to code review
* Undo changelog
* Update CHANGELOG.md
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* server: log request/response sizes for event triggers (#5463)
* server: log request/response sizes for event triggers
event triggers (and scheduled triggers) now have request/response size
in their logs.
* add changelog entry
* Tracing: Simplify HTTP traced request (#5451)
Remove the Inversion of Control (SuspendRequest) and simplify
the tracing of HTTP Requests.
Co-authored-by: Phil Freeman <phil@hasura.io>
* Attach request ID as tracing metadata (#5456)
* Propagate the trace context to event triggers
* Handle missing trace and span IDs
* Store trace context as one LOCAL
* Add migrations
* Documentation
* Include the request ID as trace metadata
* changelog
* Fix warnings
* Respond to code review suggestions
* Respond to code review
* Undo changelog
* Update CHANGELOG.md
* Typo
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* server: add logging for action handlers (#5471)
* server: add logging for action handlers
* add changelog entry
* change action-handler log type from internal to non-internal
* fix action-handler-log name
* server: pass http and websocket request to logging context (#5470)
* pass request body to logging context in all cases
* add message size logging on the websocket API
this is required by graphql-engine-pro/#416
* message size logging on websocket API
As we need to log all messages recieved/sent by the websocket server,
it makes sense to log them as part of the websocket server event logs.
Previously message recieved were logged inside the onMessage handler,
and messages sent were logged only for "data" messages (as a server event log)
* fix review comments
Co-authored-by: Phil Freeman <phil@hasura.io>
* server: stop eventing subsystem threads when shutting down (#5479)
* server: stop eventing subsystem threads when shutting down
* Apply suggestions from code review
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
* [skip ci] update commit_diff with new commits added in master
* Bugfix to support 0-size HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE
Also some minor refactoring of bounded cache module:
- the maxBound check in `trim` was confusing and unnecessary
- consequently trim was unnecessary for lookupPure
Also add some basic tests
* Support only the bounded cache, with default HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE of 4000. Closes #5363
* [skip ci] remove merge commit from commit_diff
* server: Fix compiler warning caused by GHC upgrade (#5489)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] update all non server code from master
* [skip ci] aligned object field error message with master
* [skip ci] fix remaining undefined?
* [skip ci] remove unused import
* [skip ci] revert to previous error message, fix tests
* Move nullableType/nonNullableType to Schema.hs
These are functions on Types, not on Parsers.
* [skip ci] fix setup to fix backend only test
the order in which permission checks are performed on the branch is
slightly different than on master, resulting in a slightly different
error if there are no other mutations the user has access to. By
adding update permissions, we go back to the expected case.
* [skip ci] fix insert geojson tests to reflect new paths
* [skip ci] fix enum test for better error message
* [skip ci] fix header test for better error message
* [skip ci] fix fragment cycle test for better error message
* [skip ci] fix error message for type mismatch
* [skip ci] fix variable path in test
* [skip ci] adjust tests after bug fix
* [skip ci] more tests fixing
* Add hdb_catalog.current_setting abstraction for reading Hasura settings
As the comment in the function’s definition explains, this is needed to
work around an awkward Postgres behavior.
* [skip ci] Update CONTRIBUTING.md to mention Node setup for Python tests
* [skip ci] Add missing Python tests env var to CONTRIBUTING.md
* [skip ci] fix order of result when subscription is run with multiple nodes
* [skip ci] no-op refactor: fix a warning in Internal/Parser.hs
* [skip ci] throw error when a subscription contains remote joins
* [skip ci] Enable easier profiling by hiding AssertNF behind a flag
In order to compile a profiling build, run:
$ cabal new-build -f profiling --enable-profiling
* [skip ci] Fix two warnings
We used to lookup the objects that implement a given interface by filtering all
objects in the schema document. However, one of the tests expects us to
generate a warning if the provided `implements` field of an introspection query
specifies an object not implementing some interface. So we use that field
instead.
* [skip ci] Fix warnings by commenting out query plan caching
* [skip ci] improve masking/commenting query caching related code & few warning fixes
* [skip ci] Fixed compiler warnings in graphql-parser-hs
* Sync non-Haskell assets with master
* [skip ci] add a test inserting invalid GraphQL but valid JSON value in a jsonb column
* [skip ci] Avoid converting to/from Map
* [skip ci] Apply some hlint suggestions
* [skip ci] remove redundant constraints from buildLiveQueryPlan and explainGQLQuery
* [skip ci] add NOTEs about missing Tracing constraints in PDV from master
* Remove -fdefer-typed-holes, fix warnings
* Update cabal.project.freeze
* Limit GHC’s heap size to 8GB in CI to avoid the OOM killer
* Commit package-lock.json for Python tests’ remote schema server
* restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers
* update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* add test for table_by_pk node when roles doesn't have permission to PK
* [skip ci] fix introspection query if any enum column present in primary key (fix #5200) (#5522)
* [skip ci] test case fix for a6450e126bc2d98bcfd3791501986e4627ce6c6f
* [skip ci] add tests to agg queries when role doesn't have access to any cols
* fix backend test
* Simplify subscription execution
* [skip ci] add test to check if required headers are present while querying
* Suppose, table B is related to table A and to query B certain headers are
necessary, then the test checks that we are throwing error when the header
is not set when B is queried through A
* fix mutations not checking for view mutability
* [skip ci] add variable type checking and corresponding tests
* [skip ci] add test to check if update headers are present while doing an upsert
* [skip ci] add positive counterparts to some of the negative permission tests
* fix args missing their description in introspect
* [skip ci] Remove unused function; insert missing markNotReusable call
* [skip ci] Add a Note about InputValue
* [skip ci] Delete LegacySchema/ 🎉
* [skip ci] Delete GraphQL/{Resolve,Validate}/ 🎉
* [skip ci] Delete top-level Resolve/Validate modules; tidy .cabal file
* [skip ci] Delete LegacySchema top-level module
Somehow I missed this one.
* fix input value to json
* [skip ci] elaborate on JSON objects in GraphQL
* [skip ci] add missing file
* [skip ci] add a test with subscription containing remote joins
* add a test with remote joins in mutation output
* [skip ci] Add some comments to Schema/Mutation.hs
* [skip ci] Remove no longer needed code from RemoteServer.hs
* [skip ci] Use a helper function to generate conflict clause parsers
* [skip ci] fix type checker error in fields with default value
* capitalize the header keys in select_articles_without_required_headers
* Somehow, this was the reason the tests were failing. I have no idea, why!
* [skip ci] Add a long Note about optional fields and nullability
* Improve comments a bit; simplify Schema/Common.hs a bit
* [skip ci] full implementation of 5.8.5 type checking.
* [skip ci] fix validation test teardown
* [skip ci] fix schema stitching test
* fix remote schema ignoring enum nullability
* [skip ci] fix fieldOptional to not discard nullability
* revert nullability of use_spheroid
* fix comment
* add required remote fields with arguments for tests
* [skip ci] add missing docstrings
* [skip ci] fixed description of remote fields
* [skip ci] change docstring for consistency
* fix several schema inconsistencies
* revert behaviour change in function arguments parsing
* fix remaining nullability issues in new schema
* minor no-op refactor; use isListType from graphql-parser-hs
* use nullability of remote schema node, while creating a Remote reln
* fix 'ID' input coercing & action 'ID' type relationship mapping
* include ASTs in MonadExecuteQuery
* needed for PRO code-base
* Delete code for "interfaces implementing ifaces" (draft GraphQL spec)
Previously I started writing some code that adds support for a future GraphQL
feature where interfaces may themselves be sub-types of other interfaces.
However, this code was incomplete, and partially incorrect. So this commit
deletes support for that entirely.
* Ignore a remote schema test during the upgrade/downgrade test
The PDV refactor does a better job at exposing a minimal set of types through
introspection. In particular, not every type that is present in a remote schema
is re-exposed by Hasura. The test
test_schema_stitching.py::TestRemoteSchemaBasic::test_introspection assumed that
all types were re-exposed, which is not required for GraphQL compatibility, in
order to test some aspect of our support for remote schemas.
So while this particular test has been updated on PDV, the PDV branch now does
not pass the old test, which we argue to be incorrect. Hence this test is
disabled while we await a release, after which we can re-enable it.
This also re-enables a test that was previously disabled for similar, though
unrelated, reasons.
* add haddock documentation to the action's field parsers
* Deslecting some tests in server-upgrade
Some tests with current build are failing on server upgrade
which it should not. The response is more accurate than
what it was.
Also the upgrade tests were not throwing errors when the test is
expected to return an error, but succeeds. The test framework is
patched to catch this case.
* [skip ci] Add a long Note about interfaces and object types
* send the response headers back to client after running a query
* Deselect a few more tests during upgrade/downgrade test
* Update commit_diff.txt
* change log kind from db_migrate to catalog_migrate (#5531)
* Show method and complete URI in traced HTTP calls (#5525)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers
* update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* fix introspection query if any enum column present in primary key (fix #5200) (#5522)
* Fix telemetry reporting of transport (websocket was reported as http)
* add log kinds in cli-migrations image (#5529)
* add log kinds in cli-migrations image
* give hint to resolve timeout error
* minor changes and CHANGELOG
* server: set hasura.tracecontext in RQL mutations [#5542] (#5555)
* server: set hasura.tracecontext in RQL mutations [#5542]
* Update test suite
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* Add bulldozer auto-merge and -update configuration
We still need to add the github app (as of time of opening this PR)
Afterwards devs should be able to allow bulldozer to automatically
"update" the branch, merging in parent when it changes, as well as
automatically merge when all checks pass.
This is opt-in by adding the `auto-update-auto-merge` label to the PR.
* Remove 'bulldozer' config, try 'kodiak' for auto-merge
see: https://github.com/chdsbd/kodiak
The main issue that bit us was not being able to auto update forked
branches, also:
https://github.com/palantir/bulldozer/issues/66
https://github.com/palantir/bulldozer/issues/145
* Cherry-picked all commits
* [skip ci] Slightly improve formatting
* Revert "fix introspection query if any enum column present in primary key (fix #5200) (#5522)"
This reverts commit 0f9a5afa59a88f6824f4d63d58db246a5ba3fb03.
This undoes a cherry-pick of 34288e1eb5f2c5dad9e6d1e05453dd52397dc970 that was
already done previously in a6450e126bc2d98bcfd3791501986e4627ce6c6f, and
subsequently fixed for PDV in 70e89dc250f8ddc6e2b7930bbe2b3eeaa6dbe1db
* Do a small bit of tidying in Hasura.GraphQL.Parser.Collect
* Fix cherry-picking work
Some previous cherry-picks ended up modifying code that is commented out
* [skip ci] clarified comment regarding insert representation
* [skip ci] removed obsolete todos
* cosmetic change
* fix action error message
* [skip ci] remove obsolete comment
* [skip ci] synchronize stylish haskell extensions list
* use previously defined scalar names in parsers rather than ad-hoc literals
* Apply most syntax hlint hints.
* Clarify comment on update mutation.
* [skip ci] Clarify what fields should be specified for objects
* Update "_inc" description.
* Use record types rather than tuples fo IntrospectionResult and ParsedIntrospection
* Get rid of checkFieldNamesUnique (use Data.List.Extended.duplicates)
* Throw more errors when collecting query root names
* [skip ci] clean column parser comment
* Remove dead code inserted in ab65b39
* avoid converting to non-empty list where not needed
* add note and TODO about the disabled checks in PDV
* minor refactor in remoteField' function
* Unify two getObject methods
* Nitpicks in Remote.hs
* Update CHANGELOG.md
* Revert "Unify two getObject methods"
This reverts commit bd6bb40355b3d189a46c0312eb52225e18be57b3.
We do need two different getObject functions as the corresponding error message is different
* Fix error message in Remote.hs
* Update CHANGELOG.md
Co-authored-by: Auke Booij <auke@tulcod.com>
* Apply suggested Changelog fix.
Co-authored-by: Auke Booij <auke@tulcod.com>
* Fix typo in Changelog.
* [skip ci] Update changelog.
* reuse type names to avoid duplication
* Fix Hashable instance for Definition
The presence of `Maybe Unique`, and an optional description, as part of
`Definition`s, means that `Definition`s that are considered `Eq`ual may get
different hashes. This can happen, for instance, when one object is memoized
but another is not.
* [skip ci] Update commit_diff.txt
* Bump parser version.
* Bump freeze file after changes in parser.
* [skip ci] Incorporate commits from master
* Fix developer flag in server/cabal.project.freeze
Co-authored-by: Auke Booij <auke@tulcod.com>
* Deselect a changed ENUM test for upgrade/downgrade CI
* Deselect test here as well
* [skip ci] remove dead code
* Disable more tests for upgrade/downgrade
* Fix which test gets deselected
* Revert "Add hdb_catalog.current_setting abstraction for reading Hasura settings"
This reverts commit 66e85ab9fbd56cca2c28a80201f6604fbe811b85.
* Remove circular reference in cabal.project.freeze
Co-authored-by: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Co-authored-by: Auke Booij <auke@hasura.io>
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Aleksandra Sikora <ola.zxcvbnm@gmail.com>
Co-authored-by: Brandon Simmons <brandon.m.simmons@gmail.com>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
Co-authored-by: Anon Ray <rayanon004@gmail.com>
Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com>
Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com>
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Antoine Leblanc <antoine@hasura.io>
Co-authored-by: Brandon Simmons <brandon@hasura.io>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Lyndon Maydwell <lyndon@sordina.net>
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Naveen Naidu <naveennaidu479@gmail.com>
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
Co-authored-by: Nizar Malangadan <nizar-m@users.noreply.github.com>
Co-authored-by: Antoine Leblanc <crucuny@gmail.com>
Co-authored-by: Auke Booij <auke@tulcod.com>
2020-08-21 20:27:01 +03:00
|
|
|
|
returnA -< (actionCache', resolvedCustomTypes)
|
2020-04-15 15:03:13 +03:00
|
|
|
|
|
|
|
|
|
-- If the custom types themselves are inconsistent, we can’t really do
|
|
|
|
|
-- anything with actions, so just mark them all inconsistent.
|
|
|
|
|
Nothing -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
recordInconsistencies
|
|
|
|
|
-<
|
|
|
|
|
( map mkActionMetadataObject actionList,
|
|
|
|
|
"custom types are inconsistent"
|
|
|
|
|
)
|
Rewrite GraphQL schema generation and query parsing (close #2801) (#4111)
Aka “the PDV refactor.” History is preserved on the branch 2801-graphql-schema-parser-refactor.
* [skip ci] remove stale benchmark commit from commit_diff
* [skip ci] Check for root field name conflicts between remotes
* [skip ci] Additionally check for conflicts between remotes and DB
* [skip ci] Check for conflicts in schema when tracking a table
* [skip ci] Fix equality checking in GraphQL AST
* server: fix mishandling of GeoJSON inputs in subscriptions (fix #3239) (#4551)
* Add support for multiple top-level fields in a subscription to improve testability of subscriptions
* Add an internal flag to enable multiple subscriptions
* Add missing call to withConstructorFn in live queries (fix #3239)
Co-authored-by: Alexis King <lexi.lambda@gmail.com>
* Scheduled triggers (close #1914) (#3553)
server: add scheduled triggers
Co-authored-by: Alexis King <lexi.lambda@gmail.com>
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Co-authored-by: Aleksandra Sikora <ola.zxcvbnm@gmail.com>
* dev.sh: bump version due to addition of croniter python dependency
* server: fix an introspection query caching issue (fix #4547) (#4661)
Introspection queries accept variables, but we need to make sure to
also touch the variables that we ignore, so that an introspection
query is marked not reusable if we are not able to build a correct
query plan for it.
A better solution here would be to deal with such unused variables
correctly, so that more introspection queries become reusable.
An even better solution would be to type-safely track *how* to reuse
which variables, rather than to split the reusage marking from the
planning.
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* flush log buffer on exception in mkWaiApp ( fix #4772 ) (#4801)
* flush log buffer on exception in mkWaiApp
* add comment to explain the introduced change
* add changelog
* allow logging details of a live query polling thread (#4959)
* changes for poller-log
add various multiplexed query info in poller-log
* minor cleanup, also fixes a bug which will return duplicate data
* Live query poller stats can now be logged
This also removes in-memory stats that are collected about batched
query execution as the log lines when piped into an monitoring tool
will give us better insights.
* allow poller-log to be configurable
* log minimal information in the livequery-poller-log
Other information can be retrieved from /dev/subscriptions/extended
* fix few review comments
* avoid marshalling and unmarshalling from ByteString to EncJSON
* separate out SubscriberId and SubscriberMetadata
Co-authored-by: Anon Ray <rayanon004@gmail.com>
* Don't compile in developer APIs by default
* Tighten up handling of admin secret, more docs
Store the admin secret only as a hash to prevent leaking the secret
inadvertently, and to prevent timing attacks on the secret.
NOTE: best practice for stored user passwords is a function with a
tunable cost like bcrypt, but our threat model is quite different (even
if we thought we could reasonably protect the secret from an attacker
who could read arbitrary regions of memory), and bcrypt is far too slow
(by design) to perform on each request. We'd have to rely on our
(technically savvy) users to choose high entropy passwords in any case.
Referencing #4736
* server/docs: add instructions to fix loss of float precision in PostgreSQL <= 11 (#5187)
This adds a server flag, --pg-connection-options, that can be used to set a PostgreSQL connection parameter, extra_float_digits, that needs to be used to avoid loss of data on older versions of PostgreSQL, which have odd default behavior when returning float values. (fixes #5092)
* [skip ci] Add new commits from master to the commit diff
* [skip ci] serve default directives (skip & include) over introspection
* [skip ci] Update non-Haskell assets with the version on master
* server: refactor GQL execution check and config API (#5094)
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] fix js issues in tests by pinning dependencies version
* [skip ci] bump graphql version
* [skip ci] Add note about memory usage
* generalize query execution logic on Postgres (#5110)
* generalize PGExecCtx to support specialized functions for various operations
* fix tests compilation
* allow customising PGExecCtx when starting the web server
* server: changes catalog initialization and logging for pro customization (#5139)
* new typeclass to abstract the logic of QueryLog-ing
* abstract the logic of logging websocket-server logs
introduce a MonadWSLog typeclass
* move catalog initialization to init step
expose a helper function to migrate catalog
create schema cache in initialiseCtx
* expose various modules and functions for pro
* [skip ci] cosmetic change
* [skip ci] fix test calling a mutation that does not exist
* [skip ci] minor text change
* [skip ci] refactored input values
* [skip ci] remove VString Origin
* server: fix updating of headers behaviour in the update cron trigger API and create future events immediately (#5151)
* server: fix bug to update headers in an existing cron trigger and create future events
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* Lower stack chunk size in RTS to reduce thread STACK memory (closes #5190)
This reduces memory consumption for new idle subscriptions significantly
(see linked ticket).
The hypothesis is: we fork a lot of threads per websocket, and some of
these use slightly more than the initial 1K stack size, so the first
overflow balloons to 32K, when significantly less is required.
However: running with `+RTS -K1K -xc` did not seem to show evidence of
any overflows! So it's a mystery why this improves things.
GHC should probably also be doubling the stack buffer at each overflow
or doing something even smarter; the knobs we have aren't so helpful.
* [skip ci] fix todo and schema generation for aggregate fields
* 5087 libpq pool leak (#5089)
Shrink libpq buffers to 1MB before returning connection to pool. Closes #5087
See: https://github.com/hasura/pg-client-hs/pull/19
Also related: #3388 #4077
* bump pg-client-hs version (fixes a build issue on some environments) (#5267)
* do not use prepared statements for mutations
* server: unlock scheduled events on graceful shutdown (#4928)
* Fix buggy parsing of new --conn-lifetime flag in 2b0e3774
* [skip ci] remove cherry-picked commit from commit_diff.txt
* server: include additional fields in scheduled trigger webhook payload (#5262)
* include scheduled triggers metadata in the webhook body
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* server: call the webhook asynchronously in event triggers (#5352)
* server: call the webhook asynchronosly in event triggers
* Expose all modules in Cabal file (#5371)
* [skip ci] update commit_diff.txt
* [skip ci] fix cast exp parser & few TODOs
* [skip ci] fix remote fields arguments
* [skip ci] fix few more TODO, no-op refactor, move resolve/action.hs to execute/action.hs
* Pass environment variables around as a data structure, via @sordina (#5374)
* Pass environment variables around as a data structure, via @sordina
* Resolving build error
* Adding Environment passing note to changelog
* Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge
* removing commented-out imports
* Language pragmas already set by project
* Linking async thread
* Apply suggestions from code review
Use `runQueryTx` instead of `runLazyTx` for queries.
* remove the non-user facing entry in the changelog
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] fix: restrict remote relationship field generation for hasura queries
* [skip ci] no-op refactor; move insert execution code from schema parser module
* server: call the webhook asynchronously in event triggers (#5352)
* server: call the webhook asynchronosly in event triggers
* Expose all modules in Cabal file (#5371)
* [skip ci] update commit_diff.txt
* Pass environment variables around as a data structure, via @sordina (#5374)
* Pass environment variables around as a data structure, via @sordina
* Resolving build error
* Adding Environment passing note to changelog
* Removing references to ILTPollerLog as this seems to have been reintroduced from a bad merge
* removing commented-out imports
* Language pragmas already set by project
* Linking async thread
* Apply suggestions from code review
Use `runQueryTx` instead of `runLazyTx` for queries.
* remove the non-user facing entry in the changelog
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] implement header checking
Probably closes #14 and #3659.
* server: refactor 'pollQuery' to have a hook to process 'PollDetails' (#5391)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* update pg-client (#5421)
* [skip ci] update commit_diff
* Fix latency buckets for telemetry data
These must have gotten messed up during a refactor. As a consequence
almost all samples received so far fall into the single erroneous 0 to
1K seconds (originally supposed to be 1ms?) bucket.
I also re-thought what the numbers should be, but these are still
arbitrary and might want adjusting in the future.
* [skip ci] include the latest commit compared against master in commit_diff
* [skip ci] include new commits from master in commit_diff
* [skip ci] improve description generation
* [skip ci] sort all introspect arrays
* [skip ci] allow parsers to specify error codes
* [skip ci] fix integer and float parsing error code
* [skip ci] scalar from json errors are now parse errors
* [skip ci] fixed negative integer error message and code
* [skip ci] Re-fix nullability in relationships
* [skip ci] no-op refactor and removed couple of FIXMEs
* [skip ci] uncomment code in 'deleteMetadataObject'
* [skip ci] Fix re-fix of nullability for relationships
* [skip ci] fix default arguments error code
* [skip ci] updated test error message
!!! WARNING !!!
Since all fields accept `null`, they all are technically optional in
the new schema. Meaning there's no such thing as a missing mandatory
field anymore: a field that doesn't have a default value, and which
therefore isn't labelled as "optional" in the schema, will be assumed
to be null if it's missing, meaning it isn't possible anymore to have
an error for a missing mandatory field. The only possible error is now
when a optional positional argument is omitted but is not the last
positional argument.
* [skip ci] cleanup of int scalar parser
* [skip ci] retro-compatibility of offset as string
* [skip ci] Remove commit from commit_diff.txt
Although strictly speaking we don't know if this will work correctly in PDV
if we would implement query plan caching, the fact is that in the theoretical
case that we would have the same issue in PDV, it would probably apply not just
to introspection, and the fix would be written completely differently. So this
old commit is of no value to us other than the heads-up "make sure query plan
caching works correctly even in the presence of unused variables", which is
already part of the test suite.
* Add MonadTrace and MonadExecuteQuery abstractions (#5383)
* [skip ci] Fix accumulation of input object types
Just like object types, interface types, and union types, we have to avoid
circularities when collecting input types from the GraphQL AST.
Additionally, this fixes equality checks for input object types (whose fields
are unordered, and hence should be compared as sets) and enum types (ditto).
* [skip ci] fix fragment error path
* [skip ci] fix node error code
* [skip ci] fix paths in insert queries
* [skip ci] fix path in objects
* [skip ci] manually alter node id path for consistency
* [skip ci] more node error fixups
* [skip ci] one last relay error message fix
* [skip ci] update commit_diff
* Propagate the trace context to event triggers (#5409)
* Propagate the trace context to event triggers
* Handle missing trace and span IDs
* Store trace context as one LOCAL
* Add migrations
* Documentation
* changelog
* Fix warnings
* Respond to code review suggestions
* Respond to code review
* Undo changelog
* Update CHANGELOG.md
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* server: log request/response sizes for event triggers (#5463)
* server: log request/response sizes for event triggers
event triggers (and scheduled triggers) now have request/response size
in their logs.
* add changelog entry
* Tracing: Simplify HTTP traced request (#5451)
Remove the Inversion of Control (SuspendRequest) and simplify
the tracing of HTTP Requests.
Co-authored-by: Phil Freeman <phil@hasura.io>
* Attach request ID as tracing metadata (#5456)
* Propagate the trace context to event triggers
* Handle missing trace and span IDs
* Store trace context as one LOCAL
* Add migrations
* Documentation
* Include the request ID as trace metadata
* changelog
* Fix warnings
* Respond to code review suggestions
* Respond to code review
* Undo changelog
* Update CHANGELOG.md
* Typo
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* server: add logging for action handlers (#5471)
* server: add logging for action handlers
* add changelog entry
* change action-handler log type from internal to non-internal
* fix action-handler-log name
* server: pass http and websocket request to logging context (#5470)
* pass request body to logging context in all cases
* add message size logging on the websocket API
this is required by graphql-engine-pro/#416
* message size logging on websocket API
As we need to log all messages recieved/sent by the websocket server,
it makes sense to log them as part of the websocket server event logs.
Previously message recieved were logged inside the onMessage handler,
and messages sent were logged only for "data" messages (as a server event log)
* fix review comments
Co-authored-by: Phil Freeman <phil@hasura.io>
* server: stop eventing subsystem threads when shutting down (#5479)
* server: stop eventing subsystem threads when shutting down
* Apply suggestions from code review
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
* [skip ci] update commit_diff with new commits added in master
* Bugfix to support 0-size HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE
Also some minor refactoring of bounded cache module:
- the maxBound check in `trim` was confusing and unnecessary
- consequently trim was unnecessary for lookupPure
Also add some basic tests
* Support only the bounded cache, with default HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE of 4000. Closes #5363
* [skip ci] remove merge commit from commit_diff
* server: Fix compiler warning caused by GHC upgrade (#5489)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* [skip ci] update all non server code from master
* [skip ci] aligned object field error message with master
* [skip ci] fix remaining undefined?
* [skip ci] remove unused import
* [skip ci] revert to previous error message, fix tests
* Move nullableType/nonNullableType to Schema.hs
These are functions on Types, not on Parsers.
* [skip ci] fix setup to fix backend only test
the order in which permission checks are performed on the branch is
slightly different than on master, resulting in a slightly different
error if there are no other mutations the user has access to. By
adding update permissions, we go back to the expected case.
* [skip ci] fix insert geojson tests to reflect new paths
* [skip ci] fix enum test for better error message
* [skip ci] fix header test for better error message
* [skip ci] fix fragment cycle test for better error message
* [skip ci] fix error message for type mismatch
* [skip ci] fix variable path in test
* [skip ci] adjust tests after bug fix
* [skip ci] more tests fixing
* Add hdb_catalog.current_setting abstraction for reading Hasura settings
As the comment in the function’s definition explains, this is needed to
work around an awkward Postgres behavior.
* [skip ci] Update CONTRIBUTING.md to mention Node setup for Python tests
* [skip ci] Add missing Python tests env var to CONTRIBUTING.md
* [skip ci] fix order of result when subscription is run with multiple nodes
* [skip ci] no-op refactor: fix a warning in Internal/Parser.hs
* [skip ci] throw error when a subscription contains remote joins
* [skip ci] Enable easier profiling by hiding AssertNF behind a flag
In order to compile a profiling build, run:
$ cabal new-build -f profiling --enable-profiling
* [skip ci] Fix two warnings
We used to lookup the objects that implement a given interface by filtering all
objects in the schema document. However, one of the tests expects us to
generate a warning if the provided `implements` field of an introspection query
specifies an object not implementing some interface. So we use that field
instead.
* [skip ci] Fix warnings by commenting out query plan caching
* [skip ci] improve masking/commenting query caching related code & few warning fixes
* [skip ci] Fixed compiler warnings in graphql-parser-hs
* Sync non-Haskell assets with master
* [skip ci] add a test inserting invalid GraphQL but valid JSON value in a jsonb column
* [skip ci] Avoid converting to/from Map
* [skip ci] Apply some hlint suggestions
* [skip ci] remove redundant constraints from buildLiveQueryPlan and explainGQLQuery
* [skip ci] add NOTEs about missing Tracing constraints in PDV from master
* Remove -fdefer-typed-holes, fix warnings
* Update cabal.project.freeze
* Limit GHC’s heap size to 8GB in CI to avoid the OOM killer
* Commit package-lock.json for Python tests’ remote schema server
* restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers
* update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* add test for table_by_pk node when roles doesn't have permission to PK
* [skip ci] fix introspection query if any enum column present in primary key (fix #5200) (#5522)
* [skip ci] test case fix for a6450e126bc2d98bcfd3791501986e4627ce6c6f
* [skip ci] add tests to agg queries when role doesn't have access to any cols
* fix backend test
* Simplify subscription execution
* [skip ci] add test to check if required headers are present while querying
* Suppose, table B is related to table A and to query B certain headers are
necessary, then the test checks that we are throwing error when the header
is not set when B is queried through A
* fix mutations not checking for view mutability
* [skip ci] add variable type checking and corresponding tests
* [skip ci] add test to check if update headers are present while doing an upsert
* [skip ci] add positive counterparts to some of the negative permission tests
* fix args missing their description in introspect
* [skip ci] Remove unused function; insert missing markNotReusable call
* [skip ci] Add a Note about InputValue
* [skip ci] Delete LegacySchema/ 🎉
* [skip ci] Delete GraphQL/{Resolve,Validate}/ 🎉
* [skip ci] Delete top-level Resolve/Validate modules; tidy .cabal file
* [skip ci] Delete LegacySchema top-level module
Somehow I missed this one.
* fix input value to json
* [skip ci] elaborate on JSON objects in GraphQL
* [skip ci] add missing file
* [skip ci] add a test with subscription containing remote joins
* add a test with remote joins in mutation output
* [skip ci] Add some comments to Schema/Mutation.hs
* [skip ci] Remove no longer needed code from RemoteServer.hs
* [skip ci] Use a helper function to generate conflict clause parsers
* [skip ci] fix type checker error in fields with default value
* capitalize the header keys in select_articles_without_required_headers
* Somehow, this was the reason the tests were failing. I have no idea, why!
* [skip ci] Add a long Note about optional fields and nullability
* Improve comments a bit; simplify Schema/Common.hs a bit
* [skip ci] full implementation of 5.8.5 type checking.
* [skip ci] fix validation test teardown
* [skip ci] fix schema stitching test
* fix remote schema ignoring enum nullability
* [skip ci] fix fieldOptional to not discard nullability
* revert nullability of use_spheroid
* fix comment
* add required remote fields with arguments for tests
* [skip ci] add missing docstrings
* [skip ci] fixed description of remote fields
* [skip ci] change docstring for consistency
* fix several schema inconsistencies
* revert behaviour change in function arguments parsing
* fix remaining nullability issues in new schema
* minor no-op refactor; use isListType from graphql-parser-hs
* use nullability of remote schema node, while creating a Remote reln
* fix 'ID' input coercing & action 'ID' type relationship mapping
* include ASTs in MonadExecuteQuery
* needed for PRO code-base
* Delete code for "interfaces implementing ifaces" (draft GraphQL spec)
Previously I started writing some code that adds support for a future GraphQL
feature where interfaces may themselves be sub-types of other interfaces.
However, this code was incomplete, and partially incorrect. So this commit
deletes support for that entirely.
* Ignore a remote schema test during the upgrade/downgrade test
The PDV refactor does a better job at exposing a minimal set of types through
introspection. In particular, not every type that is present in a remote schema
is re-exposed by Hasura. The test
test_schema_stitching.py::TestRemoteSchemaBasic::test_introspection assumed that
all types were re-exposed, which is not required for GraphQL compatibility, in
order to test some aspect of our support for remote schemas.
So while this particular test has been updated on PDV, the PDV branch now does
not pass the old test, which we argue to be incorrect. Hence this test is
disabled while we await a release, after which we can re-enable it.
This also re-enables a test that was previously disabled for similar, though
unrelated, reasons.
* add haddock documentation to the action's field parsers
* Deslecting some tests in server-upgrade
Some tests with current build are failing on server upgrade
which it should not. The response is more accurate than
what it was.
Also the upgrade tests were not throwing errors when the test is
expected to return an error, but succeeds. The test framework is
patched to catch this case.
* [skip ci] Add a long Note about interfaces and object types
* send the response headers back to client after running a query
* Deselect a few more tests during upgrade/downgrade test
* Update commit_diff.txt
* change log kind from db_migrate to catalog_migrate (#5531)
* Show method and complete URI in traced HTTP calls (#5525)
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers
* update CHANGELOG.md
* Apply suggestions from code review
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
* fix introspection query if any enum column present in primary key (fix #5200) (#5522)
* Fix telemetry reporting of transport (websocket was reported as http)
* add log kinds in cli-migrations image (#5529)
* add log kinds in cli-migrations image
* give hint to resolve timeout error
* minor changes and CHANGELOG
* server: set hasura.tracecontext in RQL mutations [#5542] (#5555)
* server: set hasura.tracecontext in RQL mutations [#5542]
* Update test suite
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
* Add bulldozer auto-merge and -update configuration
We still need to add the github app (as of time of opening this PR)
Afterwards devs should be able to allow bulldozer to automatically
"update" the branch, merging in parent when it changes, as well as
automatically merge when all checks pass.
This is opt-in by adding the `auto-update-auto-merge` label to the PR.
* Remove 'bulldozer' config, try 'kodiak' for auto-merge
see: https://github.com/chdsbd/kodiak
The main issue that bit us was not being able to auto update forked
branches, also:
https://github.com/palantir/bulldozer/issues/66
https://github.com/palantir/bulldozer/issues/145
* Cherry-picked all commits
* [skip ci] Slightly improve formatting
* Revert "fix introspection query if any enum column present in primary key (fix #5200) (#5522)"
This reverts commit 0f9a5afa59a88f6824f4d63d58db246a5ba3fb03.
This undoes a cherry-pick of 34288e1eb5f2c5dad9e6d1e05453dd52397dc970 that was
already done previously in a6450e126bc2d98bcfd3791501986e4627ce6c6f, and
subsequently fixed for PDV in 70e89dc250f8ddc6e2b7930bbe2b3eeaa6dbe1db
* Do a small bit of tidying in Hasura.GraphQL.Parser.Collect
* Fix cherry-picking work
Some previous cherry-picks ended up modifying code that is commented out
* [skip ci] clarified comment regarding insert representation
* [skip ci] removed obsolete todos
* cosmetic change
* fix action error message
* [skip ci] remove obsolete comment
* [skip ci] synchronize stylish haskell extensions list
* use previously defined scalar names in parsers rather than ad-hoc literals
* Apply most syntax hlint hints.
* Clarify comment on update mutation.
* [skip ci] Clarify what fields should be specified for objects
* Update "_inc" description.
* Use record types rather than tuples fo IntrospectionResult and ParsedIntrospection
* Get rid of checkFieldNamesUnique (use Data.List.Extended.duplicates)
* Throw more errors when collecting query root names
* [skip ci] clean column parser comment
* Remove dead code inserted in ab65b39
* avoid converting to non-empty list where not needed
* add note and TODO about the disabled checks in PDV
* minor refactor in remoteField' function
* Unify two getObject methods
* Nitpicks in Remote.hs
* Update CHANGELOG.md
* Revert "Unify two getObject methods"
This reverts commit bd6bb40355b3d189a46c0312eb52225e18be57b3.
We do need two different getObject functions as the corresponding error message is different
* Fix error message in Remote.hs
* Update CHANGELOG.md
Co-authored-by: Auke Booij <auke@tulcod.com>
* Apply suggested Changelog fix.
Co-authored-by: Auke Booij <auke@tulcod.com>
* Fix typo in Changelog.
* [skip ci] Update changelog.
* reuse type names to avoid duplication
* Fix Hashable instance for Definition
The presence of `Maybe Unique`, and an optional description, as part of
`Definition`s, means that `Definition`s that are considered `Eq`ual may get
different hashes. This can happen, for instance, when one object is memoized
but another is not.
* [skip ci] Update commit_diff.txt
* Bump parser version.
* Bump freeze file after changes in parser.
* [skip ci] Incorporate commits from master
* Fix developer flag in server/cabal.project.freeze
Co-authored-by: Auke Booij <auke@tulcod.com>
* Deselect a changed ENUM test for upgrade/downgrade CI
* Deselect test here as well
* [skip ci] remove dead code
* Disable more tests for upgrade/downgrade
* Fix which test gets deselected
* Revert "Add hdb_catalog.current_setting abstraction for reading Hasura settings"
This reverts commit 66e85ab9fbd56cca2c28a80201f6604fbe811b85.
* Remove circular reference in cabal.project.freeze
Co-authored-by: Karthikeyan Chinnakonda <karthikeyan@hasura.io>
Co-authored-by: Auke Booij <auke@hasura.io>
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: Aleksandra Sikora <ola.zxcvbnm@gmail.com>
Co-authored-by: Brandon Simmons <brandon.m.simmons@gmail.com>
Co-authored-by: Vamshi Surabhi <0x777@users.noreply.github.com>
Co-authored-by: Anon Ray <rayanon004@gmail.com>
Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com>
Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com>
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io>
Co-authored-by: Antoine Leblanc <antoine@hasura.io>
Co-authored-by: Brandon Simmons <brandon@hasura.io>
Co-authored-by: Phil Freeman <phil@hasura.io>
Co-authored-by: Lyndon Maydwell <lyndon@sordina.net>
Co-authored-by: Phil Freeman <paf31@cantab.net>
Co-authored-by: Naveen Naidu <naveennaidu479@gmail.com>
Co-authored-by: Karthikeyan Chinnakonda <chkarthikeyan95@gmail.com>
Co-authored-by: Nizar Malangadan <nizar-m@users.noreply.github.com>
Co-authored-by: Antoine Leblanc <crucuny@gmail.com>
Co-authored-by: Auke Booij <auke@tulcod.com>
2020-08-21 20:27:01 +03:00
|
|
|
|
returnA -< (M.empty, emptyAnnotatedCustomTypes)
|
2020-02-13 20:38:23 +03:00
|
|
|
|
|
2020-12-08 17:22:31 +03:00
|
|
|
|
cronTriggersMap <- buildCronTriggers -< ((), OMap.elems cronTriggers)
|
2020-05-13 15:33:16 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
returnA
|
|
|
|
|
-<
|
|
|
|
|
BuildOutputs
|
|
|
|
|
{ _boSources = M.map fst sourcesOutput,
|
|
|
|
|
_boActions = actionCache,
|
|
|
|
|
_boRemoteSchemas = remoteSchemaCache,
|
2022-02-08 19:53:30 +03:00
|
|
|
|
_boAllowlist = inlinedAllowlist,
|
2021-09-24 01:56:37 +03:00
|
|
|
|
_boCustomTypes = annotatedCustomTypes,
|
|
|
|
|
_boCronTriggers = cronTriggersMap,
|
|
|
|
|
_boEndpoints = resolvedEndpoints,
|
|
|
|
|
_boApiLimits = apiLimits,
|
|
|
|
|
_boMetricsConfig = metricsConfig,
|
|
|
|
|
_boRoles = mapFromL _rRoleName $ _unOrderedRoles orderedRoles,
|
|
|
|
|
_boTlsAllowlist = (networkTlsAllowlist networkConfig)
|
|
|
|
|
}
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2021-01-29 04:02:34 +03:00
|
|
|
|
mkEndpointMetadataObject (name, createEndpoint) =
|
2021-09-24 01:56:37 +03:00
|
|
|
|
let objectId = MOEndpoint name
|
|
|
|
|
in MetadataObject objectId (toJSON createEndpoint)
|
2021-01-29 04:02:34 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
buildEndpoint ::
|
|
|
|
|
(ArrowChoice arr, ArrowKleisli m arr, MonadError QErr m, ArrowWriter (Seq CollectedInfo) arr) =>
|
|
|
|
|
(InsOrdHashMap CollectionName CreateCollection, (EndpointName, CreateEndpoint)) `arr` Maybe (EndpointMetadata GQLQueryWithText)
|
2021-01-29 04:02:34 +03:00
|
|
|
|
buildEndpoint = proc (collections, e@(name, createEndpoint)) -> do
|
|
|
|
|
let endpoint = createEndpoint
|
|
|
|
|
-- QueryReference collName queryName = _edQuery endpoint
|
|
|
|
|
addContext err = "in endpoint " <> toTxt (unEndpointName name) <> ": " <> err
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
(bindErrorA -< resolveEndpoint collections endpoint)
|
|
|
|
|
|) addContext
|
|
|
|
|
)
|
|
|
|
|
|) (mkEndpointMetadataObject e)
|
|
|
|
|
|
|
|
|
|
resolveEndpoint ::
|
|
|
|
|
QErrM m =>
|
|
|
|
|
InsOrdHashMap CollectionName CreateCollection ->
|
|
|
|
|
EndpointMetadata QueryReference ->
|
|
|
|
|
m (EndpointMetadata GQLQueryWithText)
|
2021-01-29 04:02:34 +03:00
|
|
|
|
resolveEndpoint collections = traverse $ \(QueryReference collName queryName) -> do
|
2021-02-01 15:57:34 +03:00
|
|
|
|
collection <-
|
|
|
|
|
onNothing
|
|
|
|
|
(OMap.lookup collName collections)
|
|
|
|
|
(throw400 NotExists $ "collection with name " <> toTxt collName <> " does not exist")
|
|
|
|
|
listedQuery <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
flip
|
|
|
|
|
onNothing
|
|
|
|
|
( throw400 NotExists $
|
|
|
|
|
"query with name "
|
2021-02-01 15:57:34 +03:00
|
|
|
|
<> toTxt queryName
|
2021-09-24 01:56:37 +03:00
|
|
|
|
<> " does not exist in collection "
|
|
|
|
|
<> toTxt collName
|
|
|
|
|
)
|
|
|
|
|
$ find ((== queryName) . _lqName) (_cdQueries (_ccDefinition collection))
|
2021-02-24 07:30:12 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
let lq@(GQLQueryWithText lqq) = _lqQuery listedQuery
|
|
|
|
|
ds = G.getExecutableDefinitions $ unGQLQuery $ snd lqq
|
2021-02-24 13:12:12 +03:00
|
|
|
|
|
|
|
|
|
case ds of
|
|
|
|
|
[G.ExecutableDefinitionOperation (G.OperationDefinitionTyped d)]
|
|
|
|
|
| G._todType d == G.OperationTypeSubscription ->
|
2021-09-24 01:56:37 +03:00
|
|
|
|
throw405 $ "query with name " <> toTxt queryName <> " is a subscription"
|
2021-02-24 13:12:12 +03:00
|
|
|
|
| otherwise -> pure ()
|
|
|
|
|
[] -> throw400 BadRequest $ "query with name " <> toTxt queryName <> " has no definitions."
|
2021-09-24 01:56:37 +03:00
|
|
|
|
_ -> throw400 BadRequest $ "query with name " <> toTxt queryName <> " has multiple definitions."
|
2021-02-24 07:30:12 +03:00
|
|
|
|
|
|
|
|
|
pure lq
|
2021-01-29 04:02:34 +03:00
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
mkEventTriggerMetadataObject ::
|
|
|
|
|
forall b a c.
|
|
|
|
|
Backend b =>
|
|
|
|
|
(a, SourceName, c, TableName b, RecreateEventTriggers, EventTriggerConf b) ->
|
|
|
|
|
MetadataObject
|
2021-06-07 16:57:24 +03:00
|
|
|
|
mkEventTriggerMetadataObject (_, source, _, table, _, eventTriggerConf) =
|
2021-09-24 01:56:37 +03:00
|
|
|
|
let objectId =
|
|
|
|
|
MOSourceObjId source $
|
|
|
|
|
AB.mkAnyBackend $
|
|
|
|
|
SMOTableObj @b table $
|
|
|
|
|
MTOTrigger $
|
|
|
|
|
etcName eventTriggerConf
|
2020-12-08 17:22:31 +03:00
|
|
|
|
definition = object ["table" .= table, "configuration" .= eventTriggerConf]
|
2021-09-24 01:56:37 +03:00
|
|
|
|
in MetadataObject objectId definition
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
2020-05-13 15:33:16 +03:00
|
|
|
|
mkCronTriggerMetadataObject catalogCronTrigger =
|
|
|
|
|
let definition = toJSON catalogCronTrigger
|
2021-09-24 01:56:37 +03:00
|
|
|
|
in MetadataObject
|
|
|
|
|
(MOCronTrigger (ctName catalogCronTrigger))
|
|
|
|
|
definition
|
2020-05-13 15:33:16 +03:00
|
|
|
|
|
2021-10-29 07:12:27 +03:00
|
|
|
|
mkActionMetadataObject (ActionMetadata name comment defn _) =
|
|
|
|
|
MetadataObject (MOAction name) (toJSON $ CreateAction name defn comment)
|
2020-04-15 15:03:13 +03:00
|
|
|
|
|
2020-01-29 23:15:53 +03:00
|
|
|
|
mkRemoteSchemaMetadataObject remoteSchema =
|
2020-12-21 12:11:37 +03:00
|
|
|
|
MetadataObject (MORemoteSchema (_rsmName remoteSchema)) (toJSON remoteSchema)
|
|
|
|
|
|
2021-07-17 00:18:58 +03:00
|
|
|
|
mkInheritedRoleMetadataObject inheritedRole@(Role roleName _) =
|
|
|
|
|
MetadataObject (MOInheritedRole roleName) (toJSON inheritedRole)
|
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
alignExtraRemoteSchemaInfo ::
|
|
|
|
|
forall a b arr.
|
|
|
|
|
(ArrowChoice arr, Inc.ArrowDistribute arr, ArrowWriter (Seq CollectedInfo) arr) =>
|
|
|
|
|
(b -> MetadataObject) ->
|
|
|
|
|
( M.HashMap RemoteSchemaName a,
|
|
|
|
|
M.HashMap RemoteSchemaName [b]
|
|
|
|
|
)
|
|
|
|
|
`arr` M.HashMap RemoteSchemaName (a, [b])
|
2020-12-21 12:11:37 +03:00
|
|
|
|
alignExtraRemoteSchemaInfo mkMetadataObject = proc (baseInfo, extraInfo) -> do
|
|
|
|
|
combinedInfo <-
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
Inc.keyed
|
|
|
|
|
(\remoteSchemaName infos -> combine -< (remoteSchemaName, infos))
|
|
|
|
|
|) (align baseInfo extraInfo)
|
2020-12-21 12:11:37 +03:00
|
|
|
|
returnA -< M.catMaybes combinedInfo
|
|
|
|
|
where
|
|
|
|
|
combine :: (RemoteSchemaName, These a [b]) `arr` Maybe (a, [b])
|
|
|
|
|
combine = proc (remoteSchemaName, infos) -> case infos of
|
2021-09-24 01:56:37 +03:00
|
|
|
|
This base -> returnA -< Just (base, [])
|
2020-12-21 12:11:37 +03:00
|
|
|
|
These base extras -> returnA -< Just (base, extras)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
That extras -> do
|
2020-12-21 12:11:37 +03:00
|
|
|
|
let errorMessage = "remote schema " <> unRemoteSchemaName remoteSchemaName <<> " does not exist"
|
|
|
|
|
recordInconsistencies -< (map mkMetadataObject extras, errorMessage)
|
|
|
|
|
returnA -< Nothing
|
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
|
buildRemoteSchemaPermissions ::
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadError QErr m
|
|
|
|
|
) =>
|
|
|
|
|
(RemoteSchemaCtx, [AddRemoteSchemaPermission]) `arr` M.HashMap RoleName IntrospectionResult
|
2020-12-21 12:11:37 +03:00
|
|
|
|
buildRemoteSchemaPermissions = buildInfoMap _arspRole mkRemoteSchemaPermissionMetadataObject buildRemoteSchemaPermission
|
|
|
|
|
where
|
|
|
|
|
buildRemoteSchemaPermission = proc (remoteSchemaCtx, remoteSchemaPerm) -> do
|
2021-08-09 13:20:04 +03:00
|
|
|
|
let AddRemoteSchemaPermission rsName roleName defn _ = remoteSchemaPerm
|
2020-12-21 12:11:37 +03:00
|
|
|
|
metadataObject = mkRemoteSchemaPermissionMetadataObject remoteSchemaPerm
|
|
|
|
|
schemaObject = SORemoteSchemaPermission rsName roleName
|
|
|
|
|
providedSchemaDoc = _rspdSchema defn
|
|
|
|
|
addPermContext err = "in remote schema permission for role " <> roleName <<> ": " <> err
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
( do
|
|
|
|
|
bindErrorA
|
|
|
|
|
-<
|
|
|
|
|
when (roleName == adminRoleName) $
|
|
|
|
|
throw400 ConstraintViolation $ "cannot define permission for admin role"
|
|
|
|
|
(resolvedSchemaIntrospection, dependencies) <-
|
|
|
|
|
bindErrorA -< resolveRoleBasedRemoteSchema providedSchemaDoc remoteSchemaCtx
|
|
|
|
|
recordDependencies -< (metadataObject, schemaObject, dependencies)
|
|
|
|
|
returnA -< resolvedSchemaIntrospection
|
|
|
|
|
)
|
|
|
|
|
|) addPermContext
|
|
|
|
|
)
|
|
|
|
|
|) metadataObject
|
|
|
|
|
|
|
|
|
|
buildTableEventTriggers ::
|
|
|
|
|
forall arr m b.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
MonadError QErr m,
|
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
|
MonadReader BuildReason m,
|
|
|
|
|
HasServerConfigCtx m,
|
|
|
|
|
BackendMetadata b,
|
|
|
|
|
BackendEventTrigger b
|
|
|
|
|
) =>
|
|
|
|
|
( SourceName,
|
|
|
|
|
SourceConfig b,
|
|
|
|
|
TableCoreInfo b,
|
|
|
|
|
[EventTriggerConf b],
|
|
|
|
|
Inc.Dependency Inc.InvalidationKey,
|
|
|
|
|
RecreateEventTriggers
|
|
|
|
|
)
|
|
|
|
|
`arr` (EventTriggerInfoMap b)
|
2021-11-10 17:34:22 +03:00
|
|
|
|
buildTableEventTriggers = proc (sourceName, sourceConfig, tableInfo, eventTriggerConfs, metadataInvalidationKey, recreateEventTriggers) ->
|
2021-06-07 16:57:24 +03:00
|
|
|
|
buildInfoMap (etcName . (^. _6)) (mkEventTriggerMetadataObject @b) buildEventTrigger
|
2021-09-24 01:56:37 +03:00
|
|
|
|
-<
|
2021-11-10 17:34:22 +03:00
|
|
|
|
(tableInfo, map (metadataInvalidationKey,sourceName,sourceConfig,_tciName tableInfo,recreateEventTriggers,) eventTriggerConfs)
|
2019-11-27 01:49:42 +03:00
|
|
|
|
where
|
2021-06-07 16:57:24 +03:00
|
|
|
|
buildEventTrigger = proc (tableInfo, (metadataInvalidationKey, source, sourceConfig, table, recreateEventTriggers, eventTriggerConf)) -> do
|
2020-12-08 17:22:31 +03:00
|
|
|
|
let triggerName = etcName eventTriggerConf
|
2021-06-07 16:57:24 +03:00
|
|
|
|
metadataObject = mkEventTriggerMetadataObject @b (metadataInvalidationKey, source, sourceConfig, table, recreateEventTriggers, eventTriggerConf)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
schemaObjectId =
|
|
|
|
|
SOSourceObj source $
|
|
|
|
|
AB.mkAnyBackend $
|
|
|
|
|
SOITableObj @b table $
|
|
|
|
|
TOTrigger triggerName
|
2020-12-08 17:22:31 +03:00
|
|
|
|
addTriggerContext e = "in event trigger " <> triggerName <<> ": " <> e
|
2021-11-10 17:34:22 +03:00
|
|
|
|
buildReason <- bindA -< ask
|
|
|
|
|
let reloadMetadataRecreateEventTrigger =
|
|
|
|
|
case buildReason of
|
|
|
|
|
CatalogSync -> RETDoNothing
|
|
|
|
|
CatalogUpdate Nothing -> RETDoNothing
|
|
|
|
|
CatalogUpdate (Just sources) -> if source `elem` sources then RETRecreate else RETDoNothing
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
( do
|
|
|
|
|
(info, dependencies) <- bindErrorA -< buildEventTriggerInfo @b env source table eventTriggerConf
|
|
|
|
|
let tableColumns = M.mapMaybe (^? _FIColumn) (_tciFieldInfoMap tableInfo)
|
2021-11-10 17:34:22 +03:00
|
|
|
|
recreateTriggerIfNeeded -< (table, M.elems tableColumns, triggerName, etcDefinition eventTriggerConf, sourceConfig, recreateEventTriggers <> reloadMetadataRecreateEventTrigger)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
recordDependencies -< (metadataObject, schemaObjectId, dependencies)
|
|
|
|
|
returnA -< info
|
|
|
|
|
)
|
|
|
|
|
|) (addTableContext @b table . addTriggerContext)
|
|
|
|
|
)
|
|
|
|
|
|) metadataObject
|
|
|
|
|
|
|
|
|
|
recreateTriggerIfNeeded =
|
2021-11-03 04:19:40 +03:00
|
|
|
|
-- using `Inc.cache` here means that the response will be cached for the given output and the
|
|
|
|
|
-- next time this arrow recieves the same input, the cached response will be returned and the
|
|
|
|
|
-- computation will not be done again.
|
2021-09-24 01:56:37 +03:00
|
|
|
|
Inc.cache
|
|
|
|
|
proc
|
2021-11-03 04:19:40 +03:00
|
|
|
|
( tableName,
|
2021-09-24 01:56:37 +03:00
|
|
|
|
tableColumns,
|
|
|
|
|
triggerName,
|
|
|
|
|
triggerDefinition,
|
|
|
|
|
sourceConfig,
|
|
|
|
|
recreateEventTriggers
|
|
|
|
|
)
|
|
|
|
|
-> do
|
|
|
|
|
bindA
|
|
|
|
|
-< do
|
|
|
|
|
buildReason <- ask
|
|
|
|
|
serverConfigCtx <- askServerConfigCtx
|
2021-11-10 17:34:22 +03:00
|
|
|
|
let isCatalogUpdate =
|
|
|
|
|
case buildReason of
|
|
|
|
|
CatalogUpdate _ -> True
|
|
|
|
|
CatalogSync -> False
|
2021-12-08 09:26:46 +03:00
|
|
|
|
-- we don't modify the existing event trigger definitions in the maintenance mode or in read-only mode
|
2021-09-24 01:56:37 +03:00
|
|
|
|
when
|
2021-11-10 17:34:22 +03:00
|
|
|
|
( (isCatalogUpdate || recreateEventTriggers == RETRecreate)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
&& _sccMaintenanceMode serverConfigCtx == MaintenanceModeDisabled
|
2021-12-08 09:26:46 +03:00
|
|
|
|
&& _sccReadOnlyMode serverConfigCtx == ReadOnlyModeDisabled
|
2021-09-24 01:56:37 +03:00
|
|
|
|
)
|
|
|
|
|
$ liftEitherM $
|
|
|
|
|
createTableEventTrigger
|
|
|
|
|
serverConfigCtx
|
|
|
|
|
sourceConfig
|
|
|
|
|
tableName
|
|
|
|
|
tableColumns
|
|
|
|
|
triggerName
|
|
|
|
|
triggerDefinition
|
|
|
|
|
|
|
|
|
|
buildCronTriggers ::
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadError QErr m
|
|
|
|
|
) =>
|
|
|
|
|
((), [CronTriggerMetadata])
|
|
|
|
|
`arr` HashMap TriggerName CronTriggerInfo
|
2020-12-08 17:22:31 +03:00
|
|
|
|
buildCronTriggers = buildInfoMap ctName mkCronTriggerMetadataObject buildCronTrigger
|
2020-05-13 15:33:16 +03:00
|
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
|
buildCronTrigger = proc (_, cronTrigger) -> do
|
2020-12-08 17:22:31 +03:00
|
|
|
|
let triggerName = triggerNameToTxt $ ctName cronTrigger
|
2020-05-13 15:33:16 +03:00
|
|
|
|
addCronTriggerContext e = "in cron trigger " <> triggerName <> ": " <> e
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
(bindErrorA -< resolveCronTrigger env cronTrigger)
|
|
|
|
|
|) addCronTriggerContext
|
|
|
|
|
)
|
|
|
|
|
|) (mkCronTriggerMetadataObject cronTrigger)
|
|
|
|
|
|
|
|
|
|
buildInheritedRoles ::
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadError QErr m
|
|
|
|
|
) =>
|
|
|
|
|
(HashSet RoleName, [InheritedRole])
|
|
|
|
|
`arr` HashMap RoleName Role
|
2021-07-17 00:18:58 +03:00
|
|
|
|
buildInheritedRoles = buildInfoMap _rRoleName mkInheritedRoleMetadataObject buildInheritedRole
|
|
|
|
|
where
|
|
|
|
|
buildInheritedRole = proc (allRoles, inheritedRole) -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
|
let addInheritedRoleContext e = "in inherited role " <> roleNameToTxt (_rRoleName inheritedRole) <> ": " <> e
|
2021-07-17 00:18:58 +03:00
|
|
|
|
metadataObject = mkInheritedRoleMetadataObject inheritedRole
|
|
|
|
|
schemaObject = SORole $ _rRoleName inheritedRole
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
( do
|
|
|
|
|
(resolvedInheritedRole, dependencies) <- bindA -< resolveInheritedRole allRoles inheritedRole
|
|
|
|
|
recordDependencies -< (metadataObject, schemaObject, dependencies)
|
|
|
|
|
returnA -< resolvedInheritedRole
|
|
|
|
|
)
|
|
|
|
|
|) addInheritedRoleContext
|
|
|
|
|
)
|
|
|
|
|
|) metadataObject
|
|
|
|
|
|
|
|
|
|
buildActions ::
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr
|
|
|
|
|
) =>
|
|
|
|
|
( (AnnotatedCustomTypes, DMap.DMap BackendTag ScalarSet, OrderedRoles),
|
|
|
|
|
[ActionMetadata]
|
|
|
|
|
)
|
|
|
|
|
`arr` HashMap ActionName ActionInfo
|
2020-04-15 15:03:13 +03:00
|
|
|
|
buildActions = buildInfoMap _amName mkActionMetadataObject buildAction
|
|
|
|
|
where
|
2021-08-09 13:20:04 +03:00
|
|
|
|
buildAction = proc ((resolvedCustomTypes, scalarsMap, orderedRoles), action) -> do
|
2021-10-29 07:12:27 +03:00
|
|
|
|
let ActionMetadata name comment def actionPermissions = action
|
2020-04-15 15:03:13 +03:00
|
|
|
|
addActionContext e = "in action " <> name <<> "; " <> e
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
( do
|
|
|
|
|
(resolvedDef, outObject) <-
|
|
|
|
|
liftEitherA <<< bindA
|
|
|
|
|
-<
|
|
|
|
|
runExceptT $ resolveAction env resolvedCustomTypes def scalarsMap
|
|
|
|
|
let permissionInfos = map (ActionPermissionInfo . _apmRole) actionPermissions
|
|
|
|
|
metadataPermissionMap = mapFromL _apiRole permissionInfos
|
|
|
|
|
permissionsMap = mkBooleanPermissionMap ActionPermissionInfo metadataPermissionMap orderedRoles
|
|
|
|
|
forwardClientHeaders = _adForwardClientHeaders resolvedDef
|
|
|
|
|
outputType = unGraphQLType $ _adOutputType def
|
2021-10-29 07:12:27 +03:00
|
|
|
|
returnA -< ActionInfo name (outputType, outObject) resolvedDef permissionsMap forwardClientHeaders comment
|
2021-09-24 01:56:37 +03:00
|
|
|
|
)
|
|
|
|
|
|) addActionContext
|
|
|
|
|
)
|
|
|
|
|
|) (mkActionMetadataObject action)
|
|
|
|
|
|
|
|
|
|
buildRemoteSchemas ::
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
Inc.ArrowDistribute arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
Inc.ArrowCache m arr,
|
|
|
|
|
MonadIO m,
|
|
|
|
|
HasHttpManagerM m
|
|
|
|
|
) =>
|
|
|
|
|
( Inc.Dependency (HashMap RemoteSchemaName Inc.InvalidationKey),
|
|
|
|
|
[RemoteSchemaMetadata]
|
|
|
|
|
)
|
2022-02-03 21:58:37 +03:00
|
|
|
|
`arr` HashMap RemoteSchemaName ((RemoteSchemaCtx, SchemaRemoteRelationships), MetadataObject)
|
2020-01-31 02:55:09 +03:00
|
|
|
|
buildRemoteSchemas =
|
2020-12-21 12:11:37 +03:00
|
|
|
|
buildInfoMapPreservingMetadata _rsmName mkRemoteSchemaMetadataObject buildRemoteSchema
|
2020-01-29 23:15:53 +03:00
|
|
|
|
where
|
|
|
|
|
-- We want to cache this call because it fetches the remote schema over HTTP, and we don’t
|
|
|
|
|
-- want to re-run that if the remote schema definition hasn’t changed.
|
2022-02-03 21:58:37 +03:00
|
|
|
|
buildRemoteSchema = Inc.cache proc (invalidationKeys, remoteSchema@(RemoteSchemaMetadata name defn comment _ relationships)) -> do
|
2021-07-30 14:33:06 +03:00
|
|
|
|
-- TODO is it strange how we convert from RemoteSchemaMetadata back
|
|
|
|
|
-- to AddRemoteSchemaQuery here? Document types please.
|
2020-12-21 12:11:37 +03:00
|
|
|
|
let addRemoteSchemaQuery = AddRemoteSchemaQuery name defn comment
|
|
|
|
|
Inc.dependOn -< Inc.selectKeyD name invalidationKeys
|
2021-09-24 01:56:37 +03:00
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( liftEitherA <<< bindA
|
|
|
|
|
-<
|
2022-02-03 21:58:37 +03:00
|
|
|
|
(fmap . fmap) (,relationships) $
|
|
|
|
|
runExceptT $ noopTrace $ addRemoteSchemaP2Setup env addRemoteSchemaQuery
|
2021-09-24 01:56:37 +03:00
|
|
|
|
)
|
|
|
|
|
|) (mkRemoteSchemaMetadataObject remoteSchema)
|
2021-07-30 14:33:06 +03:00
|
|
|
|
-- TODO continue propagating MonadTrace up calls so that we can get tracing for remote schema introspection.
|
|
|
|
|
-- This will require modifying CacheBuild.
|
|
|
|
|
noopTrace = Tracing.runTraceTWithReporter Tracing.noReporter "buildSchemaCacheRule"
|
2020-01-29 23:15:53 +03:00
|
|
|
|
|
2022-02-03 21:58:37 +03:00
|
|
|
|
buildRemoteSchemaRemoteRelationship ::
|
|
|
|
|
forall arr m.
|
|
|
|
|
( ArrowChoice arr,
|
|
|
|
|
ArrowWriter (Seq CollectedInfo) arr,
|
|
|
|
|
ArrowKleisli m arr,
|
|
|
|
|
MonadError QErr m
|
|
|
|
|
) =>
|
|
|
|
|
( (HashMap SourceName (AB.AnyBackend PartiallyResolvedSource), RemoteSchemaMap),
|
|
|
|
|
(RemoteSchemaName, RemoteSchemaIntrospection, G.Name, RemoteRelationship)
|
|
|
|
|
)
|
|
|
|
|
`arr` Maybe (RemoteFieldInfo G.Name)
|
|
|
|
|
buildRemoteSchemaRemoteRelationship =
|
|
|
|
|
proc
|
|
|
|
|
( (allSources, remoteSchemaMap),
|
|
|
|
|
(remoteSchema, remoteSchemaIntrospection, typeName, rr@RemoteRelationship {..})
|
|
|
|
|
)
|
|
|
|
|
-> do
|
|
|
|
|
let metadataObject = mkRemoteSchemaRemoteRelationshipMetadataObject (remoteSchema, typeName, rr)
|
|
|
|
|
schemaObj = SORemoteSchemaRemoteRelationship remoteSchema typeName _rrName
|
|
|
|
|
addRemoteRelationshipContext e = "in remote relationship" <> _rrName <<> ": " <> e
|
|
|
|
|
(|
|
|
|
|
|
withRecordInconsistency
|
|
|
|
|
( (|
|
|
|
|
|
modifyErrA
|
|
|
|
|
( do
|
|
|
|
|
allowedLHSJoinFields <-
|
|
|
|
|
bindErrorA
|
|
|
|
|
-<
|
|
|
|
|
getRemoteSchemaEntityJoinColumns remoteSchema remoteSchemaIntrospection typeName
|
|
|
|
|
(remoteField, rhsDependencies) <-
|
|
|
|
|
bindErrorA
|
|
|
|
|
-<
|
|
|
|
|
buildRemoteFieldInfo (remoteSchemaToLHSIdentifier remoteSchema) allowedLHSJoinFields rr allSources remoteSchemaMap
|
|
|
|
|
-- buildRemoteFieldInfo only knows how to construct dependencies on the RHS of the join condition,
|
|
|
|
|
-- so the dependencies on the remote relationship on the LHS entity have to be computed here
|
|
|
|
|
let lhsDependencies =
|
|
|
|
|
-- a direct dependency on the remote schema on which this is defined
|
|
|
|
|
[SchemaDependency (SORemoteSchema remoteSchema) DRRemoteRelationship]
|
|
|
|
|
recordDependencies -< (metadataObject, schemaObj, lhsDependencies <> rhsDependencies)
|
|
|
|
|
returnA -< remoteField
|
|
|
|
|
)
|
|
|
|
|
|) addRemoteRelationshipContext
|
|
|
|
|
)
|
|
|
|
|
|) metadataObject
|
|
|
|
|
|
|
|
|
|
mkRemoteSchemaRemoteRelationshipMetadataObject ::
|
|
|
|
|
(RemoteSchemaName, G.Name, RemoteRelationship) ->
|
|
|
|
|
MetadataObject
|
|
|
|
|
mkRemoteSchemaRemoteRelationshipMetadataObject (remoteSchemaName, typeName, RemoteRelationship {..}) =
|
|
|
|
|
let objectId =
|
|
|
|
|
MORemoteSchemaRemoteRelationship remoteSchemaName typeName _rrName
|
|
|
|
|
in MetadataObject objectId $
|
|
|
|
|
toJSON $
|
|
|
|
|
CreateRemoteSchemaRemoteRelationship remoteSchemaName typeName _rrName _rrDefinition
|
|
|
|
|
|
2020-03-26 14:52:20 +03:00
|
|
|
|
{- Note [Keep invalidation keys for inconsistent objects]
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
After building the schema cache, we prune InvalidationKeys for objects
|
|
|
|
|
that no longer exist in the schema to avoid leaking memory for objects
|
|
|
|
|
that have been dropped. However, note that we *don’t* want to drop
|
|
|
|
|
keys for objects that are simply inconsistent!
|
|
|
|
|
|
|
|
|
|
Why? The object is still in the metadata, so next time we reload it,
|
|
|
|
|
we’ll reprocess that object. We want to reuse the cache if its
|
|
|
|
|
definition hasn’t changed, but if we dropped the invalidation key, it
|
|
|
|
|
will incorrectly be reprocessed (since the invalidation key changed
|
|
|
|
|
from present to absent). -}
|