2022-03-16 03:39:21 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2021-11-19 18:13:33 +03:00
|
|
|
-- | Testing object relationships.
|
2022-01-21 10:48:27 +03:00
|
|
|
module Test.ObjectRelationshipsSpec (spec) where
|
2021-11-19 18:13:33 +03:00
|
|
|
|
2022-02-21 11:52:05 +03:00
|
|
|
import Harness.Backend.Mysql qualified as Mysql
|
|
|
|
import Harness.Backend.Sqlserver qualified as Sqlserver
|
2021-11-19 18:13:33 +03:00
|
|
|
import Harness.GraphqlEngine qualified as GraphqlEngine
|
2022-01-21 10:48:27 +03:00
|
|
|
import Harness.Quoter.Graphql
|
|
|
|
import Harness.Quoter.Yaml
|
2021-11-23 21:15:17 +03:00
|
|
|
import Harness.State (State)
|
2022-02-21 20:05:09 +03:00
|
|
|
import Harness.Test.Context qualified as Context
|
2022-03-10 14:18:13 +03:00
|
|
|
import Harness.Test.Schema qualified as Schema
|
2021-11-19 18:13:33 +03:00
|
|
|
import Test.Hspec
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Preamble
|
|
|
|
|
2021-11-23 21:15:17 +03:00
|
|
|
spec :: SpecWith State
|
2022-02-21 11:52:05 +03:00
|
|
|
spec = do
|
2022-02-21 20:05:09 +03:00
|
|
|
Context.run
|
|
|
|
[ Context.Context
|
2022-03-15 19:08:47 +03:00
|
|
|
{ name = Context.Backend Context.SQLServer,
|
2022-02-21 20:05:09 +03:00
|
|
|
mkLocalState = Context.noLocalState,
|
2022-03-10 14:18:13 +03:00
|
|
|
setup = Sqlserver.setup schema,
|
|
|
|
teardown = Sqlserver.teardown schema,
|
2022-02-21 11:52:05 +03:00
|
|
|
customOptions = Nothing
|
|
|
|
}
|
|
|
|
]
|
|
|
|
mssqlTests
|
|
|
|
|
2022-02-21 20:05:09 +03:00
|
|
|
Context.run
|
|
|
|
[ Context.Context
|
2022-03-15 19:08:47 +03:00
|
|
|
{ name = Context.Backend Context.MySQL,
|
2022-02-21 20:05:09 +03:00
|
|
|
mkLocalState = Context.noLocalState,
|
2022-03-10 14:18:13 +03:00
|
|
|
setup = Mysql.setup schema,
|
|
|
|
teardown = Mysql.teardown schema,
|
2022-02-18 16:35:32 +03:00
|
|
|
customOptions = Nothing
|
2022-02-14 20:24:24 +03:00
|
|
|
}
|
|
|
|
]
|
2022-02-21 11:52:05 +03:00
|
|
|
mysqlTests
|
|
|
|
|
2022-03-10 14:18:13 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Schema
|
|
|
|
|
|
|
|
schema :: [Schema.Table]
|
|
|
|
schema = [author, article]
|
|
|
|
|
|
|
|
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.columnNull "author_id" Schema.TInt
|
|
|
|
]
|
|
|
|
["id"]
|
|
|
|
[Schema.Reference "author_id" "author" "id"]
|
|
|
|
[ [ Schema.VInt 1,
|
|
|
|
Schema.VInt 1
|
|
|
|
],
|
|
|
|
[ Schema.VInt 2,
|
|
|
|
Schema.VInt 1
|
|
|
|
],
|
|
|
|
[ Schema.VInt 3,
|
|
|
|
Schema.VInt 2
|
|
|
|
],
|
|
|
|
[ Schema.VInt 4,
|
|
|
|
Schema.VNull
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-02-21 11:52:05 +03:00
|
|
|
-- Tests
|
|
|
|
|
2022-03-10 14:18:13 +03:00
|
|
|
mssqlTests :: Context.Options -> SpecWith State
|
|
|
|
mssqlTests opts = do
|
|
|
|
usingWhereClause opts
|
|
|
|
nullField opts
|
|
|
|
|
2022-02-21 20:05:09 +03:00
|
|
|
mysqlTests :: Context.Options -> SpecWith State
|
2022-02-21 11:52:05 +03:00
|
|
|
mysqlTests opts = do
|
|
|
|
usingWhereClause opts
|
|
|
|
xdescribe
|
|
|
|
"Pending: The MySQL backend currently fails with relationship fields that are null.\
|
|
|
|
\ (https://github.com/hasura/graphql-engine-mono/issues/3650)"
|
|
|
|
(nullField opts)
|
|
|
|
|
2022-02-21 20:05:09 +03:00
|
|
|
usingWhereClause :: Context.Options -> SpecWith State
|
2022-02-21 11:52:05 +03:00
|
|
|
usingWhereClause opts = do
|
|
|
|
it "Author of article where id=1" $ \state ->
|
|
|
|
shouldReturnYaml
|
|
|
|
opts
|
|
|
|
( GraphqlEngine.postGraphql
|
|
|
|
state
|
|
|
|
[graphql|
|
|
|
|
query {
|
|
|
|
hasura_article(where: {id: {_eq: 1}}) {
|
|
|
|
id
|
2022-03-10 14:18:13 +03:00
|
|
|
author_by_author_id {
|
2022-02-21 11:52:05 +03:00
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
)
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
hasura_article:
|
|
|
|
- id: 1
|
2022-03-10 14:18:13 +03:00
|
|
|
author_by_author_id:
|
2022-02-21 11:52:05 +03:00
|
|
|
id: 1
|
|
|
|
|]
|
|
|
|
|
2022-02-21 20:05:09 +03:00
|
|
|
nullField :: Context.Options -> SpecWith State
|
2022-02-21 11:52:05 +03:00
|
|
|
nullField opts = do
|
|
|
|
it "Can realise a null relationship field" $ \state ->
|
|
|
|
shouldReturnYaml
|
|
|
|
opts
|
|
|
|
( GraphqlEngine.postGraphql
|
|
|
|
state
|
|
|
|
[graphql|
|
|
|
|
query {
|
|
|
|
hasura_article(where: {id: {_eq: 4}}) {
|
|
|
|
id
|
2022-03-10 14:18:13 +03:00
|
|
|
author_by_author_id {
|
2022-02-21 11:52:05 +03:00
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
)
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
hasura_article:
|
2022-03-10 14:18:13 +03:00
|
|
|
- author_by_author_id: null
|
2022-02-21 11:52:05 +03:00
|
|
|
id: 4
|
|
|
|
|]
|