mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-10-05 06:18:04 +03:00
server: adding a few code comments
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5014 GitOrigin-RevId: 7f0cb241d3eb2d91bd6feb2b2eb6bf830f1757f9
This commit is contained in:
parent
84366c9281
commit
555e0d0afe
@ -1763,7 +1763,7 @@ fromGBoolExp =
|
||||
fmap OrExpression (traverse fromGBoolExp expressions)
|
||||
Ir.BoolNot expression -> fmap NotExpression (fromGBoolExp expression)
|
||||
Ir.BoolExists gExists -> fmap ExistsExpression (fromGExists gExists)
|
||||
Ir.BoolFld expression -> pure expression
|
||||
Ir.BoolField expression -> pure expression
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Misc combinators
|
||||
|
@ -239,9 +239,9 @@ mkPlan session (SourceConfig {}) ir = translateQueryDB ir
|
||||
mkIfZeroOrMany IR.E.Or <$> traverse (translateBoolExp columnRelationshipReversePath sourceTableName) xs
|
||||
BoolNot x ->
|
||||
IR.E.Not <$> (translateBoolExp columnRelationshipReversePath sourceTableName) x
|
||||
BoolFld (AVColumn c xs) ->
|
||||
BoolField (AVColumn c xs) ->
|
||||
lift $ mkIfZeroOrMany IR.E.And <$> traverse (translateOp columnRelationshipReversePath (ciColumn c)) xs
|
||||
BoolFld (AVRelationship relationshipInfo boolExp) -> do
|
||||
BoolField (AVRelationship relationshipInfo boolExp) -> do
|
||||
let relationshipName = IR.R.mkRelationshipName $ riName relationshipInfo
|
||||
let targetTable = riRTable relationshipInfo
|
||||
let relationshipType = case riType relationshipInfo of
|
||||
|
@ -43,7 +43,7 @@ fromGBoolExp =
|
||||
fmap NotExpression (fromGBoolExp expression)
|
||||
IR.BoolExists gExists ->
|
||||
fromGExists gExists
|
||||
IR.BoolFld expression ->
|
||||
IR.BoolField expression ->
|
||||
fromAnnBoolExpFld expression
|
||||
where
|
||||
fromGExists :: IR.GExists 'MSSQL (IR.AnnBoolExpFld 'MSSQL Expression) -> ReaderT EntityAlias FromIr Expression
|
||||
|
@ -946,7 +946,7 @@ fromGBoolExp =
|
||||
fmap NotExpression (fromGBoolExp expression)
|
||||
IR.BoolExists gExists ->
|
||||
fromGExists gExists
|
||||
IR.BoolFld expression ->
|
||||
IR.BoolField expression ->
|
||||
fromAnnBoolExpFld expression
|
||||
where
|
||||
fromGExists :: IR.GExists 'MSSQL (IR.AnnBoolExpFld 'MSSQL Expression) -> ReaderT EntityAlias FromIr Expression
|
||||
|
@ -153,7 +153,7 @@ fromGBoolExp = do
|
||||
fmap NotExpression (fromGBoolExp expression)
|
||||
IR.BoolExists gExists ->
|
||||
fmap ExistsExpression (fromGExists gExists)
|
||||
IR.BoolFld expression ->
|
||||
IR.BoolField expression ->
|
||||
pure expression
|
||||
|
||||
fromAnnBoolExp ::
|
||||
|
@ -71,7 +71,7 @@ annBoolExp rhsParser rootTable fim boolExp =
|
||||
refFields <- withPathK "_table" $ askFieldInfoMapSource refqt
|
||||
annWhereExp <- withPathK "_where" $ annBoolExp rhsParser rootTable refFields whereExp
|
||||
return $ BoolExists $ GExists refqt annWhereExp
|
||||
BoolFld fld -> BoolFld <$> annColExp rhsParser rootTable fim fld
|
||||
BoolField fld -> BoolField <$> annColExp rhsParser rootTable fim fld
|
||||
where
|
||||
procExps = mapM (annBoolExp rhsParser rootTable fim)
|
||||
|
||||
@ -157,7 +157,7 @@ translateBoolExp = \case
|
||||
BoolExists (GExists currTableReference wh) -> do
|
||||
whereExp <- recCurrentTable (S.QualTable currTableReference) wh
|
||||
return $ S.mkExists (S.FISimple currTableReference Nothing) whereExp
|
||||
BoolFld boolExp -> case boolExp of
|
||||
BoolField boolExp -> case boolExp of
|
||||
AVColumn colInfo opExps -> do
|
||||
BoolExpCtx {rootReference, currTableReference} <- ask
|
||||
let colFld = fromCol @('Postgres pgKind) $ ciColumn colInfo
|
||||
|
@ -34,7 +34,7 @@ import Hasura.Backends.Postgres.Types.Column (unsafePGColumnToBackend)
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
( AnnBoolExpFld (AVColumn),
|
||||
GBoolExp (BoolFld),
|
||||
GBoolExp (BoolField),
|
||||
OpExpG (AGT, ALT),
|
||||
andAnnBoolExps,
|
||||
)
|
||||
@ -87,7 +87,7 @@ mkStreamSQLSelect (AnnSelectStreamG () fields from perm args strfyNum) =
|
||||
fromResVars
|
||||
(CollectableTypeScalar $ unsafePGColumnToBackend $ cvType (_sciInitialValue cursorArg))
|
||||
["cursor", getPGColTxt $ ciColumn cursorColInfo]
|
||||
in BoolFld $ AVColumn cursorColInfo [(orderByOpExp sqlExp)]
|
||||
in BoolField $ AVColumn cursorColInfo [(orderByOpExp sqlExp)]
|
||||
|
||||
selectArgs =
|
||||
noSelectArgs
|
||||
|
@ -356,13 +356,13 @@ resolveAsyncActionQuery userInfo annAction =
|
||||
ciDescription = Nothing,
|
||||
ciMutability = ColumnMutability False False
|
||||
}
|
||||
actionIdColumnEq = BoolFld $ AVColumn actionIdColumnInfo [AEQ True $ IR.UVLiteral $ S.SELit $ actionIdToText actionId]
|
||||
actionIdColumnEq = BoolField $ AVColumn actionIdColumnInfo [AEQ True $ IR.UVLiteral $ S.SELit $ actionIdToText actionId]
|
||||
sessionVarsColumnInfo = mkPGColumnInfo sessionVarsColumn
|
||||
sessionVarValue =
|
||||
IR.UVParameter Nothing $
|
||||
ColumnValue (ColumnScalar PGJSONB) $
|
||||
PGValJSONB $ Q.JSONB $ J.toJSON $ _uiSession userInfo
|
||||
sessionVarsColumnEq = BoolFld $ AVColumn sessionVarsColumnInfo [AEQ True sessionVarValue]
|
||||
sessionVarsColumnEq = BoolField $ AVColumn sessionVarsColumnInfo [AEQ True sessionVarValue]
|
||||
in -- For non-admin roles, accessing an async action's response should be allowed only for the user
|
||||
-- who initiated the action through mutation. The action's response is accessible for a query/subscription
|
||||
-- only when it's session variables are equal to that of action's.
|
||||
|
@ -72,7 +72,7 @@ boolExp sourceInfo tableInfo = memoizeOn 'boolExp (_siName sourceInfo, tableName
|
||||
|
||||
pure $
|
||||
BoolAnd <$> P.object name (Just description) do
|
||||
tableFields <- map BoolFld . catMaybes <$> sequenceA tableFieldParsers
|
||||
tableFields <- map BoolField . catMaybes <$> sequenceA tableFieldParsers
|
||||
specialFields <- catMaybes <$> sequenceA specialFieldParsers
|
||||
pure (tableFields ++ specialFields)
|
||||
where
|
||||
|
@ -472,5 +472,5 @@ primaryKeysArguments tableInfo = runMaybeT $ do
|
||||
fmap (BoolAnd . toList) . sequenceA <$> for columns \columnInfo -> do
|
||||
field <- columnParser (ciType columnInfo) (G.Nullability False)
|
||||
pure $
|
||||
BoolFld . AVColumn columnInfo . pure . AEQ True . IR.mkParameter
|
||||
BoolField . AVColumn columnInfo . pure . AEQ True . IR.mkParameter
|
||||
<$> P.field (ciName columnInfo) (ciDescription columnInfo) field
|
||||
|
@ -216,7 +216,7 @@ nodeField sourceCache = do
|
||||
parseScalarValueColumnType columnType columnValue `onLeft` \e ->
|
||||
P.parseErrorWith ParseFailed $ "value of column " <> ciColumn columnInfo <<> " in node id: " <> qeError e
|
||||
pure $
|
||||
IR.BoolFld $
|
||||
IR.BoolField $
|
||||
IR.AVColumn
|
||||
columnInfo
|
||||
[IR.AEQ True $ IR.UVParameter Nothing $ ColumnValue columnType parsedValue]
|
||||
|
@ -211,7 +211,7 @@ selectTableByPk sourceInfo tableInfo fieldName description = runMaybeT do
|
||||
sequenceA <$> for primaryKeys \columnInfo -> do
|
||||
field <- columnParser (ciType columnInfo) (G.Nullability $ ciIsNullable columnInfo)
|
||||
pure $
|
||||
BoolFld . AVColumn columnInfo . pure . AEQ True . IR.mkParameter
|
||||
BoolField . AVColumn columnInfo . pure . AEQ True . IR.mkParameter
|
||||
<$> P.field (ciName columnInfo) (ciDescription columnInfo) field
|
||||
pure $
|
||||
P.setFieldParserOrigin (MOSource (_siName sourceInfo)) $
|
||||
@ -1107,7 +1107,7 @@ relationshipField sourceInfo table ri = runMaybeT do
|
||||
let deduplicatePermissions :: AnnBoolExp b (IR.UnpreparedValue b) -> AnnBoolExp b (IR.UnpreparedValue b)
|
||||
deduplicatePermissions x =
|
||||
case (optimizePermissionFilters, x) of
|
||||
(True, BoolAnd [BoolFld (AVRelationship remoteRI remoteTablePerm)]) ->
|
||||
(True, BoolAnd [BoolField (AVRelationship remoteRI remoteTablePerm)]) ->
|
||||
-- Here we try to figure out if the "forwards" joining condition
|
||||
-- from `table` to the related table `riRTable ri` is equal to the
|
||||
-- "backwards" joining condition from the related table back to
|
||||
|
@ -453,7 +453,7 @@ updateFieldInBoolExp qt rf be =
|
||||
BoolExists (GExists refqt wh) ->
|
||||
BoolExists . GExists refqt . unBoolExp
|
||||
<$> updateFieldInBoolExp refqt rf (BoolExp wh)
|
||||
BoolFld fld -> BoolFld <$> updateColExp qt rf fld
|
||||
BoolField fld -> BoolField <$> updateColExp qt rf fld
|
||||
where
|
||||
procExps = mapM updateBoolExp'
|
||||
updateBoolExp' =
|
||||
|
@ -1,6 +1,14 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
|
||||
-- | Boolean Expressions
|
||||
--
|
||||
-- This module defines the IR representation of boolean expressions
|
||||
-- used in @_where@ clauses in GraphQL queries, permissions, and so on.
|
||||
--
|
||||
-- The types in this module define a /generic/ structure with "holes" to be filled
|
||||
-- by each backend. Specifically, holes will include things like types for table names,
|
||||
-- and backend field types.
|
||||
module Hasura.RQL.IR.BoolExp
|
||||
( BoolExp (..),
|
||||
ColExp (..),
|
||||
@ -63,15 +71,23 @@ import Hasura.Session
|
||||
----------------------------------------------------------------------------------------------------
|
||||
-- Boolean structure
|
||||
|
||||
-- | This type represents a hierarchical boolean expression. It is parametric over the actual
|
||||
-- | This type represents a boolean expression tree. It is parametric over the actual
|
||||
-- implementation of the actual boolean term values. It nonetheless leaks some information:
|
||||
-- "exists" is only used in permissions, to add conditions based on another table.
|
||||
data GBoolExp (b :: BackendType) a
|
||||
= BoolAnd [GBoolExp b a]
|
||||
| BoolOr [GBoolExp b a]
|
||||
| BoolNot (GBoolExp b a)
|
||||
| BoolExists (GExists b a)
|
||||
| BoolFld a
|
||||
--
|
||||
-- * The @backend@ parameter is used to find the backend-specific type for table names
|
||||
-- in the @BoolExists@ constructor.
|
||||
-- * The @field@ type represent the type of database-specific field types.
|
||||
data GBoolExp (backend :: BackendType) field
|
||||
= BoolAnd [GBoolExp backend field]
|
||||
| BoolOr [GBoolExp backend field]
|
||||
| BoolNot (GBoolExp backend field)
|
||||
| -- | Represents a condition on an aribtrary table.
|
||||
-- since the @backend@ and @field@ are the same,
|
||||
-- the table must be of the same database type.
|
||||
BoolExists (GExists backend field)
|
||||
| -- | A column field
|
||||
BoolField field
|
||||
deriving (Show, Eq, Functor, Foldable, Traversable, Data, Generic)
|
||||
|
||||
instance (Backend b, NFData a) => NFData (GBoolExp b a)
|
||||
@ -94,36 +110,41 @@ instance (Backend b, FromJSONKeyValue a) => FromJSON (GBoolExp b a) where
|
||||
| k == "_not" -> BoolNot <$> parseJSON v <?> Key k
|
||||
| k == "$exists" -> BoolExists <$> parseJSON v <?> Key k
|
||||
| k == "_exists" -> BoolExists <$> parseJSON v <?> Key k
|
||||
| otherwise -> BoolFld <$> parseJSONKeyValue (k, v)
|
||||
| otherwise -> BoolField <$> parseJSONKeyValue (k, v)
|
||||
|
||||
instance (Backend b, ToJSONKeyValue a) => ToJSON (GBoolExp b a) where
|
||||
instance (Backend backend, ToJSONKeyValue field) => ToJSON (GBoolExp backend field) where
|
||||
-- A representation for boolean values as JSON.
|
||||
toJSON be = case be of
|
||||
-- special encoding for _and
|
||||
-- @and@ expressions can be represented differently than the rest
|
||||
-- if the keys are unique
|
||||
BoolAnd bExps ->
|
||||
let m = M.fromList $ map getKV bExps
|
||||
in -- if the keys aren't repeated, then object encoding can be used
|
||||
in -- if the keys aren't repeated, then the special notation of object encoding can be used
|
||||
if length m == length bExps
|
||||
then toJSON m
|
||||
else object $ pure kv
|
||||
_ -> object $ pure kv
|
||||
where
|
||||
kv :: (Key, Value)
|
||||
kv = getKV be
|
||||
getKV :: GBoolExp backend field -> (Key, Value)
|
||||
getKV = \case
|
||||
BoolAnd bExps -> "_and" .= map toJSON bExps
|
||||
BoolOr bExps -> "_or" .= map toJSON bExps
|
||||
BoolNot bExp -> "_not" .= toJSON bExp
|
||||
BoolExists bExists -> "_exists" .= toJSON bExists
|
||||
BoolFld a -> toJSONKeyValue a
|
||||
BoolField a -> toJSONKeyValue a
|
||||
|
||||
gBoolExpTrue :: GBoolExp b a
|
||||
-- | A default representation for a @true@ boolean value.
|
||||
gBoolExpTrue :: GBoolExp backend field
|
||||
gBoolExpTrue = BoolAnd []
|
||||
|
||||
-- | Represents a condition on an aribtrary table. Used as part of our permissions boolean
|
||||
-- expressions. See our documentation for more information:
|
||||
-- https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#using-unrelated-tables-views
|
||||
data GExists (b :: BackendType) a = GExists
|
||||
{ _geTable :: TableName b,
|
||||
_geWhere :: GBoolExp b a
|
||||
-- <https://hasura.io/docs/latest/graphql/core/auth/authorization/permission-rules.html#using-unrelated-tables-views>
|
||||
data GExists (backend :: BackendType) field = GExists
|
||||
{ _geTable :: TableName backend,
|
||||
_geWhere :: GBoolExp backend field
|
||||
}
|
||||
deriving (Functor, Foldable, Traversable, Generic)
|
||||
|
||||
@ -189,10 +210,10 @@ makePrisms ''GBoolExp
|
||||
-- | Permissions get translated into boolean expressions that are threaded throuhgout the
|
||||
-- parsers. For the leaf values of those permissions, we use this type, which references but doesn't
|
||||
-- inline the session variables.
|
||||
data PartialSQLExp (b :: BackendType)
|
||||
= PSESessVar (SessionVarType b) SessionVariable
|
||||
data PartialSQLExp (backend :: BackendType)
|
||||
= PSESessVar (SessionVarType backend) SessionVariable
|
||||
| PSESession
|
||||
| PSESQLExp (SQLExpression b)
|
||||
| PSESQLExp (SQLExpression backend)
|
||||
deriving (Generic)
|
||||
|
||||
deriving instance (Backend b) => Eq (PartialSQLExp b)
|
||||
@ -224,32 +245,32 @@ hasStaticExp = getAny . foldMap (Any . isStaticValue)
|
||||
-- Boolean expressions in the schema
|
||||
|
||||
-- | Operand for cast operator
|
||||
type CastExp b a = M.HashMap (ScalarType b) [OpExpG b a]
|
||||
type CastExp backend field = M.HashMap (ScalarType backend) [OpExpG backend field]
|
||||
|
||||
-- | This type represents the boolean operators that can be applied on values of a column. This type
|
||||
-- only contains the common core, that we expect to be ultimately entirely supported in most if not
|
||||
-- all backends. Backends can extend this with the @BooleanOperators@ type in @Backend@.
|
||||
data OpExpG (b :: BackendType) a
|
||||
= ACast (CastExp b a)
|
||||
| AEQ Bool a
|
||||
| ANE Bool a
|
||||
| AIN a
|
||||
| ANIN a
|
||||
| AGT a
|
||||
| ALT a
|
||||
| AGTE a
|
||||
| ALTE a
|
||||
| ALIKE a -- LIKE
|
||||
| ANLIKE a -- NOT LIKE
|
||||
| CEQ (RootOrCurrentColumn b)
|
||||
| CNE (RootOrCurrentColumn b)
|
||||
| CGT (RootOrCurrentColumn b)
|
||||
| CLT (RootOrCurrentColumn b)
|
||||
| CGTE (RootOrCurrentColumn b)
|
||||
| CLTE (RootOrCurrentColumn b)
|
||||
data OpExpG (backend :: BackendType) field
|
||||
= ACast (CastExp backend field)
|
||||
| AEQ Bool field
|
||||
| ANE Bool field
|
||||
| AIN field
|
||||
| ANIN field
|
||||
| AGT field
|
||||
| ALT field
|
||||
| AGTE field
|
||||
| ALTE field
|
||||
| ALIKE field -- LIKE
|
||||
| ANLIKE field -- NOT LIKE
|
||||
| CEQ (RootOrCurrentColumn backend)
|
||||
| CNE (RootOrCurrentColumn backend)
|
||||
| CGT (RootOrCurrentColumn backend)
|
||||
| CLT (RootOrCurrentColumn backend)
|
||||
| CGTE (RootOrCurrentColumn backend)
|
||||
| CLTE (RootOrCurrentColumn backend)
|
||||
| ANISNULL -- IS NULL
|
||||
| ANISNOTNULL -- IS NOT NULL
|
||||
| ABackendSpecific (BooleanOperators b a)
|
||||
| ABackendSpecific (BooleanOperators backend field)
|
||||
deriving (Generic)
|
||||
|
||||
data RootOrCurrentColumn b = RootOrCurrentColumn RootOrCurrent (Column b)
|
||||
@ -319,7 +340,7 @@ instance (Backend b, ToJSONKeyValue (BooleanOperators b a), ToJSON a) => ToJSONK
|
||||
ANISNOTNULL -> ("_is_null", toJSON False)
|
||||
ABackendSpecific b -> toJSONKeyValue b
|
||||
|
||||
opExpDepCol :: OpExpG backend a -> Maybe (RootOrCurrentColumn backend)
|
||||
opExpDepCol :: OpExpG backend field -> Maybe (RootOrCurrentColumn backend)
|
||||
opExpDepCol = \case
|
||||
CEQ c -> Just c
|
||||
CNE c -> Just c
|
||||
@ -330,10 +351,12 @@ opExpDepCol = \case
|
||||
_ -> Nothing
|
||||
|
||||
-- | This type is used to represent the kinds of boolean expression used for compouted fields
|
||||
-- based on the return type of the SQL function
|
||||
data ComputedFieldBoolExp (b :: BackendType) a
|
||||
= CFBEScalar [OpExpG b a] -- SQL function returning a scalar
|
||||
| CFBETable (TableName b) (AnnBoolExp b a) -- SQL function returning SET OF table
|
||||
-- based on the return type of the SQL function.
|
||||
data ComputedFieldBoolExp (backend :: BackendType) scalar
|
||||
= -- | SQL function returning a scalar
|
||||
CFBEScalar [OpExpG backend scalar]
|
||||
| -- | SQL function returning SET OF table
|
||||
CFBETable (TableName backend) (AnnBoolExp backend scalar)
|
||||
deriving (Functor, Foldable, Traversable, Generic)
|
||||
|
||||
deriving instance (Backend b, Eq (BooleanOperators b a), Eq (FunctionArgumentExp b a), Eq a) => Eq (ComputedFieldBoolExp b a)
|
||||
@ -357,15 +380,15 @@ instance (Backend b, Hashable (BooleanOperators b a), Hashable (FunctionArgument
|
||||
-- full_name
|
||||
-- }
|
||||
-- }
|
||||
-- Limitation: Computed field whose function with no input arguments are allowed in boolean
|
||||
-- expression. It is complex to generate schema for `where` clause with functions having
|
||||
-- input arguments.
|
||||
data AnnComputedFieldBoolExp (b :: BackendType) a = AnnComputedFieldBoolExp
|
||||
{ _acfbXFieldInfo :: XComputedField b,
|
||||
-- Limitation: We only support computed fields in boolean expressions when they
|
||||
-- are functions with no input arguments, because it is complex to generate schema
|
||||
-- for @where@ clauses for functions that have input arguments.
|
||||
data AnnComputedFieldBoolExp (backend :: BackendType) scalar = AnnComputedFieldBoolExp
|
||||
{ _acfbXFieldInfo :: XComputedField backend,
|
||||
_acfbName :: ComputedFieldName,
|
||||
_acfbFunction :: FunctionName b,
|
||||
_acfbFunctionArgsExp :: FunctionArgsExp b a,
|
||||
_acfbBoolExp :: ComputedFieldBoolExp b a
|
||||
_acfbFunction :: FunctionName backend,
|
||||
_acfbFunctionArgsExp :: FunctionArgsExp backend scalar,
|
||||
_acfbBoolExp :: ComputedFieldBoolExp backend scalar
|
||||
}
|
||||
deriving (Generic)
|
||||
|
||||
@ -389,12 +412,13 @@ instance (Backend b, Hashable (BooleanOperators b a), Hashable (FunctionArgument
|
||||
-- terms:
|
||||
-- - operators on a column of the current table, using the 'OpExpG' kind of operators
|
||||
-- - arbitrary expressions on columns of tables in relationships (in the same source)
|
||||
-- - A computed field of the current table
|
||||
--
|
||||
-- This type is parametric over the type of leaf values, the values on which we operate.
|
||||
data AnnBoolExpFld (b :: BackendType) a
|
||||
= AVColumn (ColumnInfo b) [OpExpG b a]
|
||||
| AVRelationship (RelInfo b) (AnnBoolExp b a)
|
||||
| AVComputedField (AnnComputedFieldBoolExp b a)
|
||||
-- This type is parameterized over the type of leaf values, the values on which we operate.
|
||||
data AnnBoolExpFld (backend :: BackendType) leaf
|
||||
= AVColumn (ColumnInfo backend) [OpExpG backend leaf]
|
||||
| AVRelationship (RelInfo backend) (AnnBoolExp backend leaf)
|
||||
| AVComputedField (AnnComputedFieldBoolExp backend leaf)
|
||||
deriving (Functor, Foldable, Traversable, Generic)
|
||||
|
||||
deriving instance (Backend b, Eq (BooleanOperators b a), Eq (FunctionArgumentExp b a), Eq a) => Eq (AnnBoolExpFld b a)
|
||||
@ -427,19 +451,19 @@ instance (Backend b, ToJSONKeyValue (BooleanOperators b a), ToJSON a) => ToJSONK
|
||||
|
||||
-- | A simple alias for the kind of boolean expressions used in the schema, that ties together
|
||||
-- 'GBoolExp', 'OpExpG', and 'AnnBoolExpFld'.
|
||||
type AnnBoolExp b a = GBoolExp b (AnnBoolExpFld b a)
|
||||
type AnnBoolExp backend scalar = GBoolExp backend (AnnBoolExpFld backend scalar)
|
||||
|
||||
-- Type aliases for common use cases:
|
||||
type AnnBoolExpFldSQL b = AnnBoolExpFld b (SQLExpression b)
|
||||
type AnnBoolExpFldSQL backend = AnnBoolExpFld backend (SQLExpression backend)
|
||||
|
||||
type AnnBoolExpSQL b = AnnBoolExp b (SQLExpression b)
|
||||
type AnnBoolExpSQL backend = AnnBoolExp backend (SQLExpression backend)
|
||||
|
||||
type AnnBoolExpPartialSQL b = AnnBoolExp b (PartialSQLExp b)
|
||||
type AnnBoolExpPartialSQL backend = AnnBoolExp backend (PartialSQLExp backend)
|
||||
|
||||
annBoolExpTrue :: AnnBoolExp backend a
|
||||
annBoolExpTrue :: AnnBoolExp backend scalar
|
||||
annBoolExpTrue = gBoolExpTrue
|
||||
|
||||
andAnnBoolExps :: AnnBoolExp backend a -> AnnBoolExp backend a -> AnnBoolExp backend a
|
||||
andAnnBoolExps :: AnnBoolExp backend scalar -> AnnBoolExp backend scalar -> AnnBoolExp backend scalar
|
||||
andAnnBoolExps l r = BoolAnd [l, r]
|
||||
|
||||
----------------------------------------------------------------------------------------------------
|
||||
@ -449,9 +473,9 @@ andAnnBoolExps l r = BoolAnd [l, r]
|
||||
-- are part of the common core of operators.
|
||||
|
||||
-- | Operand for STDWithin opoerator
|
||||
data DWithinGeomOp a = DWithinGeomOp
|
||||
{ dwgeomDistance :: a,
|
||||
dwgeomFrom :: a
|
||||
data DWithinGeomOp field = DWithinGeomOp
|
||||
{ dwgeomDistance :: field,
|
||||
dwgeomFrom :: field
|
||||
}
|
||||
deriving (Show, Eq, Functor, Foldable, Traversable, Generic, Data)
|
||||
|
||||
@ -464,10 +488,10 @@ instance (Hashable a) => Hashable (DWithinGeomOp a)
|
||||
$(deriveJSON hasuraJSON ''DWithinGeomOp)
|
||||
|
||||
-- | Operand for STDWithin opoerator
|
||||
data DWithinGeogOp a = DWithinGeogOp
|
||||
{ dwgeogDistance :: a,
|
||||
dwgeogFrom :: a,
|
||||
dwgeogUseSpheroid :: a
|
||||
data DWithinGeogOp field = DWithinGeogOp
|
||||
{ dwgeogDistance :: field,
|
||||
dwgeogFrom :: field,
|
||||
dwgeogUseSpheroid :: field
|
||||
}
|
||||
deriving (Show, Eq, Functor, Foldable, Traversable, Generic, Data)
|
||||
|
||||
@ -480,9 +504,9 @@ instance (Hashable a) => Hashable (DWithinGeogOp a)
|
||||
$(deriveJSON hasuraJSON ''DWithinGeogOp)
|
||||
|
||||
-- | Operand for STIntersect
|
||||
data STIntersectsNbandGeommin a = STIntersectsNbandGeommin
|
||||
{ singNband :: a,
|
||||
singGeommin :: a
|
||||
data STIntersectsNbandGeommin field = STIntersectsNbandGeommin
|
||||
{ singNband :: field,
|
||||
singGeommin :: field
|
||||
}
|
||||
deriving (Show, Eq, Functor, Foldable, Traversable, Generic, Data)
|
||||
|
||||
@ -495,9 +519,9 @@ instance (Hashable a) => Hashable (STIntersectsNbandGeommin a)
|
||||
$(deriveJSON hasuraJSON ''STIntersectsNbandGeommin)
|
||||
|
||||
-- | Operand for STIntersect
|
||||
data STIntersectsGeomminNband a = STIntersectsGeomminNband
|
||||
{ signGeommin :: a,
|
||||
signNband :: Maybe a
|
||||
data STIntersectsGeomminNband field = STIntersectsGeomminNband
|
||||
{ signGeommin :: field,
|
||||
signNband :: Maybe field
|
||||
}
|
||||
deriving (Show, Eq, Functor, Foldable, Traversable, Generic, Data)
|
||||
|
||||
@ -515,7 +539,7 @@ $(deriveJSON hasuraJSON ''STIntersectsGeomminNband)
|
||||
-- | This is a simple newtype over AnnBoolExpFld. At time of writing, I do not know why we want
|
||||
-- this, and why it exists. It might be a relic of a needed differentiation, now lost?
|
||||
-- TODO: can this be removed?
|
||||
newtype AnnColumnCaseBoolExpField (b :: BackendType) a = AnnColumnCaseBoolExpField {_accColCaseBoolExpField :: AnnBoolExpFld b a}
|
||||
newtype AnnColumnCaseBoolExpField (backend :: BackendType) field = AnnColumnCaseBoolExpField {_accColCaseBoolExpField :: AnnBoolExpFld backend field}
|
||||
deriving (Functor, Foldable, Traversable, Generic)
|
||||
|
||||
deriving instance (Backend b, Eq (BooleanOperators b a), Eq (FunctionArgumentExp b a), Eq a) => Eq (AnnColumnCaseBoolExpField b a)
|
||||
|
@ -132,7 +132,7 @@ instance (Backend b, Eq a, Hashable a) => OnlyRelevantEq (GBoolExp b a) where
|
||||
BoolOr boolExpL `relevantEq` BoolOr boolExpR = Set.fromList boolExpL == Set.fromList boolExpR
|
||||
BoolNot boolExpL `relevantEq` BoolNot boolExpR = boolExpL == boolExpR
|
||||
BoolExists boolExpL `relevantEq` BoolExists boolExpR = boolExpL == boolExpR
|
||||
BoolFld boolExpL `relevantEq` BoolFld boolExpR = boolExpL == boolExpR
|
||||
BoolField boolExpL `relevantEq` BoolField boolExpR = boolExpL == boolExpR
|
||||
_ `relevantEq` _ = False
|
||||
|
||||
instance (Backend b, Eq a, Eq (BooleanOperators b a), Eq (FunctionArgumentExp b a)) => OnlyRelevantEq (AnnComputedFieldBoolExp b a) where
|
||||
|
@ -750,7 +750,7 @@ getBoolExpDeps' = \case
|
||||
BoolAnd exps -> procExps exps
|
||||
BoolOr exps -> procExps exps
|
||||
BoolNot e -> getBoolExpDeps' e
|
||||
BoolFld fld -> getColExpDeps fld
|
||||
BoolField fld -> getColExpDeps fld
|
||||
BoolExists (GExists refqt whereExp) -> do
|
||||
BoolExpCtx {source} <- ask
|
||||
let tableDep =
|
||||
|
@ -75,7 +75,7 @@ genAnnBoolExp
|
||||
boolOr = BoolOr <$> list defaultRange (genAnnBoolExp aGen tableGen)
|
||||
boolNot = BoolNot <$> genAnnBoolExp aGen tableGen
|
||||
boolExists = BoolExists <$> genGExists aGen tableGen
|
||||
boolFld = BoolFld <$> aGen
|
||||
boolFld = BoolField <$> aGen
|
||||
|
||||
genAnnBoolExpFld ::
|
||||
MonadGen m =>
|
||||
|
@ -141,7 +141,7 @@ mkAnnotatedUpdate AnnotatedUpdateBuilder {..} = AnnotatedUpdateG {..}
|
||||
_auWhere :: (BoolExp, BoolExp)
|
||||
_auWhere =
|
||||
( column [],
|
||||
BoolAnd $ fmap (\(c, ops) -> BoolFld $ AVColumn c ops) aubWhere
|
||||
BoolAnd $ fmap (\(c, ops) -> BoolField $ AVColumn c ops) aubWhere
|
||||
)
|
||||
|
||||
_auCheck :: BoolExp
|
||||
@ -163,5 +163,5 @@ mkAnnotatedUpdate AnnotatedUpdateBuilder {..} = AnnotatedUpdateG {..}
|
||||
column :: [OpExpG PG (UnpreparedValue PG)] -> BoolExp
|
||||
column stuff =
|
||||
BoolAnd
|
||||
. fmap (\c -> BoolFld . AVColumn c $ stuff)
|
||||
. fmap (\c -> BoolField . AVColumn c $ stuff)
|
||||
$ aubColumns
|
||||
|
@ -115,7 +115,7 @@ mkParser table cib =
|
||||
columnInfos = mkColumnInfo <$> cib
|
||||
|
||||
upiFilter :: GBoolExp PG (AnnBoolExpFld PG (PartialSQLExp PG))
|
||||
upiFilter = BoolAnd $ fmap (\ci -> BoolFld $ AVColumn ci []) columnInfos
|
||||
upiFilter = BoolAnd $ fmap (\ci -> BoolField $ AVColumn ci []) columnInfos
|
||||
|
||||
------------------------------------------
|
||||
sourceInfo :: SourceInfo PG
|
||||
|
Loading…
Reference in New Issue
Block a user