Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides common building blocks for composing Schema Parsers used in the schema of Update Mutations.
Synopsis
- data UpdateOperator b m n op = UpdateOperator {
- updateOperatorApplicableColumn :: ColumnInfo b -> Bool
- updateOperatorParser :: GQLNameIdentifier -> TableName b -> NonEmpty (ColumnInfo b) -> m (InputFieldsParser n (HashMap (Column b) op))
- buildUpdateOperators :: forall b r m n op. MonadBuildSchema b r m n => HashMap (Column b) op -> [UpdateOperator b m n op] -> TableInfo b -> m (InputFieldsParser n (HashMap (Column b) op))
- presetColumns :: UpdPermInfo b -> HashMap (Column b) (UnpreparedValue b)
- runUpdateOperator :: forall b r m n op. MonadBuildSchema b r m n => TableInfo b -> UpdateOperator b m n op -> m (Maybe (InputFieldsParser n (HashMap (Column b) op)))
- mergeDisjoint :: forall b m t. (Backend b, MonadParse m) => [HashMap (Column b) t] -> m (HashMap (Column b) t)
- updateOperator :: forall n r m b a. (MonadParse n, MonadReader r m, Has MkTypename r, Has NamingCase r, Backend b) => GQLNameIdentifier -> GQLNameIdentifier -> GQLNameIdentifier -> (ColumnInfo b -> m (Parser 'Both n a)) -> NonEmpty (ColumnInfo b) -> Description -> Description -> m (InputFieldsParser n (HashMap (Column b) a))
- setOp :: forall b n r m. (BackendSchema b, MonadReader r m, Has MkTypename r, Has NamingCase r, MonadError QErr m, MonadParse n) => UpdateOperator b m n (UnpreparedValue b)
- incOp :: forall b m n r. (Backend b, MonadReader r m, MonadError QErr m, MonadParse n, BackendSchema b, Has MkTypename r, Has NamingCase r) => UpdateOperator b m n (UnpreparedValue b)
- updateTable :: forall b r m n. (MonadBuildSchema b r m n, AggregationPredicatesSchema b, BackendTableSelectSchema b) => InputFieldsParser n (BackendUpdate b (UnpreparedValue b)) -> Scenario -> SourceInfo b -> TableInfo b -> Name -> Maybe Description -> m (Maybe (FieldParser n (AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
- updateTableByPk :: forall b r m n. MonadBuildSchema b r m n => BackendTableSelectSchema b => InputFieldsParser n (BackendUpdate b (UnpreparedValue b)) -> Scenario -> SourceInfo b -> TableInfo b -> Name -> Maybe Description -> m (Maybe (FieldParser n (AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
- mkUpdateObject :: Backend b => TableName b -> [ColumnInfo b] -> UpdPermInfo b -> Maybe NamingCase -> ((BackendUpdate b (UnpreparedValue b), AnnBoolExp b (UnpreparedValue b)), MutationOutputG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)) -> AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
Documentation
data UpdateOperator b m n op Source #
UpdateOperator b m n op
represents one single update operator for a
backend b
.
The type variable op
is the backend-specific data type that represents
update operators, typically in the form of a sum-type with an
UnpreparedValue b
in each constructor.
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.
UpdateOperator | |
|
Instances
(Functor m, Functor n) => Functor (UpdateOperator b m n) Source # | |
Defined in Hasura.GraphQL.Schema.Update fmap :: (a -> b0) -> UpdateOperator b m n a -> UpdateOperator b m n b0 # (<$) :: a -> UpdateOperator b m n b0 -> UpdateOperator b m n a # |
:: forall b r m n op. MonadBuildSchema b r m n | |
=> HashMap (Column b) op | Columns with |
-> [UpdateOperator b m n op] | Update operators to include in the Schema |
-> TableInfo b | |
-> m (InputFieldsParser n (HashMap (Column b) op)) |
The top-level component for building update operators parsers.
- It implements the
preset
functionality from Update Permissions (see <https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#column-presets Permissions user docs>). Use thepresetColumns
function to extract those from the update permissions. - 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 mutation query text or in update preset columns) and that each column is only used in one operator.
presetColumns :: UpdPermInfo b -> HashMap (Column b) (UnpreparedValue b) Source #
The columns that have preset
definitions applied to them. (see
<https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#column-presets
Permissions user docs>)
runUpdateOperator :: forall b r m n op. MonadBuildSchema b r m n => TableInfo b -> UpdateOperator b m n op -> m (Maybe (InputFieldsParser n (HashMap (Column b) op))) Source #
Produce an InputFieldsParser from an UpdateOperator, but only if the operator applies to the table (i.e., it admits a non-empty column set).
mergeDisjoint :: forall b m t. (Backend b, MonadParse m) => [HashMap (Column b) t] -> m (HashMap (Column b) t) Source #
Merge the results of parsed update operators. Throws an error if the same column has been specified in multiple operators.
updateOperator :: forall n r m b a. (MonadParse n, MonadReader r m, Has MkTypename r, Has NamingCase r, Backend b) => GQLNameIdentifier -> GQLNameIdentifier -> GQLNameIdentifier -> (ColumnInfo b -> m (Parser 'Both n a)) -> NonEmpty (ColumnInfo b) -> Description -> Description -> m (InputFieldsParser n (HashMap (Column b) a)) Source #
Construct a parser for a single update operator.
updateOperator _ "op" fp MkOp ["col1","col2"]
gives a parser that accepts
objects in the shape of:
op: { col1: "x", col2: "y" }
And (morally) parses into values:
M.fromList [("col1", MkOp (fp "x")), ("col2", MkOp (fp "y"))]
setOp :: forall b n r m. (BackendSchema b, MonadReader r m, Has MkTypename r, Has NamingCase r, MonadError QErr m, MonadParse n) => UpdateOperator b m n (UnpreparedValue b) Source #
incOp :: forall b m n r. (Backend b, MonadReader r m, MonadError QErr m, MonadParse n, BackendSchema b, Has MkTypename r, Has NamingCase r) => UpdateOperator b m n (UnpreparedValue b) Source #
:: forall b r m n. (MonadBuildSchema b r m n, AggregationPredicatesSchema b, BackendTableSelectSchema b) | |
=> InputFieldsParser n (BackendUpdate b (UnpreparedValue b)) | backend-specific data needed to perform an update mutation |
-> Scenario | |
-> SourceInfo b | table source |
-> TableInfo b | table info |
-> Name | field display name |
-> Maybe Description | field description, if any |
-> m (Maybe (FieldParser n (AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))) |
Construct a root field, normally called update_tablename, that can be used to update rows in a DB table specified by filters. Only returns a parser if there are columns the user is allowed to update; otherwise returns Nothing.
:: forall b r m n. MonadBuildSchema b r m n | |
=> BackendTableSelectSchema b | |
=> InputFieldsParser n (BackendUpdate b (UnpreparedValue b)) | backend-specific data needed to perform an update mutation |
-> Scenario | |
-> SourceInfo b | table source |
-> TableInfo b | table info |
-> Name | field display name |
-> Maybe Description | field description, if any |
-> m (Maybe (FieldParser n (AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))) |
Construct a root field, normally called update_tablename_by_pk
, that can be used
to update a single in a DB table, specified by primary key. Only returns a
parser if there are columns the user is allowed to update and if the user has
select permissions on all primary keys; otherwise returns Nothing.
mkUpdateObject :: Backend b => TableName b -> [ColumnInfo b] -> UpdPermInfo b -> Maybe NamingCase -> ((BackendUpdate b (UnpreparedValue b), AnnBoolExp b (UnpreparedValue b)), MutationOutputG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)) -> AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b) Source #