mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
d91029ad51
### Description This PR removes all `fmapX` and `traverseX` functions from RQL.IR, favouring instead `Functor` and `Traversable` instances throughout the code. This was a relatively straightforward change, except for two small pain points: `AnnSelectG` and `AnnInsert`. Both were parametric over two types `a` and `v`, making it impossible to make them traversable functors... But it turns out that in every single use case, `a ~ f v`. By changing those types to take such an `f :: Type -> Type` as an argument instead of `a :: Type` makes it possible to make them functors. The only small difference is for `AnnIns`, I had to introduce one `Identity` transformation for one of the `f` parameters. This is relatively straightforward. ### Notes This PR fixes the most verbose BigQuery hint (`let` instead of `<- pure`). https://github.com/hasura/graphql-engine-mono/pull/1668 GitOrigin-RevId: e632263a8c559aa04aeae10dcaec915b4a81ad1a
53 lines
1.7 KiB
Haskell
53 lines
1.7 KiB
Haskell
module Hasura.RQL.IR.Update where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Data.Kind (Type)
|
|
|
|
import Hasura.RQL.IR.BoolExp
|
|
import Hasura.RQL.IR.Returning
|
|
import Hasura.RQL.Types.Backend
|
|
import Hasura.RQL.Types.Column
|
|
import Hasura.SQL.Backend
|
|
|
|
|
|
data AnnUpdG (b :: BackendType) (r :: BackendType -> Type) v
|
|
= AnnUpd
|
|
{ uqp1Table :: !(TableName b)
|
|
, uqp1OpExps :: ![(Column b, UpdOpExpG v)]
|
|
, uqp1Where :: !(AnnBoolExp b v, AnnBoolExp b v)
|
|
, uqp1Check :: !(AnnBoolExp b v)
|
|
-- we don't prepare the arguments for returning
|
|
-- however the session variable can still be
|
|
-- converted as desired
|
|
, uqp1Output :: !(MutationOutputG b r v)
|
|
, uqp1AllCols :: ![ColumnInfo b]
|
|
} deriving (Functor, Foldable, Traversable)
|
|
|
|
type AnnUpd b = AnnUpdG b (Const Void) (SQLExpression b)
|
|
|
|
data UpdOpExpG v
|
|
= UpdSet !v
|
|
| UpdInc !v
|
|
| UpdAppend !v
|
|
| UpdPrepend !v
|
|
| UpdDeleteKey !v
|
|
| UpdDeleteElem !v
|
|
| UpdDeleteAtPath ![v]
|
|
deriving (Functor, Foldable, Traversable, Generic, Data)
|
|
|
|
|
|
-- NOTE: This function can be improved, because we use
|
|
-- the literal values defined below in the 'updateOperators'
|
|
-- function in 'Hasura.GraphQL.Schema.Mutation'. It would
|
|
-- be nice if we could avoid duplicating the string literal
|
|
-- values
|
|
updateOperatorText :: UpdOpExpG a -> Text
|
|
updateOperatorText (UpdSet _) = "_set"
|
|
updateOperatorText (UpdInc _) = "_inc"
|
|
updateOperatorText (UpdAppend _) = "_append"
|
|
updateOperatorText (UpdPrepend _) = "_prepend"
|
|
updateOperatorText (UpdDeleteKey _) = "_delete_key"
|
|
updateOperatorText (UpdDeleteElem _) = "_delete_elem"
|
|
updateOperatorText (UpdDeleteAtPath _) = "_delete_at_path"
|