graphql-engine/server/src-lib/Hasura/Backends/BigQuery/Plan.hs
Robert 11a454c2d6 server, pro: actually reformat the code-base using ormolu
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
2021-09-23 22:57:37 +00:00

69 lines
2.3 KiB
Haskell

-- | Planning T-SQL queries and subscriptions.
module Hasura.Backends.BigQuery.Plan
( planNoPlan,
)
where
import Control.Monad.Validate
import Data.Aeson.Text
import Data.Text.Extended
import Data.Text.Lazy qualified as LT
import Hasura.Backends.BigQuery.FromIr as BigQuery
import Hasura.Backends.BigQuery.Types
import Hasura.Base.Error qualified as E
import Hasura.GraphQL.Parser qualified as GraphQL
import Hasura.Prelude
import Hasura.RQL.IR
import Hasura.RQL.Types.Column qualified as RQL
import Hasura.SQL.Backend
import Hasura.SQL.Types
import Hasura.Session
--------------------------------------------------------------------------------
-- Top-level planner
planNoPlan ::
MonadError E.QErr m =>
FromIrConfig ->
UserInfo ->
QueryDB 'BigQuery (Const Void) (GraphQL.UnpreparedValue 'BigQuery) ->
m Select
planNoPlan fromIrConfig userInfo queryDB = do
rootField <- traverse (prepareValueNoPlan (_uiSession userInfo)) queryDB
runValidate (BigQuery.runFromIr fromIrConfig (BigQuery.fromRootField rootField))
`onLeft` (E.throw400 E.NotSupported . (tshow :: NonEmpty Error -> Text))
--------------------------------------------------------------------------------
-- Resolving values
-- | Prepare a value without any query planning; we just execute the
-- query with the values embedded.
prepareValueNoPlan ::
(MonadError E.QErr m) =>
SessionVariables ->
GraphQL.UnpreparedValue 'BigQuery ->
m Expression
prepareValueNoPlan sessionVariables =
\case
GraphQL.UVLiteral x -> pure x
GraphQL.UVSession -> pure globalSessionExpression
-- To be honest, I'm not sure if it's indeed the JSON_VALUE operator we need here...
GraphQL.UVSessionVar typ text ->
case typ of
CollectableTypeScalar scalarType ->
pure
( CastExpression
( JsonValueExpression
globalSessionExpression
(FieldPath RootPath (toTxt text))
)
scalarType
)
CollectableTypeArray {} ->
throwError $ E.internalError "Cannot currently prepare array types in BigQuery."
GraphQL.UVParameter _ RQL.ColumnValue {..} -> pure (ValueExpression cvValue)
where
globalSessionExpression =
ValueExpression
(StringValue (LT.toStrict (encodeToLazyText sessionVariables)))