mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
50 lines
1.6 KiB
Haskell
50 lines
1.6 KiB
Haskell
-- | Planning MySQL queries and subscriptions.
|
|
module Hasura.Backends.MySQL.Plan (planQuery) where
|
|
|
|
import Control.Monad.Validate
|
|
import Data.Aeson qualified as J
|
|
import Data.ByteString.Lazy (toStrict)
|
|
import Data.Text.Extended
|
|
import Hasura.Backends.MySQL.FromIr
|
|
import Hasura.Backends.MySQL.Types
|
|
import Hasura.Base.Error
|
|
import Hasura.GraphQL.Parser qualified as GraphQL
|
|
import Hasura.Prelude hiding (first)
|
|
import Hasura.RQL.IR
|
|
import Hasura.RQL.Types.Column qualified as RQL
|
|
import Hasura.SQL.Backend
|
|
import Hasura.Session
|
|
|
|
planQuery ::
|
|
MonadError QErr m =>
|
|
SessionVariables ->
|
|
QueryDB 'MySQL (Const Void) (GraphQL.UnpreparedValue 'MySQL) ->
|
|
m Select
|
|
planQuery sessionVariables queryDB = do
|
|
rootField <- traverse (prepareValueQuery sessionVariables) queryDB
|
|
sel <-
|
|
runValidate (runFromIr (fromRootField rootField))
|
|
`onLeft` (throw400 NotSupported . tshow)
|
|
pure $
|
|
sel
|
|
{ selectFor = NoFor
|
|
}
|
|
|
|
-- | Prepare a value without any query planning; we just execute the
|
|
-- query with the values embedded.
|
|
prepareValueQuery ::
|
|
MonadError QErr m =>
|
|
SessionVariables ->
|
|
GraphQL.UnpreparedValue 'MySQL ->
|
|
m Expression
|
|
prepareValueQuery sessionVariables =
|
|
\case
|
|
GraphQL.UVLiteral x -> pure x
|
|
GraphQL.UVSession -> pure $ ValueExpression $ BinaryValue $ toStrict $ J.encode sessionVariables
|
|
GraphQL.UVParameter _ RQL.ColumnValue {..} -> pure $ ValueExpression cvValue
|
|
GraphQL.UVSessionVar _typ sessionVariable -> do
|
|
value <-
|
|
getSessionVariableValue sessionVariable sessionVariables
|
|
`onNothing` throw400 NotFound ("missing session variable: " <>> sessionVariable)
|
|
pure $ ValueExpression $ TextValue value
|