mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
Add tests for query aliases
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6384 Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com> GitOrigin-RevId: 331baf9ec41bc6b2d618362e87defa44ca39da40
This commit is contained in:
parent
1e8846d27d
commit
c1b66d7243
@ -108,6 +108,7 @@ executable api-tests
|
||||
Test.Postgres.UniqueConstraintsSpec
|
||||
Test.Queries.AggregationPredicatesSpec
|
||||
Test.Queries.AggregationSpec
|
||||
Test.Queries.AliasesSpec
|
||||
Test.Queries.Directives.IncludeAndSkipSpec
|
||||
Test.Queries.Directives.IncludeSpec
|
||||
Test.Queries.Directives.SkipSpec
|
||||
|
125
server/lib/api-tests/test/Test/Queries/AliasesSpec.hs
Normal file
125
server/lib/api-tests/test/Test/Queries/AliasesSpec.hs
Normal file
@ -0,0 +1,125 @@
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
-- |
|
||||
-- Tests for queries involving GraphQL aliases.
|
||||
--
|
||||
-- https://hasura.io/docs/latest/queries/postgres/variables-aliases-fragments-directives/#using-aliases
|
||||
-- https://hasura.io/docs/latest/queries/ms-sql-server/variables-aliases-fragments-directives/#using-aliases
|
||||
-- https://hasura.io/docs/latest/queries/bigquery/variables-aliases-fragments-directives/#using-aliases
|
||||
module Test.Queries.AliasesSpec where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Cockroach qualified as Cockroach
|
||||
import Harness.Backend.Mysql qualified as Mysql
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
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 Harness.Yaml (shouldReturnYaml)
|
||||
import Hasura.Prelude
|
||||
import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec = do
|
||||
Fixture.run
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Mysql.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Citus.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.defaultOptions
|
||||
{ Fixture.stringifyNumbers = True
|
||||
}
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Cockroach)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Cockroach.setupTablesAction schema testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Schema
|
||||
|
||||
schema :: [Schema.Table]
|
||||
schema =
|
||||
[ (table "author")
|
||||
{ tableColumns =
|
||||
[ Schema.column "id" Schema.TInt,
|
||||
Schema.column "name" Schema.TStr
|
||||
],
|
||||
tablePrimaryKey = ["id"],
|
||||
tableData =
|
||||
[ [Schema.VInt 1, Schema.VStr "Alice"],
|
||||
[Schema.VInt 2, Schema.VStr "Bob"]
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
||||
describe "Using aliases" do
|
||||
it "Two aliased queries" \testEnvironment -> do
|
||||
let schemaName :: Schema.SchemaName
|
||||
schemaName = Schema.getSchemaName testEnvironment
|
||||
|
||||
actual :: IO Value
|
||||
actual =
|
||||
postGraphql
|
||||
testEnvironment
|
||||
[graphql|
|
||||
query {
|
||||
first:#{schemaName}_author (where: { id: { _eq: 1 } }) { name }
|
||||
second:#{schemaName}_author (where: { id: { _eq: 2 } }) { name }
|
||||
}
|
||||
|]
|
||||
|
||||
expected :: Value
|
||||
expected =
|
||||
[interpolateYaml|
|
||||
data:
|
||||
first:
|
||||
- name: Alice
|
||||
second:
|
||||
- name: Bob
|
||||
|]
|
||||
|
||||
actual `shouldBe` expected
|
Loading…
Reference in New Issue
Block a user