mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
853e9b760d
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3765 GitOrigin-RevId: 22c36c83ff900b3423144353ccdf61980b66bc6b
201 lines
4.6 KiB
Haskell
201 lines
4.6 KiB
Haskell
-- | 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.State (State)
|
|
import Harness.Test.Context qualified as Context
|
|
import Harness.Test.Schema qualified as Schema
|
|
import Test.Hspec (SpecWith, describe, it)
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Preamble
|
|
|
|
spec :: SpecWith State
|
|
spec =
|
|
Context.run
|
|
[ Context.Context
|
|
{ name = Context.MySQL,
|
|
mkLocalState = Context.noLocalState,
|
|
setup = Mysql.setup schema,
|
|
teardown = Mysql.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.Postgres,
|
|
mkLocalState = Context.noLocalState,
|
|
setup = Postgres.setup schema,
|
|
teardown = Postgres.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.Citus,
|
|
mkLocalState = Context.noLocalState,
|
|
setup = Citus.setup schema,
|
|
teardown = Citus.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.SQLServer,
|
|
mkLocalState = Context.noLocalState,
|
|
setup = Sqlserver.setup schema,
|
|
teardown = Sqlserver.teardown schema,
|
|
customOptions = Nothing
|
|
},
|
|
Context.Context
|
|
{ name = Context.BigQuery,
|
|
mkLocalState = Context.noLocalState,
|
|
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 =
|
|
Schema.Table
|
|
"author"
|
|
[ Schema.column "id" Schema.TInt,
|
|
Schema.column "name" Schema.TStr
|
|
]
|
|
["id"]
|
|
[]
|
|
[ [Schema.VInt 1, Schema.VStr "Author 1"],
|
|
[Schema.VInt 2, Schema.VStr "Author 2"]
|
|
]
|
|
|
|
_article :: Schema.Table
|
|
_article =
|
|
Schema.Table
|
|
"article"
|
|
[ Schema.column "id" Schema.TInt,
|
|
Schema.column "name" Schema.TStr,
|
|
Schema.column "author_id" Schema.TInt
|
|
]
|
|
["id"]
|
|
[Schema.Reference "author_id" "hasura.author" "id"]
|
|
[ [Schema.VInt 1, Schema.VStr "article1", Schema.VInt 1],
|
|
[Schema.VInt 2, Schema.VStr "article2", Schema.VInt 2],
|
|
[Schema.VInt 3, Schema.VStr "article3", Schema.VInt 3]
|
|
]
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Tests
|
|
|
|
tests :: Context.Options -> SpecWith State
|
|
tests opts = describe "BasicFieldsSpec" $ do
|
|
it "Author fields" $ \state ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
state
|
|
[graphql|
|
|
query {
|
|
hasura_author(order_by:[{id:asc}]) {
|
|
name
|
|
id
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
data:
|
|
hasura_author:
|
|
- name: Author 1
|
|
id: 1
|
|
- name: Author 2
|
|
id: 2
|
|
|]
|
|
it "Use operationName" $ \state ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphqlYaml
|
|
state
|
|
[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" $ \state -> do
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
state
|
|
[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" $ \state ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
state
|
|
[graphql|
|
|
query {
|
|
random {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
errors:
|
|
- extensions:
|
|
code: validation-failed
|
|
path: $.selectionSet.random
|
|
message: |-
|
|
field "random" not found in type: 'query_root'
|
|
|]
|