mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-20 22:11:45 +03:00
7228d0327f
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6849 GitOrigin-RevId: 0ab90aaf281cc1c043f73fd6d63c4c18d58c7c92
122 lines
4.8 KiB
Haskell
122 lines
4.8 KiB
Haskell
{-# LANGUAGE OverloadedLists #-}
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
module Hasura.Backends.DataConnector.API.V0.CapabilitiesSpec (spec) where
|
|
|
|
import Data.Aeson.QQ.Simple (aesonQQ)
|
|
import Data.HashMap.Strict qualified as HashMap
|
|
import Hasura.Backends.DataConnector.API.V0.Capabilities
|
|
import Hasura.Backends.DataConnector.API.V0.ConfigSchema
|
|
import Hasura.Backends.DataConnector.API.V0.Scalar (ScalarType (..))
|
|
import Hasura.Backends.DataConnector.API.V0.ScalarSpec (genScalarType)
|
|
import Hasura.Generator.Common
|
|
import Hasura.Prelude
|
|
import Hedgehog
|
|
import Hedgehog.Gen qualified as Gen
|
|
import Language.GraphQL.Draft.Syntax.QQ qualified as G
|
|
import Test.Aeson.Utils
|
|
import Test.Hspec
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "Capabilities" $ do
|
|
testToFromJSONToSchema defaultCapabilities [aesonQQ|{}|]
|
|
jsonOpenApiProperties genCapabilities
|
|
describe "CapabilitiesResponse" $ do
|
|
testToFromJSON
|
|
(CapabilitiesResponse (defaultCapabilities {_cRelationships = Just RelationshipCapabilities {}}) emptyConfigSchemaResponse Nothing Nothing)
|
|
[aesonQQ|{"capabilities": {"relationships": {}}, "config_schemas": {"config_schema": {}, "other_schemas": {}}}|]
|
|
describe "ScalarTypesCapabilities" $ do
|
|
testToFromJSONToSchema (ScalarTypesCapabilities (HashMap.singleton StringTy (ScalarTypeCapabilities mempty mempty))) [aesonQQ|{"string": {}}|]
|
|
jsonOpenApiProperties genScalarTypesCapabilities
|
|
describe "ScalarTypeCapabilities" $ do
|
|
let comparisonOperators = ComparisonOperators $ HashMap.fromList [([G.name|same_day_as|], CustomTy "DateTime")]
|
|
let aggregateFunctions = AggregateFunctions $ HashMap.fromList [([G.name|max|], CustomTy "DateTime")]
|
|
let json =
|
|
[aesonQQ|{
|
|
"comparison_operators": {
|
|
"same_day_as": "DateTime"
|
|
},
|
|
"aggregate_functions": {
|
|
"max": "DateTime"
|
|
}
|
|
}|]
|
|
testToFromJSONToSchema (ScalarTypeCapabilities comparisonOperators aggregateFunctions) json
|
|
|
|
genDataSchemaCapabilities :: MonadGen m => m DataSchemaCapabilities
|
|
genDataSchemaCapabilities =
|
|
DataSchemaCapabilities
|
|
<$> Gen.bool
|
|
<*> Gen.bool
|
|
<*> genColumnNullability
|
|
|
|
genColumnNullability :: MonadGen m => m ColumnNullability
|
|
genColumnNullability =
|
|
Gen.element [NullableAndNonNullableColumns, OnlyNullableColumns]
|
|
|
|
genQueryCapabilities :: MonadGen m => m QueryCapabilities
|
|
genQueryCapabilities = pure QueryCapabilities
|
|
|
|
genMutationCapabilities :: MonadGen m => m MutationCapabilities
|
|
genMutationCapabilities = pure MutationCapabilities {}
|
|
|
|
genSubscriptionCapabilities :: MonadGen m => m SubscriptionCapabilities
|
|
genSubscriptionCapabilities = pure SubscriptionCapabilities {}
|
|
|
|
genComparisonOperators :: (MonadGen m, GenBase m ~ Identity) => m ComparisonOperators
|
|
genComparisonOperators =
|
|
ComparisonOperators <$> genHashMap (genGName defaultRange) genScalarType defaultRange
|
|
|
|
genAggregateFunctions :: (MonadGen m, GenBase m ~ Identity) => m AggregateFunctions
|
|
genAggregateFunctions =
|
|
AggregateFunctions <$> genHashMap (genGName defaultRange) genScalarType defaultRange
|
|
|
|
genScalarTypeCapabilities :: (MonadGen m, GenBase m ~ Identity) => m ScalarTypeCapabilities
|
|
genScalarTypeCapabilities =
|
|
ScalarTypeCapabilities
|
|
<$> genComparisonOperators
|
|
<*> genAggregateFunctions
|
|
|
|
genScalarTypesCapabilities :: (MonadGen m, GenBase m ~ Identity) => m ScalarTypesCapabilities
|
|
genScalarTypesCapabilities =
|
|
ScalarTypesCapabilities <$> genHashMap genScalarType genScalarTypeCapabilities defaultRange
|
|
|
|
genRelationshipCapabilities :: MonadGen m => m RelationshipCapabilities
|
|
genRelationshipCapabilities = pure RelationshipCapabilities {}
|
|
|
|
genComparisonCapabilities :: MonadGen m => m ComparisonCapabilities
|
|
genComparisonCapabilities =
|
|
ComparisonCapabilities
|
|
<$> Gen.maybe genSubqueryComparisonCapabilities
|
|
|
|
genSubqueryComparisonCapabilities :: MonadGen m => m SubqueryComparisonCapabilities
|
|
genSubqueryComparisonCapabilities =
|
|
SubqueryComparisonCapabilities
|
|
<$> Gen.bool
|
|
|
|
genMetricsCapabilities :: MonadGen m => m MetricsCapabilities
|
|
genMetricsCapabilities = pure MetricsCapabilities {}
|
|
|
|
genExplainCapabilities :: MonadGen m => m ExplainCapabilities
|
|
genExplainCapabilities = pure ExplainCapabilities {}
|
|
|
|
genRawCapabilities :: MonadGen m => m RawCapabilities
|
|
genRawCapabilities = pure RawCapabilities {}
|
|
|
|
genCapabilities :: Gen Capabilities
|
|
genCapabilities =
|
|
Capabilities
|
|
<$> genDataSchemaCapabilities
|
|
<*> Gen.maybe genQueryCapabilities
|
|
<*> Gen.maybe genMutationCapabilities
|
|
<*> Gen.maybe genSubscriptionCapabilities
|
|
<*> genScalarTypesCapabilities
|
|
<*> Gen.maybe genRelationshipCapabilities
|
|
<*> Gen.maybe genComparisonCapabilities
|
|
<*> Gen.maybe genMetricsCapabilities
|
|
<*> Gen.maybe genExplainCapabilities
|
|
<*> Gen.maybe genRawCapabilities
|
|
|
|
emptyConfigSchemaResponse :: ConfigSchemaResponse
|
|
emptyConfigSchemaResponse = ConfigSchemaResponse mempty mempty
|