Yeet some default-extensions

Manually enables:
* EmptyCase
* ExistentialQuantification
* QuantifiedConstraints
* QuasiQuotes
* TemplateHaskell
* TypeFamilyDependencies

...in the following components:
* 'graphql-engine' library
* 'graphql-engine' 'src-test'
* 'graphql-engine' 'tests/integration'
* 'graphql-engine' tests-hspec'

Additionally, performs some light refactoring and documentation.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3991
GitOrigin-RevId: 514477d3466b01f60eca8935d0fef60dd0756838
This commit is contained in:
jkachmar 2022-03-15 20:39:21 -04:00 committed by hasura-bot
parent c9e80cbfaf
commit 647231b685
182 changed files with 433 additions and 69 deletions

View File

@ -67,8 +67,6 @@ common common-all
DeriveLift
DeriveTraversable
DerivingVia
EmptyCase
ExistentialQuantification
FlexibleContexts
FlexibleInstances
FunctionalDependencies
@ -82,19 +80,15 @@ common common-all
NamedFieldPuns
NoImplicitPrelude
OverloadedStrings
QuantifiedConstraints
QuasiQuotes
RankNTypes
RecordWildCards
RoleAnnotations
ScopedTypeVariables
StandaloneDeriving
StrictData
TemplateHaskell
TupleSections
TypeApplications
TypeFamilies
TypeFamilyDependencies
TypeOperators
common common-exe

View File

@ -1,4 +1,7 @@
module Main (main) where
module Main
( main,
)
where
import Control.Concurrent.Extended qualified as C
import Control.Exception

View File

