Improvements to Update Operators api docs

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3225
GitOrigin-RevId: 8f8123353249efb5acaab00681988171e44fae02
This commit is contained in:
Philip Lykke Carlsen 2021-12-29 04:51:01 +01:00 committed by hasura-bot
parent 5fa2e489e8
commit 33a107d371
2 changed files with 23 additions and 20 deletions

View File

@ -806,7 +806,7 @@ deleteAtPathOp = SU.UpdateOperator {..}
desc desc
desc desc
-- | Various update operators -- | The update operators that we support on Postgres.
updateOperators :: updateOperators ::
forall pgKind m n r. forall pgKind m n r.
( MonadParse n, ( MonadParse n,

View File

@ -38,45 +38,48 @@ import Hasura.RQL.Types.Common (SourceName)
import Hasura.RQL.Types.Table (SelPermInfo, TableInfo, UpdPermInfo (..), tableInfoName) import Hasura.RQL.Types.Table (SelPermInfo, TableInfo, UpdPermInfo (..), tableInfoName)
import Language.GraphQL.Draft.Syntax (Description (..), Name (..), Nullability (..), litName) import Language.GraphQL.Draft.Syntax (Description (..), Name (..), Nullability (..), litName)
-- | @UpdateOperator b m n t@ represents one single update operator for a -- | @UpdateOperator b m n op@ represents one single update operator for a
-- backend @b@, parsing a value of type @t@. @UpdateOperator b m n@ is a -- backend @b@.
-- @Functor@, which (apart from the type variable @b@) is what enables
-- multi-backend support.
-- --
-- Use the 'Functor (UpdateOperator b m n)' instance to inject the -- The type variable @op@ is the backend-specific data type that represents
-- @UpdateOperator b m n (UnpreparedValue b)@ operators into backend-specific -- update operators, typically in the form of a sum-type with an
-- IR types that encode update operators. -- @UnpreparedValue b@ in each constructor.
data UpdateOperator b m n t = UpdateOperator --
-- The @UpdateOperator b m n@ is a @Functor@. There exist building blocks of
-- common update operators (such as 'setOp', etc.) which have @op ~
-- UnpreparedValue b@. The Functor instance lets you wrap the generic update
-- operators in backend-specific tags.
data UpdateOperator b m n op = UpdateOperator
{ updateOperatorApplicableColumn :: ColumnInfo b -> Bool, { updateOperatorApplicableColumn :: ColumnInfo b -> Bool,
updateOperatorParser :: updateOperatorParser ::
Name -> Name ->
TableName b -> TableName b ->
NonEmpty (ColumnInfo b) -> NonEmpty (ColumnInfo b) ->
m (P.InputFieldsParser n (HashMap (Column b) t)) m (P.InputFieldsParser n (HashMap (Column b) op))
} }
deriving (Functor) deriving (Functor)
-- | The top-level component for building update operators parsers. -- | The top-level component for building update operators parsers.
-- --
-- * It implements the 'preset' functionality from Update Permissions (see -- * It implements the @preset@ functionality from Update Permissions (see
-- <https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#column-presets -- <https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#column-presets
-- Permissions user docs>) -- Permissions user docs>). Use the 'presetColumns' function to extract those from the update permissions.
-- * It validates that that the update fields parsed are sound when taken as a -- * It validates that that the update fields parsed are sound when taken as a
-- whole, i.e. that some changes are actually specified (either in the -- whole, i.e. that some changes are actually specified (either in the
-- mutation query text or in update preset columns) and that each column is -- mutation query text or in update preset columns) and that each column is
-- only used in one operator. -- only used in one operator.
buildUpdateOperators :: buildUpdateOperators ::
forall b n t m. forall b n op m.
(BackendSchema b, P.MonadSchema n m, MonadError QErr m) => (BackendSchema b, P.MonadSchema n m, MonadError QErr m) =>
-- | Columns with @preset@ expressions -- | Columns with @preset@ expressions
(HashMap (Column b) t) -> (HashMap (Column b) op) ->
-- | Update operators to include in the Schema -- | Update operators to include in the Schema
[UpdateOperator b m n t] -> [UpdateOperator b m n op] ->
TableInfo b -> TableInfo b ->
UpdPermInfo b -> UpdPermInfo b ->
m (P.InputFieldsParser n (HashMap (Column b) t)) m (P.InputFieldsParser n (HashMap (Column b) op))
buildUpdateOperators presetCols ops tableInfo updatePermissions = do buildUpdateOperators presetCols ops tableInfo updatePermissions = do
parsers :: P.InputFieldsParser n [HashMap (Column b) t] <- parsers :: P.InputFieldsParser n [HashMap (Column b) op] <-
sequenceA . catMaybes <$> traverse (runUpdateOperator tableInfo updatePermissions) ops sequenceA . catMaybes <$> traverse (runUpdateOperator tableInfo updatePermissions) ops
pure $ pure $
parsers parsers
@ -94,16 +97,16 @@ presetColumns = fmap partialSQLExpToUnpreparedValue . upiSet
-- | Produce an InputFieldsParser from an UpdateOperator, but only if the operator -- | Produce an InputFieldsParser from an UpdateOperator, but only if the operator
-- applies to the table (i.e., it admits a non-empty column set). -- applies to the table (i.e., it admits a non-empty column set).
runUpdateOperator :: runUpdateOperator ::
forall b m n t. forall b m n op.
(Backend b, P.MonadSchema n m, MonadError QErr m) => (Backend b, P.MonadSchema n m, MonadError QErr m) =>
TableInfo b -> TableInfo b ->
UpdPermInfo b -> UpdPermInfo b ->
UpdateOperator b m n t -> UpdateOperator b m n op ->
m m
( Maybe ( Maybe
( P.InputFieldsParser ( P.InputFieldsParser
n n
(HashMap (Column b) t) (HashMap (Column b) op)
) )
) )
runUpdateOperator tableInfo updatePermissions UpdateOperator {..} = do runUpdateOperator tableInfo updatePermissions UpdateOperator {..} = do