{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
module Hasura.RQL.Types.Backend
( Backend (..),
SessionVarType,
XDisable,
XEnable,
ComputedFieldReturnType (..),
_ReturnsTable,
SupportedNamingCase (..),
HasSourceConfiguration (..),
Representable,
)
where
import Autodocodec (HasCodec (..))
import Autodocodec.DerivingVia ()
import Autodocodec.OpenAPI ()
import Control.Lens.TH (makePrisms)
import Data.Aeson.Extended
import Data.Environment qualified as Env
import Data.Kind (Type)
import Data.Text.Casing (GQLNameIdentifier)
import Data.Text.Extended
import Data.Typeable (Typeable)
import Hasura.Backends.Postgres.Connection.Settings (ConnectionTemplate (..))
import Hasura.Base.Error
import Hasura.Base.ToErrorValue
import Hasura.EncJSON (EncJSON)
import Hasura.Prelude
import Hasura.RQL.Types.BackendTag
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.HealthCheckImplementation (HealthCheckImplementation)
import Hasura.RQL.Types.ResizePool (ServerReplicas, SourceResizePoolSummary)
import Hasura.RQL.Types.SourceConfiguration
import Hasura.SQL.Types
import Language.GraphQL.Draft.Syntax qualified as G
type SessionVarType b = CollectableType (ScalarType b)
data ComputedFieldReturnType (b :: BackendType)
= ReturnsScalar (ScalarType b)
| ReturnsTable (TableName b)
| ReturnsOthers
type XEnable = ()
type XDisable = Void
data SupportedNamingCase = OnlyHasuraCase | AllConventions
class
( HasSourceConfiguration b,
Representable (BasicOrderType b),
Representable (Column b),
Representable (ComputedFieldDefinition b),
Representable (ComputedFieldImplicitArguments b),
Representable (ComputedFieldReturn b),
Representable (ConstraintName b),
Representable (ExtraTableMetadata b),
Representable (FunctionArgument b),
Representable (FunctionName b),
Representable (FunctionReturnType b),
Representable (HealthCheckTest b),
Representable (NullsOrderType b),
Representable (SQLExpression b),
Representable (ScalarSelectionArguments b),
Representable (ScalarType b),
Representable (XComputedField b),
Representable (XGroupBy b),
Representable (TableName b),
Eq (RawFunctionInfo b),
Show (RawFunctionInfo b),
Representable (ResolvedConnectionTemplate b),
Ord (TableName b),
Ord (FunctionName b),
Ord (ScalarType b),
Ord (Column b),
Ord (ComputedFieldReturn b),
Ord (ComputedFieldImplicitArguments b),
Ord (ConstraintName b),
Ord (FunctionArgument b),
Ord (XComputedField b),
Data (TableName b),
FromJSON (BackendConfig b),
FromJSON (Column b),
FromJSON (ComputedFieldDefinition b),
FromJSON (ConnectionTemplateRequestContext b),
FromJSON (ConstraintName b),
FromJSON (ExtraTableMetadata b),
FromJSON (FunctionName b),
FromJSON (FunctionReturnType b),
FromJSON (HealthCheckTest b),
FromJSON (RawFunctionInfo b),
FromJSON (ScalarType b),
FromJSON (TableName b),
FromJSONKey (Column b),
FromJSONKey (ConstraintName b),
HasCodec (BackendConfig b),
HasCodec (BackendSourceKind b),
HasCodec (Column b),
HasCodec (ComputedFieldDefinition b),
HasCodec (FunctionName b),
HasCodec (FunctionReturnType b),
HasCodec (ScalarType b),
HasCodec (TableName b),
ToJSON (BackendConfig b),
ToJSON (Column b),
ToJSON (ConstraintName b),
ToJSON (ExecutionStatistics b),
ToJSON (FunctionArgument b),
ToJSON (FunctionName b),
ToJSON (FunctionReturnType b),
ToJSON (RawFunctionInfo b),
ToJSON (ScalarType b),
ToJSON (TableName b),
ToJSON (ExtraTableMetadata b),
ToJSON (SQLExpression b),
ToJSON (ComputedFieldDefinition b),
ToJSON (ComputedFieldImplicitArguments b),
ToJSON (ComputedFieldReturn b),
ToJSON (HealthCheckTest b),
ToJSON (ResolvedConnectionTemplate b),
ToJSONKey (Column b),
ToJSONKey (ConstraintName b),
ToJSONKey (ScalarType b),
ToTxt (Column b),
ToTxt (FunctionName b),
ToTxt (ScalarType b),
ToTxt (TableName b),
ToTxt (ConstraintName b),
ToErrorValue (Column b),
ToErrorValue (TableName b),
Typeable (Column b),
Typeable b,
HasTag b,
Traversable (CountType b),
Traversable (FunctionArgumentExp b),
Eq (BackendConfig b),
Show (BackendConfig b),
Eq (BackendInfo b),
Show (BackendInfo b),
Monoid (BackendInfo b),
Eq (ScalarValue b),
Show (ScalarValue b),
Eq (XNodesAgg b),
Show (XNodesAgg b),
Eq (XRelay b),
Show (XRelay b),
Eq (XStreamingSubscription b),
Show (XStreamingSubscription b),
Eq (XNestedObjects b),
Ord (XNestedObjects b),
Show (XNestedObjects b),
NFData (XNestedObjects b),
Hashable (XNestedObjects b),
ToJSON (XNestedObjects b),
FromJSON (XNestedObjects b),
ToTxt (XNestedObjects b),
Traversable (BooleanOperators b),
Traversable (UpdateVariant b),
Traversable (BackendInsert b),
Traversable (AggregationPredicates b)
) =>
Backend (b :: BackendType)
where
type BackendConfig b :: Type
type BackendInfo b :: Type
type TableName b :: Type
type FunctionName b :: Type
type FunctionReturnType b :: Type
type FunctionReturnType b = XDisable
type RawFunctionInfo b :: Type
type ConstraintName b :: Type
type BasicOrderType b :: Type
type NullsOrderType b :: Type
type CountType b :: Type -> Type
type Column b :: Type
type ScalarValue b :: Type
type ScalarType b :: Type
type SQLExpression b :: Type
type ComputedFieldDefinition b :: Type
type ScalarSelectionArguments b :: Type
type b :: Type
type FunctionArgument b :: Type
type FunctionArgumentExp b :: Type -> Type
type ComputedFieldImplicitArguments b :: Type
type ComputedFieldReturn b :: Type
type HealthCheckTest b :: Type
healthCheckImplementation :: Maybe (HealthCheckImplementation (HealthCheckTest b))
healthCheckImplementation = Maybe (HealthCheckImplementation (HealthCheckTest b))
forall a. Maybe a
Nothing
versionCheckImplementation :: Env.Environment -> SourceConnConfiguration b -> IO (Either QErr ())
versionCheckImplementation = (SourceConnConfiguration b -> IO (Either QErr ()))
-> Environment -> SourceConnConfiguration b -> IO (Either QErr ())
forall a b. a -> b -> a
const (IO (Either QErr ())
-> SourceConnConfiguration b -> IO (Either QErr ())
forall a b. a -> b -> a
const (Either QErr () -> IO (Either QErr ())
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either QErr () -> IO (Either QErr ()))
-> Either QErr () -> IO (Either QErr ())
forall a b. (a -> b) -> a -> b
$ () -> Either QErr ()
forall a b. b -> Either a b
Right ()))
runPingSource :: Env.Environment -> (String -> IO ()) -> SourceName -> SourceConnConfiguration b -> IO ()
runPingSource Environment
_ String -> IO ()
_ SourceName
_ SourceConnConfiguration b
_ = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
type BooleanOperators b :: Type -> Type
type AggregationPredicates b :: Type -> Type
type AggregationPredicates b = Const Void
type UpdateVariant b :: Type -> Type
type UpdateVariant b = Const Void
type BackendInsert b :: Type -> Type
type BackendInsert b = Const Void
type XComputedField b :: Type
type XRelay b :: Type
type XNodesAgg b :: Type
type XEventTriggers b :: Type
type XNestedInserts b :: Type
type XStreamingSubscription b :: Type
type XNestedObjects b :: Type
type XNestedObjects b = XDisable
type XGroupBy b :: Type
type XGroupBy b = XDisable
type ResolvedConnectionTemplate b :: Type
type ResolvedConnectionTemplate b = ()
type ConnectionTemplateRequestContext b :: Type
type ConnectionTemplateRequestContext b = ()
resolveConnectionTemplate :: SourceConfig b -> ConnectionTemplateRequestContext b -> Maybe ConnectionTemplate -> Either QErr EncJSON
resolveConnectionTemplate SourceConfig b
_ ConnectionTemplateRequestContext b
_ Maybe ConnectionTemplate
_ = QErr -> Either QErr EncJSON
forall a b. a -> Either a b
Left (Code -> Text -> QErr
err400 (Code
NotSupported) Text
"connection template is not implemented")
type ExecutionStatistics b :: Type
type ExecutionStatistics b = ()
isComparableType :: ScalarType b -> Bool
isNumType :: ScalarType b -> Bool
getCustomAggregateOperators :: SourceConfig b -> HashMap G.Name (HashMap (ScalarType b) (ScalarType b))
getCustomAggregateOperators = HashMap Name (HashMap (ScalarType b) (ScalarType b))
-> SourceConfig b
-> HashMap Name (HashMap (ScalarType b) (ScalarType b))
forall a b. a -> b -> a
const HashMap Name (HashMap (ScalarType b) (ScalarType b))
forall a. Monoid a => a
mempty
textToScalarValue :: Maybe Text -> ScalarValue b
parseScalarValue :: ScalarTypeParsingContext b -> ScalarType b -> Value -> Either QErr (ScalarValue b)
scalarValueToJSON :: ScalarValue b -> Value
functionToTable :: FunctionName b -> TableName b
tableToFunction :: TableName b -> FunctionName b
computedFieldFunction :: ComputedFieldDefinition b -> FunctionName b
computedFieldReturnType :: ComputedFieldReturn b -> ComputedFieldReturnType b
supportsAggregateComputedFields :: Bool
supportsAggregateComputedFields = Bool
False
fromComputedFieldImplicitArguments :: v -> ComputedFieldImplicitArguments b -> [FunctionArgumentExp b v]
tableGraphQLName :: TableName b -> Either QErr G.Name
functionGraphQLName :: FunctionName b -> Either QErr G.Name
getTableIdentifier :: TableName b -> Either QErr GQLNameIdentifier
snakeCaseTableName :: TableName b -> Text
namingConventionSupport :: SupportedNamingCase
resizeSourcePools :: SourceConfig b -> ServerReplicas -> IO SourceResizePoolSummary
defaultTriggerOnReplication :: Maybe (XEventTriggers b, TriggerOnReplication)
backendSupportsNestedObjects :: Either QErr (XNestedObjects b)
default backendSupportsNestedObjects :: (XNestedObjects b ~ XDisable) => Either QErr (XNestedObjects b)
backendSupportsNestedObjects = Code -> Text -> Either QErr XDisable
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
InvalidConfiguration Text
"Nested objects not supported"
sourceSupportsSchemalessTables :: SourceConfig b -> Bool
sourceSupportsSchemalessTables = Bool -> SourceConfig b -> Bool
forall a b. a -> b -> a
const Bool
False
$(makePrisms ''ComputedFieldReturnType)