mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
7b2bb262b8
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5138 GitOrigin-RevId: 1328772e5262f4cd4d931bfb40103fe619d39f83
170 lines
4.2 KiB
Haskell
170 lines
4.2 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 "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
|
|
|]
|
|
|
|
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'
|
|
|]
|
|
|
|
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'
|
|
|]
|