mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
5e7018b424
These are all enabled as default-extensions. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3800 GitOrigin-RevId: ab9f4b900df53d66221095c02d6b12a930ff5873
100 lines
1.9 KiB
Haskell
100 lines
1.9 KiB
Haskell
-- | Tests that `where' works.
|
|
module Test.WhereSpec (spec) where
|
|
|
|
import Harness.Backend.Mysql as Mysql
|
|
import Harness.GraphqlEngine qualified as GraphqlEngine
|
|
import Harness.Quoter.Graphql
|
|
import Harness.Quoter.Sql
|
|
import Harness.Quoter.Yaml
|
|
import Harness.State (State)
|
|
import Harness.Test.Context qualified as Context
|
|
import Test.Hspec
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Preamble
|
|
|
|
spec :: SpecWith State
|
|
spec =
|
|
Context.run
|
|
[ Context.Context
|
|
{ name = Context.MySQL,
|
|
mkLocalState = Context.noLocalState,
|
|
setup = mysqlSetup,
|
|
teardown = mysqlTeardown,
|
|
customOptions = Nothing
|
|
}
|
|
]
|
|
tests
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- MySQL backend
|
|
|
|
mysqlSetup :: (State, ()) -> IO ()
|
|
mysqlSetup (state, _) = do
|
|
-- Clear and reconfigure the metadata
|
|
GraphqlEngine.setSource state Mysql.defaultSourceMetadata
|
|
|
|
-- Setup tables
|
|
Mysql.run_
|
|
[sql|
|
|
CREATE TABLE author
|
|
(
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(45) UNIQUE KEY
|
|
);
|
|
|]
|
|
Mysql.run_
|
|
[sql|
|
|
INSERT INTO author
|
|
(name)
|
|
VALUES
|
|
( 'Author 1'),
|
|
( 'Author 2');
|
|
|]
|
|
|
|
-- Track the tables
|
|
GraphqlEngine.postMetadata_
|
|
state
|
|
[yaml|
|
|
type: mysql_track_table
|
|
args:
|
|
source: mysql
|
|
table:
|
|
schema: hasura
|
|
name: author
|
|
|]
|
|
|
|
mysqlTeardown :: (State, ()) -> IO ()
|
|
mysqlTeardown _ = do
|
|
Mysql.run_
|
|
[sql|
|
|
DROP TABLE author;
|
|
|]
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Tests
|
|
|
|
tests :: Context.Options -> SpecWith State
|
|
tests opts = do
|
|
it "Where id=1" \state ->
|
|
shouldReturnYaml
|
|
opts
|
|
( GraphqlEngine.postGraphql
|
|
state
|
|
[graphql|
|
|
query {
|
|
hasura_author(where: {id: {_eq: 1}}) {
|
|
name
|
|
id
|
|
}
|
|
}
|
|
|]
|
|
)
|
|
[yaml|
|
|
data:
|
|
hasura_author:
|
|
- name: Author 1
|
|
id: 1
|
|
|]
|