@ -1,3 +1,4 @@
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.Stateless

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Data.Text.NonEmpty
( NonEmptyText,
mkNonEmptyTextUnsafe,

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | A convenience wrapper around "GHC.Stats", which makes RTS stats available

View File

@ -1,3 +1,5 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.App

View File

@ -1,4 +1,5 @@
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.Backends.BigQuery.Connection
( BigQueryProblem,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- |
-- Working example:
--

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.BigQuery.Instances.Schema () where

View File

@ -1,4 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE NoGeneralisedNewtypeDeriving #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | MSSQL Connection

View File

@ -1,4 +1,10 @@
module Hasura.Backends.MSSQL.DDL.EventTrigger (createTableEventTrigger) where
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.Backends.MSSQL.DDL.EventTrigger
( createTableEventTrigger,
)
where
import Data.FileEmbed (makeRelativeToProject)
import Data.Text qualified as T

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-- | MSSQL DDL RunSQL

View File

@ -1,3 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- | MSSQL Source
--
-- Implements the Source related methods of the

View File

@ -1,3 +1,5 @@
{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.MSSQL.DDL.Source.Version
( latestSourceCatalogVersion,
setSourceCatalogVersion,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | MSSQL Instances Schema

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Metadata related types, functions and helpers.
--
-- Provides a single function which loads the MSSQL database metadata.

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
-- | MSSQL Schema IfMatched
--

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | MSSQL Types Instances

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.MySQL.Instances.Schema () where

View File

@ -1,4 +1,9 @@
module Hasura.Backends.MySQL.Meta (getMetadata) where
{-# LANGUAGE TemplateHaskell #-}
module Hasura.Backends.MySQL.Meta
( getMetadata,
)
where
import Control.Exception (throw)
import Data.ByteString.Char8 qualified as B8

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.Backends.MySQL.SQL
( runSQL,
RunSQL (..),

View File

@ -1,4 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Instances that're slow to compile.

View File

@ -1,3 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Postgres Connection MonadTx

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Postgres Connection Settings
@ -189,15 +190,24 @@ $(deriveFromJSON (aesonDrop 3 (fmap toLower)) ''PGClientCerts)
$(deriveToJSON (aesonDrop 3 (fmap toLower)) ''PGClientCerts)
instance Bifunctor PGClientCerts where
bimap f g pgCerts = g <$> pgCerts {pgcSslPassword = f <$> (pgcSslPassword pgCerts)}
bimap f g oldCerts@(PGClientCerts {pgcSslPassword}) =
let certs = oldCerts {pgcSslPassword = f <$> pgcSslPassword}
in g <$> certs
instance Bifoldable PGClientCerts where
bifoldMap f g PGClientCerts {..} =
fold $ fmap g [pgcSslCert, pgcSslKey, pgcSslRootCert] <> maybe [] (pure . f) pgcSslPassword
let gs = foldMap g [pgcSslCert, pgcSslKey, pgcSslRootCert]
fs = foldMap f pgcSslPassword
in gs <> fs
instance Bitraversable PGClientCerts where
bitraverse f g PGClientCerts {..} =
PGClientCerts <$> g pgcSslCert <*> g pgcSslKey <*> g pgcSslRootCert <*> pure pgcSslMode <*> traverse f pgcSslPassword
PGClientCerts
<$> g pgcSslCert
<*> g pgcSslKey
<*> g pgcSslRootCert
<*> pure pgcSslMode
<*> traverse f pgcSslPassword
instance (Cacheable p, Cacheable a) => Cacheable (PGClientCerts p a)

View File

@ -1,3 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres DDL EventTrigger
--
-- Used for creating event triggers for metadata changes.

View File

@ -1,3 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres DDL RunSQL
--
-- Escape hatch for running raw SQL against a postgres database.

View File

@ -1,3 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres DDL Source
--
-- A Source is a connected database. One can have multiple sources of the same

View File

@ -1,3 +1,5 @@
{-# LANGUAGE QuasiQuotes #-}
-- | Postgres DDL Source Version
--
-- Deals with catalog version - used by 'Hasura.Backends.Postgres.DDL.Source'.

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres Execute LiveQuery
--
-- Multiplex is an optimization which allows us to group similar queries into a

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres SQL Error
--
-- Functions and datatypes for interpreting Postgres errors.

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres SQL Types
--
-- Combinators and helpers for dealing with Postgres types such as strings, numerals,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres Schema OnConflict
--

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Postgres Types CitusExtraTableMetadata
--
-- Additional metadata information for Citus tables.

View File

@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | This module defines all missing instances of third party libraries.

View File

@ -1,4 +1,5 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}
-- |
-- = Event Triggers

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- |
-- = Hasura.Eventing.HTTP
--

View File

@ -1,4 +1,5 @@
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE QuasiQuotes #-}
-- |
-- = Scheduled Triggers

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.Eventing.ScheduledTrigger.Types
( CronTriggerStats (CronTriggerStats, ctsMaxScheduledTime, ctsName),
RetryContext (RetryContext, _rctxConf),

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Analyse
( Analysis (..),
FieldAnalysis (..),

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Context
( RoleContext (..),
GQLContext (..),

View File

@ -1,3 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Execute.Action
( fetchActionLogResponses,
runActionExecution,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Execute.Action.Types
( ActionContext (..),
ActionExecution (..),

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | This module implements /fragment inlining/, which converts all fragment
-- spreads in a GraphQL query to inline fragments. For example, given a query like
--

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
-- |

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Multiplexed live query poller threads; see "Hasura.GraphQL.Execute.LiveQuery" for details.
module Hasura.GraphQL.Execute.LiveQuery.Poll
( -- * Pollers

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Top-level management of live query poller threads. The implementation of the polling itself is
-- in "Hasura.GraphQL.Execute.LiveQuery.Poll". See "Hasura.GraphQL.Execute.LiveQuery" for high-level
-- details.

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Execute.RemoteJoin.Collect
( getRemoteJoinsQueryDB,
getRemoteJoinsMutationDB,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Explain
( explainGQLQuery,
GQLExplain,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Definition of all supported GraphQL directives.
module Hasura.GraphQL.Parser.Directives
( -- list of directives, for the schema

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_HADDOCK not-home #-}
-- | Defines the 'Parser' type and its primitive combinators.

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | This module defines all backend-agnostic scalars we use throughout the
-- schema. This includes GraphQL scalars, and several other custom ones.
module Hasura.GraphQL.Parser.Internal.Scalars

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.RemoteServer
( fetchRemoteSchema,
getSchemaIntrospection,

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module Hasura.GraphQL.Schema

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.Action
( actionExecute,
actionAsyncMutation,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.BoolExp
( boolExp,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | This module provides building blocks for the GraphQL Schema that the
-- GraphQL Engine presents.
--

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.Common
( MonadBuildSchemaBase,
AggSelectExp,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.Introspect
( buildIntrospectionSchema,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.Mutation
( insertIntoTable,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.OrderBy
( orderByExp,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module Hasura.GraphQL.Schema.Remote

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Schema.RemoteRelationship
( remoteRelationshipField,
)

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-- | Generate table selection schema both for ordinary Hasura-type and

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Helper functions for generating the schema of database tables
module Hasura.GraphQL.Schema.Table
( getTableGQLName,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskell #-}
-- | This module provides common building blocks for composing Schema Parsers
-- used in the schema of Update Mutations.

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Transport.HTTP.Protocol
( GQLReq (..),
GQLBatchedReqs (..),

View File

@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
-- | This file contains the handlers that are used within websocket server.
--

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | This file contains types for both the websocket protocols (Apollo) and (graphql-ws)
-- | See Apollo: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
-- | See graphql-ws: https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md

View File

@ -1,4 +1,5 @@
{-# LANGUAGE NondecreasingIndentation #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.GraphQL.Transport.WebSocket.Server
( AcceptWith (AcceptWith),
@ -208,13 +209,6 @@ createWSServer logger = do
serverStatus <- STM.newTVar (AcceptingConns connMap)
return $ WSServer logger serverStatus
-- -- UNUSED
-- closeAll :: WSServer a -> BL.ByteString -> IO ()
-- closeAll (WSServer (L.Logger writeLog) serverStatus) msg = do
-- writeLog $ L.debugT "closing all connections"
-- conns <- STM.atomically $ flushConnMap serverStatus
-- closeAllWith (flip closeConn) msg conns
closeAllWith ::
(BL.ByteString -> WSConn a -> IO ()) ->
BL.ByteString ->

View File

@ -1,3 +1,4 @@
{-# LANGUAGE EmptyCase #-}
{-# OPTIONS_HADDOCK not-home #-}
-- | Supporting functionality for fine-grained dependency tracking.

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.Logging
@ -191,7 +192,9 @@ deriving instance Show (EngineLogType impl) => Show (EngineLog impl)
deriving instance Eq (EngineLogType impl) => Eq (EngineLog impl)
-- empty splice to bring all the above definitions in scope
-- Empty splice to bring all the above definitions in scope.
--
-- TODO: Restructure the code so that we can avoid this.
$(pure [])
instance J.ToJSON (EngineLogType impl) => J.ToJSON (EngineLog impl) where

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.DDL.Action
( CreateAction (..),
runCreateAction,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.DDL.EventTrigger
( CreateEventTriggerQuery,
runCreateEventTriggerQuery,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Types related to metadata management API
module Hasura.RQL.DDL.Metadata.Types
( currentMetadataVersion,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TypeFamilyDependencies #-}
module Hasura.RQL.DDL.Permission
( CreatePerm,
runCreatePerm,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.DDL.QueryTags
( SetQueryTagsConfig,
runSetQueryTagsConfig,

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.RQL.DDL.RemoteRelationship

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-- | Validate input queries against remote schemas.

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- |
-- = Remote Schema Permissions Validation
--

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | This module (along with the various @Hasura.RQL.DDL.Schema.*@ modules) provides operations to
-- load and modify the Hasura catalog and schema cache.
--
@ -26,7 +28,7 @@ module Hasura.RQL.DDL.Schema
where
import Data.Aeson
import Data.Aeson.TH
import Data.Aeson.TH (deriveJSON)
import Data.Text.Encoding qualified as TE
import Database.PG.Query qualified as Q
import Database.PostgreSQL.LibPQ qualified as PQ

View File

@ -1,4 +1,5 @@
{-# LANGUAGE Arrows #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
-- | Types/functions shared between modules that implement "Hasura.RQL.DDL.Schema.Cache". Other

View File

@ -1,3 +1,5 @@
{-# LANGUAGE QuasiQuotes #-}
-- | Functions for fetching and updating @'Metadata' in the catalog.
module Hasura.RQL.DDL.Schema.Catalog
( fetchMetadataFromCatalog,

View File

@ -1,3 +1,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Funtions related to @hdb_catalog@ schema prior to metadata separation (catalog version < 43).
module Hasura.RQL.DDL.Schema.LegacyCatalog
( saveMetadataToHdbTables,

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.DDL.Schema.Source
( AddSource,
DropSource,

View File

@ -1,4 +1,5 @@
{-# LANGUAGE Arrows #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Description: Create/delete SQL tables to/from Hasura metadata.
module Hasura.RQL.DDL.Schema.Table

View File

@ -203,6 +203,10 @@ instance ToJSON RequestTransformFn where
-- TODO(SOLOMON): Add lens law unit tests
-- | A lens for mapping from an actual 'HTTP.Request' term to our HKD.
--
-- XXX: This function makes internal usage of 'TE.decodeUtf8', which throws an
-- impure exception when the supplied 'ByteString' cannot be decoded into valid
-- UTF8 text!
request :: Lens' HTTP.Request RequestData
request = lens getter setter
where
@ -346,6 +350,10 @@ buildRespTransformCtx reqCtx sessionVars engine respBody =
_ -> Left $ Kriti.CustomFunctionError "Session variable name should be a string"
-- | Construct a Template Transformation function for Responses
--
-- XXX: This function makes internal usage of 'TE.decodeUtf8', which throws an
-- impure exception when the supplied 'ByteString' cannot be decoded into valid
-- UTF8 text!
mkRespTemplateTransform :: TemplatingEngine -> BodyTransformAction -> ResponseTransformCtx -> Either TransformErrorBundle J.Value
mkRespTemplateTransform _ RemoveBody _ = pure J.Null
mkRespTemplateTransform engine (ModifyBody (Template template)) ResponseTransformCtx {..} =

View File

@ -49,7 +49,6 @@ import Data.ByteString.Builder.Scientific (scientificBuilder)
import Data.ByteString.Lazy qualified as LBS
import Data.HashMap.Strict qualified as M
import Data.Kind (Constraint, Type)
import Data.Text qualified as T
import Data.Text.Encoding (encodeUtf8)
import Data.Text.Encoding qualified as TE
import Data.Validation (Validation, fromEither)
@ -129,7 +128,7 @@ data RequestTransformCtx = RequestTransformCtx
rtcSessionVariables :: J.Value,
rtcQueryParams :: Maybe J.Value,
rtcEngine :: TemplatingEngine,
rtcFunctions :: M.HashMap T.Text (J.Value -> Either Kriti.CustomFunctionError J.Value)
rtcFunctions :: M.HashMap Text (J.Value -> Either Kriti.CustomFunctionError J.Value)
}
instance ToJSON RequestTransformCtx where
@ -145,16 +144,36 @@ instance ToJSON RequestTransformCtx where
in J.object (required <> catMaybes optional)
-- | A smart constructor for constructing the 'RequestTransformCtx'
mkReqTransformCtx :: T.Text -> Maybe SessionVariables -> TemplatingEngine -> HTTP.Request -> RequestTransformCtx
mkReqTransformCtx url sessionVars engine reqData =
--
-- XXX: This function makes internal usage of 'TE.decodeUtf8', which throws an
-- impure exception when the supplied 'ByteString' cannot be decoded into valid
-- UTF8 text!
mkReqTransformCtx ::
Text ->
Maybe SessionVariables ->
TemplatingEngine ->
HTTP.Request ->
RequestTransformCtx
{ rtcBaseUrl = Just $ J.toJSON url,
rtcBody = fromMaybe J.Null $ J.decode @J.Value =<< view HTTP.body reqData,
rtcSessionVariables = J.toJSON sessionVars,
rtcQueryParams = Just $ J.toJSON $ bimap TE.decodeUtf8 (fmap TE.decodeUtf8) <$> view HTTP.queryParams reqData,
rtcEngine = engine,
mkReqTransformCtx url sessionVars rtcEngine reqData =
let rtcBaseUrl = Just $ J.toJSON url
rtcBody =
let mBody = view HTTP.body reqData >>= J.decode @J.Value
in fromMaybe J.Null mBody
rtcSessionVariables = J.toJSON sessionVars
rtcQueryParams =
let queryParams =
view HTTP.queryParams reqData & fmap \(key, val) ->
(TE.decodeUtf8 key, fmap TE.decodeUtf8 val)
in Just $ J.toJSON queryParams
rtcFunctions = M.singleton "getSessionVariable" getSessionVar
}
in RequestTransformCtx
{ rtcBaseUrl,
rtcBody,
rtcSessionVariables,
rtcQueryParams,
rtcEngine,
rtcFunctions
}
where
getSessionVar :: J.Value -> Either Kriti.CustomFunctionError J.Value
getSessionVar inp = case inp of
@ -170,7 +189,7 @@ mkReqTransformCtx url sessionVars engine reqData =
data ResponseTransformCtx = ResponseTransformCtx
{ responseTransformBody :: J.Value,
responseTransformReqCtx :: J.Value,
responseTransformFunctions :: M.HashMap T.Text (J.Value -> Either Kriti.CustomFunctionError J.Value),
responseTransformFunctions :: M.HashMap Text (J.Value -> Either Kriti.CustomFunctionError J.Value),
responseTransformEngine :: TemplatingEngine
}

View File

@ -60,8 +60,6 @@ instance Transform Headers where
transform (HeadersTransform transformation) context (Headers originalHeaders) =
case transformation of
ReplaceHeaders ReplaceHeaderFields {rhf_addHeaders, rhf_removeHeaders} -> do
-- NOTE: 'TE.decodeUtf8' can fail with an impure exception; conversion
-- to bytes is infallible.
let removeHeadersBytes = fmap (CI.map TE.encodeUtf8) rhf_removeHeaders
filteredHeaders =
originalHeaders & filter \(key, _val) ->

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.DML.Types
( OrderByExp (..),
DMLQuery (..),

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.IR.Action
( ActionFieldG (..),
ActionFieldsG,

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.RQL.IR.BoolExp

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.RQL.IR.Delete

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Internal representation of an insertion in a database table.
--
-- What makes this specific mutation tricky is that we support recursive

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Representation for queries going to remote schemas. Due to the existence of
-- remote relationships from remote schemas, we can't simply reuse the GraphQL
-- document AST we define in graphql-parser-hs, and instead redefine a custom

View File

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasura.RQL.IR.Returning

View File

@ -1,4 +1,5 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
-- | This modules defines the tree of Select types: how we represent a query internally, from its top

View File

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.IR.Update
( AnnotatedUpdate,
AnnotatedUpdateG (..),

Some files were not shown because too many files have changed in this diff Show More