mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
f33fad5fc1
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4768 GitOrigin-RevId: 2d182344d724cf0fc07ec73f8a3c4d786afe9243
196 lines
5.1 KiB
Haskell
196 lines
5.1 KiB
Haskell
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
-- | Test querying an entity for a couple fields.
|
|
module Test.BasicFieldsSpec (spec) where
|
|
|
|
import Harness.Backend.BigQuery qualified as Bigquery
|
|
import Harness.Backend.Citus qualified as Citus
|
|
import Harness.Backend.Mysql qualified as Mysql
|
|
import Harness.Backend.Postgres qualified as Postgres
|
|
import Harness.Backend.Sqlserver qualified as Sqlserver
|
|
import Harness.GraphqlEngine qualified as GraphqlEngine
|
|
import Harness.Quoter.Graphql (graphql)
|
|
import Harness.Quoter.Yaml (shouldReturnYaml, yaml)
|
|
import Harness.Test.Context qualified as Context
|
|
import Harness.Test.Schema (Table (..), table)
|
|
import Harness.Test.Schema qualified as Schema
|
|
import Harness.TestEnvironment (TestEnvironment)
|
|
import Test.Hspec (SpecWith, describe, it)
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Preamble
|
|
|
|
spec :: SpecWith TestEnvironment
|
|
spec =
|
|
Context.run
|
|
[ Context.Context
|
|
{ name = Context.Backend Context.MySQL,
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
|
setup = Mysql.setup schema,
|
|
teardown = Mysql.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.Backend Context.Postgres,
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
|
setup = Postgres.setup schema,
|
|
teardown = Postgres.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.Backend Context.Citus,
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
|
setup = Citus.setup schema,
|
|
teardown = Citus.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.Backend Context.SQLServer,
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
|
setup = Sqlserver.setup schema,
|
|
teardown = Sqlserver.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.Backend Context.BigQuery,
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
|
setup = Bigquery.setup schema,
|
|
teardown = Bigquery.teardown schema,
|
|
customOptions =
|
|
Just $
|
|
Context.Options
|
|
{ stringifyNumbers = True
|
|
}
|
|
}
|
|
]
|
|
tests
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Schema
|
|
|
|
schema :: [Schema.Table]
|
|
schema = [author]
|
|
|
|
author :: Schema.Table
|
|
author =
|
|
(table "author")
|
|
{ tableColumns =
|
|
[ Schema.column "id" Schema.TInt,
|
|
Schema.column "name" Schema.TStr
|
|
],
|
|
tablePrimaryKey = ["id"],
|
|
tableData =
|
|
[ [Schema.VInt 1, Schema.VStr "Author 1"],
|
|
[Schema.VInt 2, Schema.VStr "Author 2"]
|
|
]
|
|
}
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Tests
|
|
|
|
tests :: Context.Options -> SpecWith TestEnvironment
|
|
tests opts = describe "BasicFieldsSpec" $ do
|
|
it "Author fields" $ \testEnvironment ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
testEnvironment
|
|
[graphql|
|
|
query {
|
|
hasura_author(order_by:[{id:asc}]) {
|
|
name
|
|
id
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
data:
|
|
hasura_author:
|
|
- name: Author 1
|
|
id: 1
|
|
- name: Author 2
|
|
id: 2
|
|
|]
|
|
-- Equivalent python suite: test_select_query_author
|
|
-- https://github.com/hasura/graphql-engine/blob/369d1ab2f119634b0e27e9ed353fa3d08c22d3fb/server/tests-py/test_graphql_queries.py#L254
|
|
it "Use operationName" $ \testEnvironment ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphqlYaml
|
|
testEnvironment
|
|
[yaml|
|
|
operationName: chooseThisOne
|
|
query: |
|
|
query ignoreThisOne {
|
|
MyQuery {
|
|
name
|
|
}
|
|
}
|
|
query chooseThisOne {
|
|
hasura_author(order_by:[{id:asc}]) {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
data:
|
|
hasura_author:
|
|
- name: Author 1
|
|
id: 1
|
|
- name: Author 2
|
|
id: 2
|
|
|]
|
|
-- Equivalent python suite: test_select_query_col_not_present_err
|
|
-- https://github.com/hasura/graphql-engine/blob/369d1ab2f119634b0e27e9ed353fa3d08c22d3fb/server/tests-py/test_graphql_queries.py#L292
|
|
it "Missing field" $ \testEnvironment -> do
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
testEnvironment
|
|
[graphql|
|
|
query {
|
|
hasura_author {
|
|
id
|
|
name
|
|
notPresentCol
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
errors:
|
|
- extensions:
|
|
code: validation-failed
|
|
path: $.selectionSet.hasura_author.selectionSet.notPresentCol
|
|
message: |-
|
|
field "notPresentCol" not found in type: 'hasura_author'
|
|
|]
|
|
-- Equivalent python suite: test_select_query_non_tracked_table
|
|
-- https://github.com/hasura/graphql-engine/blob/369d1ab2f119634b0e27e9ed353fa3d08c22d3fb/server/tests-py/test_graphql_queries.py#L289
|
|
it "Missing table" $ \testEnvironment ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
testEnvironment
|
|
[graphql|
|
|
query {
|
|
random {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
errors:
|
|
- extensions:
|
|
code: validation-failed
|
|
path: $.selectionSet.random
|
|
message: |-
|
|
field "random" not found in type: 'query_root'
|
|
|]
|