mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
9ef603360c
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io> Co-authored-by: Vladimir Ciobanu <admin@cvlad.info> Co-authored-by: Antoine Leblanc <antoine@hasura.io> Co-authored-by: Stylish Haskell Bot <stylish-haskell@users.noreply.github.com> GitOrigin-RevId: 9d631878037637f3ed2994b5d0525efd978f7b8f
55 lines
1.8 KiB
Haskell
55 lines
1.8 KiB
Haskell
{-# LANGUAGE StrictData #-}
|
||
|
||
module Hasura.GraphQL.Parser.Column
|
||
( UnpreparedValue(..)
|
||
|
||
, Opaque
|
||
, mkOpaque
|
||
, openOpaque
|
||
, mkParameter
|
||
) where
|
||
|
||
import Hasura.Prelude
|
||
|
||
import Hasura.GraphQL.Parser.Class
|
||
import Hasura.GraphQL.Parser.Schema
|
||
import Hasura.RQL.Types.Backend
|
||
import Hasura.RQL.Types.Column hiding (EnumValue (..), EnumValueInfo (..))
|
||
import Hasura.SQL.Backend
|
||
import Hasura.Session (SessionVariable)
|
||
|
||
-- -------------------------------------------------------------------------------------------------
|
||
|
||
data Opaque a = Opaque
|
||
{ _opVariable :: Maybe VariableInfo
|
||
-- ^ The variable this value came from, if any.
|
||
, _opValue :: a
|
||
} -- Note: we intentionally don’t derive any instances here, since that would
|
||
-- defeat the opaqueness!
|
||
|
||
mkOpaque :: Maybe VariableInfo -> a -> Opaque a
|
||
mkOpaque = Opaque
|
||
|
||
openOpaque :: MonadParse m => Opaque a -> m a
|
||
openOpaque (Opaque Nothing value) = pure value
|
||
openOpaque (Opaque (Just _) value) = markNotReusable $> value
|
||
|
||
data UnpreparedValue (b :: BackendType)
|
||
-- | A SQL value that can be parameterized over.
|
||
= UVParameter
|
||
(Maybe VariableInfo)
|
||
-- ^ The GraphQL variable this value came from, if any.
|
||
(ColumnValue b)
|
||
-- | A literal SQL expression that /cannot/ be parameterized over.
|
||
| UVLiteral (SQLExpression b)
|
||
-- | The entire session variables JSON object.
|
||
| UVSession
|
||
-- | A single session variable.
|
||
| UVSessionVar (SessionVarType b) SessionVariable
|
||
|
||
-- FIXME exporting this method means doing away with the opaqueness of the
|
||
-- 'Opaque' data type, since the constructors of 'UnpreparedValue' are exported
|
||
-- globally.
|
||
mkParameter :: Opaque (ColumnValue b) -> UnpreparedValue b
|
||
mkParameter (Opaque variable value) = UVParameter variable value
|