server: fix caching for queries using remote schema permissions

https://github.com/hasura/graphql-engine-mono/pull/1579

Co-authored-by: Solomon Bothwell <24038+ssbothwell@users.noreply.github.com>
GitOrigin-RevId: 8fdf33863d812f2ee4edee7eec34150a7dc03231
This commit is contained in:
Phil Freeman 2021-06-17 12:16:11 -07:00 committed by hasura-bot
parent 12045a827c
commit 456caa59e1
2 changed files with 13 additions and 3 deletions

View File

@ -5,6 +5,7 @@
- server: make improvements in the `livequery-poller-log`
- server: Backends Citus, MSSQL, and BigQuery now all support the `set_table_customization` operation.
- server: Adds caching support for queries using remote schema permissions
- cli: `metadata diff` will now only show the differences in metadata. old behaviour is avialble behind a flag (`--type unified-common`) (#5487)
## v2.0.0-beta.2

View File

@ -36,7 +36,7 @@ import qualified Language.GraphQL.Draft.Syntax as G
import qualified Network.HTTP.Types as HTTP
import qualified Network.Wai.Extended as Wai
import Control.Lens (toListOf)
import Control.Lens (Traversal', toListOf)
import Control.Monad.Morph (hoist)
import Control.Monad.Trans.Control (MonadBaseControl)
@ -166,7 +166,7 @@ runSessVarPred = filterSessionVariables . unSessVarPred
-- | Filter out only those session variables used by the query AST provided
filterVariablesFromQuery
:: Backend backend
=> [RootField (QueryDBRoot UnpreparedValue) c (ActionQuery backend (UnpreparedValue bet)) d]
=> [RootField (QueryDBRoot UnpreparedValue) RemoteField (ActionQuery backend (UnpreparedValue bet)) d]
-> SessVarPred
filterVariablesFromQuery query = fold $ rootToSessVarPreds =<< query
where
@ -174,17 +174,26 @@ filterVariablesFromQuery query = fold $ rootToSessVarPreds =<< query
RFDB _ exists ->
AB.dispatchAnyBackend @Backend exists \case
SourceConfigWith _ (QDBR db) -> toPred <$> toListOf traverseQueryDB db
RFRemote remote -> match <$> toListOf (traverse . _SessionPresetVariable) remote
RFAction actionQ -> toPred <$> toListOf traverseActionQuery actionQ
_ -> []
_SessionPresetVariable :: Traversal' RemoteSchemaVariable SessionVariable
_SessionPresetVariable f (SessionPresetVariable a b c) =
(\a' -> SessionPresetVariable a' b c) <$> f a
_SessionPresetVariable _ x = pure x
toPred :: UnpreparedValue bet -> SessVarPred
-- if we see a reference to the whole session variables object,
-- then we need to keep everything:
toPred UVSession = keepAllSessionVariables
-- if we only see a specific session variable, we only need to keep that one:
toPred (UVSessionVar _type sv) = SessVarPred $ \sv' _ -> sv == sv'
toPred (UVSessionVar _type sv) = match sv
toPred _ = mempty
match :: SessionVariable -> SessVarPred
match sv = SessVarPred $ \sv' _ -> sv == sv'
-- | Run (execute) a single GraphQL query
runGQ
:: forall m