mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
server/postgres: fix the schema types conflict between aggregation predicates and table selection aggregates
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6452 GitOrigin-RevId: ed43442c7ade298659bdc42ff76e8e229825f0f1
This commit is contained in:
parent
ac4b15c07b
commit
9c3bd2f0d0
@ -130,6 +130,7 @@ executable api-tests
|
||||
Test.Queries.SortSpec
|
||||
Test.Queries.VariablesSpec
|
||||
Test.Quoter.YamlSpec
|
||||
Test.Regression.AggregateBoolExpConflictSpec
|
||||
Test.Regression.ArrayLiteralTextEncodingSpec
|
||||
Test.Regression.DoNotTruncateSessionVariables8158Spec
|
||||
Test.Regression.DropColumnWithPermissions8415Spec
|
||||
|
@ -0,0 +1,93 @@
|
||||
-- | Test the schema names conflict of bool exp aggregates and table selection aggregates
|
||||
module Test.Regression.AggregateBoolExpConflictSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
import Hasura.Prelude
|
||||
import Test.Hspec (SpecWith, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Fixture.run
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Schema
|
||||
|
||||
schema :: [Schema.Table]
|
||||
schema =
|
||||
[ (table "author")
|
||||
{ tableColumns =
|
||||
[ Schema.column "id" Schema.defaultSerialType,
|
||||
Schema.column "name" Schema.TStr
|
||||
],
|
||||
tablePrimaryKey = ["id"]
|
||||
},
|
||||
(table "user")
|
||||
{ tableColumns =
|
||||
[ Schema.column "id" Schema.defaultSerialType,
|
||||
Schema.column "name" Schema.TStr
|
||||
],
|
||||
tablePrimaryKey = ["id"]
|
||||
},
|
||||
(table "article")
|
||||
{ tableColumns =
|
||||
[ Schema.column "id" Schema.defaultSerialType,
|
||||
Schema.column "title" Schema.TStr,
|
||||
Schema.column "content" Schema.TStr,
|
||||
Schema.column "published_on" Schema.TStr,
|
||||
Schema.column "author_id" serialInt,
|
||||
Schema.column "user_id" serialInt
|
||||
],
|
||||
tablePrimaryKey = ["id"],
|
||||
tableReferences =
|
||||
[ Schema.Reference "author_id" "author" "id",
|
||||
Schema.Reference "user_id" "user" "id"
|
||||
]
|
||||
},
|
||||
-- The regression specifically is that the `_aggregate` root field for this
|
||||
-- table will conflict with the aggregation predicate for the array relationship
|
||||
-- between author and article.
|
||||
(table $ Schema.mkArrayRelationshipName "author_article" "id" "author_id")
|
||||
{ tableColumns =
|
||||
[ Schema.column "id" Schema.defaultSerialType
|
||||
],
|
||||
tablePrimaryKey = ["id"]
|
||||
},
|
||||
(table $ Schema.mkArrayRelationshipName "article" "id" "author_id")
|
||||
{ tableColumns =
|
||||
[ Schema.column "id" Schema.defaultSerialType
|
||||
],
|
||||
tablePrimaryKey = ["id"]
|
||||
}
|
||||
]
|
||||
|
||||
serialInt :: Schema.ScalarType
|
||||
serialInt =
|
||||
Schema.TCustomType $
|
||||
Schema.defaultBackendScalarType
|
||||
{ Schema.bstCitus = Just "INT",
|
||||
Schema.bstPostgres = Just "INT",
|
||||
Schema.bstCockroach = Just "INT4"
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests _ =
|
||||
-- All of the testing is done during setup.
|
||||
-- If setup succeeds and we have no conflicts, and this test will pass.
|
||||
it "Creates a schema without conflicts" \_ -> pure @IO ()
|
@ -63,7 +63,7 @@ defaultAggregationPredicatesParser aggFns si ti = runMaybeT do
|
||||
guard $ spiAllowAgg selectPermissions
|
||||
let rowPermissions = fmap partialSQLExpToUnpreparedValue <$> spiFilter selectPermissions
|
||||
relGqlName <- textToName $ relNameToTxt $ riName rel
|
||||
typeGqlName <- (<> Name.__ <> relGqlName <> Name.__ <> Name._aggregate) <$> getTableGQLName ti
|
||||
typeGqlName <- (<> Name.__ <> Name._aggregate_bool_exp) <$> getTableGQLName relTable
|
||||
|
||||
-- We only make a field for aggregations over a relation if at least
|
||||
-- some aggregation predicates are callable.
|
||||
|
@ -195,6 +195,9 @@ __or = [G.name|_or|]
|
||||
_aggregate :: G.Name
|
||||
_aggregate = [G.name|aggregate|]
|
||||
|
||||
_aggregate_bool_exp :: G.Name
|
||||
_aggregate_bool_exp = [G.name|aggregate_bool_exp|]
|
||||
|
||||
_column :: G.Name
|
||||
_column = [G.name|column|]
|
||||
|
||||
|
@ -130,13 +130,13 @@ spec = do
|
||||
[aesonQQ|
|
||||
{ "types": [
|
||||
{
|
||||
"name": "album_tracks_aggregate",
|
||||
"name": "track_aggregate_bool_exp",
|
||||
"fields": null,
|
||||
"inputFields": [
|
||||
{
|
||||
"name": "count",
|
||||
"type": {
|
||||
"name": "album_tracks_aggregate_count"
|
||||
"name": "track_aggregate_bool_exp_count"
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -148,7 +148,7 @@ spec = do
|
||||
[aesonQQ|
|
||||
{ "types": [
|
||||
{
|
||||
"name": "album_tracks_aggregate_count",
|
||||
"name": "track_aggregate_bool_exp_count",
|
||||
"fields": null,
|
||||
"inputFields": [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user