mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
Remove the BasicFieldsSpec
module, reorganise its contents
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5189 GitOrigin-RevId: f68baca8cc5c0b52135141191bbbee5771d791e1
This commit is contained in:
parent
b69182f4fe
commit
9a55b50d0e
@ -1224,7 +1224,6 @@ test-suite tests-hspec
|
|||||||
-- Test
|
-- Test
|
||||||
Test.ArrayParamPermissionSpec
|
Test.ArrayParamPermissionSpec
|
||||||
Test.BackendOnlyPermissionsSpec
|
Test.BackendOnlyPermissionsSpec
|
||||||
Test.BasicFieldsSpec
|
|
||||||
Test.BigQuery.ComputedFieldSpec
|
Test.BigQuery.ComputedFieldSpec
|
||||||
Test.BigQuery.Metadata.ComputedFieldSpec
|
Test.BigQuery.Metadata.ComputedFieldSpec
|
||||||
Test.ColumnPresetsSpec
|
Test.ColumnPresetsSpec
|
||||||
@ -1265,6 +1264,7 @@ test-suite tests-hspec
|
|||||||
Test.PrimaryKeySpec
|
Test.PrimaryKeySpec
|
||||||
Test.Queries.Paginate.LimitSpec
|
Test.Queries.Paginate.LimitSpec
|
||||||
Test.Queries.Simple.ObjectQueriesSpec
|
Test.Queries.Simple.ObjectQueriesSpec
|
||||||
|
Test.Queries.Simple.OperationNameSpec
|
||||||
Test.RemoteRelationship.FromRemoteSchemaSpec
|
Test.RemoteRelationship.FromRemoteSchemaSpec
|
||||||
Test.RemoteRelationship.MetadataAPI.ClearMetadataSpec
|
Test.RemoteRelationship.MetadataAPI.ClearMetadataSpec
|
||||||
Test.RemoteRelationship.MetadataAPI.Common
|
Test.RemoteRelationship.MetadataAPI.Common
|
||||||
|
@ -153,3 +153,58 @@ tests opts = do
|
|||||||
|]
|
|]
|
||||||
|
|
||||||
actual `shouldBe` expected
|
actual `shouldBe` expected
|
||||||
|
|
||||||
|
it "Fails on missing tables" \testEnvironment -> do
|
||||||
|
let expected :: Value
|
||||||
|
expected =
|
||||||
|
[yaml|
|
||||||
|
errors:
|
||||||
|
- extensions:
|
||||||
|
code: validation-failed
|
||||||
|
path: $.selectionSet.random
|
||||||
|
message: |-
|
||||||
|
field 'random' not found in type: 'query_root'
|
||||||
|
|]
|
||||||
|
|
||||||
|
actual :: IO Value
|
||||||
|
actual =
|
||||||
|
postGraphql
|
||||||
|
testEnvironment
|
||||||
|
[graphql|
|
||||||
|
query {
|
||||||
|
random {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
|
actual `shouldBe` expected
|
||||||
|
|
||||||
|
it "Fails on missing fields" \testEnvironment -> do
|
||||||
|
let expected :: Value
|
||||||
|
expected =
|
||||||
|
[yaml|
|
||||||
|
errors:
|
||||||
|
- extensions:
|
||||||
|
code: validation-failed
|
||||||
|
path: $.selectionSet.hasura_author.selectionSet.notPresentCol
|
||||||
|
message: |-
|
||||||
|
field 'notPresentCol' not found in type: 'hasura_author'
|
||||||
|
|]
|
||||||
|
|
||||||
|
actual :: IO Value
|
||||||
|
actual =
|
||||||
|
postGraphql
|
||||||
|
testEnvironment
|
||||||
|
[graphql|
|
||||||
|
query {
|
||||||
|
hasura_author {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
notPresentCol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
|
actual `shouldBe` expected
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
|
||||||
-- | Test querying an entity for a couple fields.
|
-- |
|
||||||
module Test.BasicFieldsSpec (spec) where
|
-- Queries involving the `operationName` key.
|
||||||
|
--
|
||||||
|
-- https://spec.graphql.org/June2018/#sec-Executing-Requests
|
||||||
|
module Test.Queries.Simple.OperationNameSpec (spec) where
|
||||||
|
|
||||||
import Harness.Backend.BigQuery qualified as Bigquery
|
import Data.Aeson (Value)
|
||||||
|
import Harness.Backend.BigQuery qualified as BigQuery
|
||||||
import Harness.Backend.Citus qualified as Citus
|
import Harness.Backend.Citus qualified as Citus
|
||||||
import Harness.Backend.Mysql qualified as Mysql
|
import Harness.Backend.Mysql qualified as Mysql
|
||||||
import Harness.Backend.Postgres qualified as Postgres
|
import Harness.Backend.Postgres qualified as Postgres
|
||||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
import Harness.GraphqlEngine (postGraphqlYaml)
|
||||||
import Harness.Quoter.Graphql (graphql)
|
|
||||||
import Harness.Quoter.Yaml (shouldReturnYaml, yaml)
|
import Harness.Quoter.Yaml (shouldReturnYaml, yaml)
|
||||||
|
import Harness.Test.Context (Options (..))
|
||||||
import Harness.Test.Context qualified as Context
|
import Harness.Test.Context qualified as Context
|
||||||
import Harness.Test.Schema (Table (..), table)
|
import Harness.Test.Schema (Table (..), table)
|
||||||
import Harness.Test.Schema qualified as Schema
|
import Harness.Test.Schema qualified as Schema
|
||||||
@ -18,11 +22,8 @@ import Harness.TestEnvironment (TestEnvironment)
|
|||||||
import Test.Hspec (SpecWith, describe, it)
|
import Test.Hspec (SpecWith, describe, it)
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Preamble
|
|
||||||
|
|
||||||
spec :: SpecWith TestEnvironment
|
spec :: SpecWith TestEnvironment
|
||||||
spec =
|
spec = do
|
||||||
Context.run
|
Context.run
|
||||||
[ Context.Context
|
[ Context.Context
|
||||||
{ name = Context.Backend Context.MySQL,
|
{ name = Context.Backend Context.MySQL,
|
||||||
@ -55,8 +56,8 @@ spec =
|
|||||||
Context.Context
|
Context.Context
|
||||||
{ name = Context.Backend Context.BigQuery,
|
{ name = Context.Backend Context.BigQuery,
|
||||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||||
setup = Bigquery.setup schema,
|
setup = BigQuery.setup schema,
|
||||||
teardown = Bigquery.teardown schema,
|
teardown = BigQuery.teardown schema,
|
||||||
customOptions =
|
customOptions =
|
||||||
Just $
|
Just $
|
||||||
Context.Options
|
Context.Options
|
||||||
@ -70,31 +71,48 @@ spec =
|
|||||||
-- Schema
|
-- Schema
|
||||||
|
|
||||||
schema :: [Schema.Table]
|
schema :: [Schema.Table]
|
||||||
schema = [author]
|
schema =
|
||||||
|
[ (table "author")
|
||||||
author :: Schema.Table
|
|
||||||
author =
|
|
||||||
(table "author")
|
|
||||||
{ tableColumns =
|
{ tableColumns =
|
||||||
[ Schema.column "id" Schema.TInt,
|
[ Schema.column "id" Schema.TInt,
|
||||||
Schema.column "name" Schema.TStr
|
Schema.column "name" Schema.TStr
|
||||||
],
|
],
|
||||||
tablePrimaryKey = ["id"],
|
tablePrimaryKey = ["id"],
|
||||||
tableData =
|
tableData =
|
||||||
[ [Schema.VInt 1, Schema.VStr "Author 1"],
|
[ [ Schema.VInt 1,
|
||||||
[Schema.VInt 2, Schema.VStr "Author 2"]
|
Schema.VStr "Author 1"
|
||||||
|
],
|
||||||
|
[ Schema.VInt 2,
|
||||||
|
Schema.VStr "Author 2"
|
||||||
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Tests
|
-- Tests
|
||||||
|
|
||||||
tests :: Context.Options -> SpecWith TestEnvironment
|
tests :: Context.Options -> SpecWith TestEnvironment
|
||||||
tests opts = describe "BasicFieldsSpec" $ do
|
tests opts = describe "BasicFieldsSpec" do
|
||||||
it "Use operationName" $ \testEnvironment ->
|
let shouldBe :: IO Value -> Value -> IO ()
|
||||||
shouldReturnYaml
|
shouldBe = shouldReturnYaml opts
|
||||||
opts
|
|
||||||
( GraphqlEngine.postGraphqlYaml
|
describe "Use the `operationName` key" do
|
||||||
|
it "Selects the correct operation" \testEnvironment -> do
|
||||||
|
let expected :: Value
|
||||||
|
expected =
|
||||||
|
[yaml|
|
||||||
|
data:
|
||||||
|
hasura_author:
|
||||||
|
- name: Author 1
|
||||||
|
id: 1
|
||||||
|
- name: Author 2
|
||||||
|
id: 2
|
||||||
|
|]
|
||||||
|
|
||||||
|
actual :: IO Value
|
||||||
|
actual =
|
||||||
|
postGraphqlYaml
|
||||||
testEnvironment
|
testEnvironment
|
||||||
[yaml|
|
[yaml|
|
||||||
operationName: chooseThisOne
|
operationName: chooseThisOne
|
||||||
@ -111,59 +129,5 @@ query: |
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
)
|
|
||||||
[yaml|
|
|
||||||
data:
|
|
||||||
hasura_author:
|
|
||||||
- name: Author 1
|
|
||||||
id: 1
|
|
||||||
- name: Author 2
|
|
||||||
id: 2
|
|
||||||
|]
|
|
||||||
|
|
||||||
it "Missing field" $ \testEnvironment -> do
|
actual `shouldBe` expected
|
||||||
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'
|
|
||||||
|]
|
|
Loading…
Reference in New Issue
Block a user