mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
af0b56332d
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8723 GitOrigin-RevId: 5df1a05c47852d7371ef323bb0df2ac9d1749243
66 lines
1.8 KiB
Haskell
66 lines
1.8 KiB
Haskell
{-# LANGUAGE UndecidableInstances #-}
|
|
|
|
module Hasura.RQL.IR.Value
|
|
( UnpreparedValue (..),
|
|
Provenance (..),
|
|
ValueWithOrigin (..),
|
|
openValueOrigin,
|
|
mkParameter,
|
|
)
|
|
where
|
|
|
|
import Hasura.GraphQL.Parser.Variable
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Backend
|
|
import Hasura.RQL.Types.Column
|
|
import Hasura.SQL.Backend
|
|
import Hasura.Session (SessionVariable)
|
|
|
|
-- | Where did this variable come from?
|
|
data Provenance
|
|
= -- | We don't know / it isn't important
|
|
Unknown
|
|
| -- | A GraphQL variable (e.g. a query parameter)
|
|
FromGraphQL VariableInfo
|
|
| -- | An internal source (e.g. a logical model argument)
|
|
FromInternal Text
|
|
deriving stock (Eq, Show)
|
|
|
|
data UnpreparedValue (b :: BackendType)
|
|
= -- | A SQL value that can be parameterized over.
|
|
UVParameter Provenance (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
|
|
|
|
deriving instance
|
|
( Backend b,
|
|
Eq (ColumnValue b)
|
|
) =>
|
|
Eq (UnpreparedValue b)
|
|
|
|
deriving instance
|
|
( Backend b,
|
|
Show (ColumnValue b)
|
|
) =>
|
|
Show (UnpreparedValue b)
|
|
|
|
-- | This indicates whether a variable value came from a certain GraphQL variable
|
|
data ValueWithOrigin a
|
|
= ValueWithOrigin VariableInfo a
|
|
| ValueNoOrigin a
|
|
deriving (Functor)
|
|
|
|
openValueOrigin :: ValueWithOrigin a -> a
|
|
openValueOrigin (ValueWithOrigin _ a) = a
|
|
openValueOrigin (ValueNoOrigin a) = a
|
|
|
|
mkParameter :: ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
|
|
mkParameter (ValueWithOrigin valInfo columnValue) =
|
|
UVParameter (FromGraphQL valInfo) columnValue
|
|
mkParameter (ValueNoOrigin columnValue) =
|
|
UVParameter Unknown columnValue
|