mirror of
https://github.com/Airsequel/AirGQL.git
synced 2025-08-14 02:36:57 +03:00
Move mutation tests into their own file & fix breaking tests
This commit is contained in:
parent
7a9914325d
commit
d490179428
7 changed files with 1516 additions and 1227 deletions
|
@ -902,7 +902,7 @@ mutationType connection maxRowsPerTable accessMode dbId tables = do
|
|||
"Column "
|
||||
<> T.unpack column
|
||||
<> " cannot be set on conflicts without \
|
||||
\ being explicitly provided"
|
||||
\being explicitly provided"
|
||||
|
||||
pure $
|
||||
quoteKeyword column
|
||||
|
|
|
@ -231,7 +231,11 @@ mutationResponseType accessMode table = do
|
|||
]
|
||||
<> readonlyFields
|
||||
)
|
||||
& Type.withDescription ("Mutation response for " <> table.name)
|
||||
& Type.withDescription
|
||||
( "Mutation response for table \""
|
||||
<> table.name
|
||||
<> "\""
|
||||
)
|
||||
|
||||
|
||||
mutationByPkResponseType :: AccessMode -> TableEntry -> Type.IntrospectionType
|
||||
|
@ -250,7 +254,11 @@ mutationByPkResponseType accessMode table = do
|
|||
]
|
||||
<> readonlyFields
|
||||
)
|
||||
& Type.withDescription ("Mutation response for " <> table.name)
|
||||
& Type.withDescription
|
||||
( "Response for a PK-based mutation on table \""
|
||||
<> table.name
|
||||
<> "\""
|
||||
)
|
||||
|
||||
|
||||
tableInsertField :: AccessMode -> TableEntry -> Type.Field
|
||||
|
@ -388,7 +396,7 @@ tableUpdateFieldByPk accessMode tables table = do
|
|||
)
|
||||
(Type.nonNull $ mutationByPkResponseType accessMode table)
|
||||
& Type.fieldWithDescription
|
||||
("Update row in table \"" <> table.name <> "\"")
|
||||
("Update row in table \"" <> table.name <> "\" by PK")
|
||||
& Type.withArguments arguments
|
||||
|
||||
|
||||
|
@ -423,7 +431,7 @@ tableDeleteFieldByPK accessMode tables table = do
|
|||
)
|
||||
(Type.nonNull $ mutationByPkResponseType accessMode table)
|
||||
& Type.fieldWithDescription
|
||||
("Delete row in table \"" <> table.name <> "\"")
|
||||
("Delete row in table \"" <> table.name <> "\" by PK")
|
||||
& Type.withArguments args
|
||||
|
||||
|
||||
|
|
1218
tests/Spec.hs
1218
tests/Spec.hs
File diff suppressed because it is too large
Load diff
|
@ -239,10 +239,21 @@ main = void $ do
|
|||
{ "name": "set" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "update_users_by_pk",
|
||||
"args": [
|
||||
{ "name": "email" },
|
||||
{ "name": "set" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "delete_users",
|
||||
"args": [ { "name": "filter" } ]
|
||||
},
|
||||
{
|
||||
"name": "delete_users_by_pk",
|
||||
"args": [ { "name": "email" } ]
|
||||
},
|
||||
{
|
||||
"name": "insert_songs",
|
||||
"args": [ { "name": "objects" }, { "name": "on_conflict" } ]
|
||||
|
@ -254,9 +265,20 @@ main = void $ do
|
|||
{ "name": "set" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "update_songs_by_pk",
|
||||
"args": [
|
||||
{ "name": "rowid" },
|
||||
{ "name": "set" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "delete_songs",
|
||||
"args": [ { "name": "filter" } ]
|
||||
},
|
||||
{
|
||||
"name": "delete_songs_by_pk",
|
||||
"args": [ { "name": "rowid" } ]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -334,7 +356,11 @@ main = void $ do
|
|||
{ "name": "delete_users" },
|
||||
{ "name": "insert_songs" },
|
||||
{ "name": "update_songs" },
|
||||
{ "name": "delete_songs" }
|
||||
{ "name": "delete_songs" },
|
||||
{ "name": "update_users_by_pk" },
|
||||
{ "name": "delete_users_by_pk" },
|
||||
{ "name": "update_songs_by_pk" },
|
||||
{ "name": "delete_songs_by_pk" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -408,6 +434,7 @@ main = void $ do
|
|||
"types": [
|
||||
{ "kind": "OBJECT", "name": "users_row" },
|
||||
{ "kind": "OBJECT", "name": "users_mutation_response" },
|
||||
{ "kind": "OBJECT", "name": "users_mutation_by_pk_response" },
|
||||
{ "kind": "INPUT_OBJECT", "name": "users_insert_input" },
|
||||
{ "kind": "ENUM", "name": "users_column" },
|
||||
{ "kind": "INPUT_OBJECT", "name": "users_upsert_on_conflict" },
|
||||
|
@ -417,6 +444,7 @@ main = void $ do
|
|||
|
||||
{ "kind": "OBJECT", "name": "songs_row" },
|
||||
{ "kind": "OBJECT", "name": "songs_mutation_response" },
|
||||
{ "kind": "OBJECT", "name": "songs_mutation_by_pk_response" },
|
||||
{ "kind": "INPUT_OBJECT", "name": "songs_insert_input" },
|
||||
{ "kind": "ENUM", "name": "songs_column" },
|
||||
{ "kind": "INPUT_OBJECT", "name": "songs_upsert_on_conflict" },
|
||||
|
@ -596,6 +624,13 @@ main = void $ do
|
|||
schema <- getDerivedSchema defaultSchemaConf conn fixtureDbId tables
|
||||
|
||||
Right result <- graphql schema Nothing mempty introspectionQuery
|
||||
|
||||
-- Uncomment to write the new file to disk (for easier diffing)
|
||||
-- writeFile (testRoot </> "new_introspection_result.json") $
|
||||
-- decodeUtf8 $
|
||||
-- BL.toStrict $
|
||||
-- Ae.encode result
|
||||
|
||||
result `unorderedShouldBe` expected
|
||||
|
||||
it "doesn't allow writeonly tokens to return data" $ do
|
||||
|
|
1108
tests/Tests/MutationSpec.hs
Normal file
1108
tests/Tests/MutationSpec.hs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,8 +10,6 @@ import Protolude (
|
|||
Maybe (Nothing),
|
||||
Monoid (mempty),
|
||||
bracket_,
|
||||
finally,
|
||||
flip,
|
||||
fromMaybe,
|
||||
show,
|
||||
void,
|
||||
|
@ -24,7 +22,7 @@ import Database.SQLite.Simple.QQ (sql)
|
|||
import Language.GraphQL.JSON (graphql)
|
||||
import Language.GraphQL.TH (gql)
|
||||
import System.FilePath ((</>))
|
||||
import Test.Hspec (Spec, before_, describe, it, pendingWith, shouldBe, shouldContain)
|
||||
import Test.Hspec (Spec, before_, describe, it, shouldBe, shouldContain)
|
||||
|
||||
import AirGQL.GraphQL (getDerivedSchema)
|
||||
import AirGQL.Lib (getEnrichedTables)
|
||||
|
@ -836,3 +834,127 @@ main = void $ do
|
|||
|]
|
||||
|
||||
Ae.encode result `shouldBe` expected
|
||||
|
||||
it "treats NULL as a value when using 'neq' filters" $ do
|
||||
conn <- SS.open dbPath
|
||||
SS.execute_
|
||||
conn
|
||||
[sql|
|
||||
insert into users (name, email, created_utc)
|
||||
values
|
||||
(NULL, 'john@example.com', '2021-01-01T00:00Z'),
|
||||
('Eve', 'eve@example.com', '2021-01-02T00:00Z')
|
||||
|]
|
||||
|
||||
let
|
||||
query =
|
||||
[gql|
|
||||
query {
|
||||
users(filter: { name: { neq: "Eve" }}) {
|
||||
name, email
|
||||
}
|
||||
}
|
||||
|]
|
||||
|
||||
expected =
|
||||
rmSpaces
|
||||
[raw|{
|
||||
"data": {
|
||||
"users": [{
|
||||
"name": null,
|
||||
"email": "john@example.com"
|
||||
}]
|
||||
}
|
||||
}|]
|
||||
|
||||
Right tables <- getEnrichedTables conn
|
||||
schema <- getDerivedSchema defaultSchemaConf conn fixtureDbId tables
|
||||
Right result <- graphql schema Nothing mempty query
|
||||
|
||||
Ae.encode result `shouldBe` expected
|
||||
|
||||
it "treats NULL as a value when using 'nin' filters" $ do
|
||||
conn <- SS.open dbPath
|
||||
SS.execute_
|
||||
conn
|
||||
[sql|
|
||||
insert into users (name, email, created_utc)
|
||||
values
|
||||
('Eve', 'eve@example.com', '2021-01-01T00:00Z'),
|
||||
('Jon', 'jon@example.com', '2021-01-02T00:00Z'),
|
||||
('Arbuckle', 'arbuckle@example.com', '2021-01-03T00:00Z'),
|
||||
(NULL, 'adam@example.com', '2021-01-04T00:00Z')
|
||||
|]
|
||||
|
||||
let
|
||||
query =
|
||||
[gql|
|
||||
query {
|
||||
users(filter: { name: { nin: ["Eve", "Arbuckle"]}}) {
|
||||
name, email
|
||||
}
|
||||
}
|
||||
|]
|
||||
|
||||
expected =
|
||||
rmSpaces
|
||||
[raw|{
|
||||
"data": {
|
||||
"users": [{
|
||||
"name": "Jon",
|
||||
"email": "jon@example.com"
|
||||
}, {
|
||||
"name": null,
|
||||
"email": "adam@example.com"
|
||||
}]
|
||||
}
|
||||
}|]
|
||||
|
||||
Right tables <- getEnrichedTables conn
|
||||
schema <- getDerivedSchema defaultSchemaConf conn fixtureDbId tables
|
||||
Right result <- graphql schema Nothing mempty query
|
||||
|
||||
Ae.encode result `shouldBe` expected
|
||||
|
||||
it "supports 'in' filters" $ do
|
||||
conn <- SS.open dbPath
|
||||
SS.execute_
|
||||
conn
|
||||
[sql|
|
||||
insert into users (name, email, created_utc)
|
||||
values
|
||||
('Eve', 'eve@example.com', '2021-01-01T00:00Z'),
|
||||
('Jon', 'jon@example.com', '2021-01-02T00:00Z'),
|
||||
('Arbuckle', 'arbuckle@example.com', '2021-01-03T00:00Z'),
|
||||
(NULL, 'adam@example.com', '2021-01-04T00:00Z')
|
||||
|]
|
||||
|
||||
let
|
||||
query =
|
||||
[gql|
|
||||
query {
|
||||
users(filter: { name: { in: ["Eve", "Arbuckle"]}}) {
|
||||
name, email
|
||||
}
|
||||
}
|
||||
|]
|
||||
|
||||
expected =
|
||||
rmSpaces
|
||||
[raw|{
|
||||
"data": {
|
||||
"users": [{
|
||||
"name": "Eve",
|
||||
"email": "eve@example.com"
|
||||
}, {
|
||||
"name": "Arbuckle",
|
||||
"email": "arbuckle@example.com"
|
||||
}]
|
||||
}
|
||||
}|]
|
||||
|
||||
Right tables <- getEnrichedTables conn
|
||||
schema <- getDerivedSchema defaultSchemaConf conn fixtureDbId tables
|
||||
Right result <- graphql schema Nothing mempty query
|
||||
|
||||
Ae.encode result `shouldBe` expected
|
||||
|
|
|
@ -359,7 +359,7 @@
|
|||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"description": "Mutation response for users",
|
||||
"description": "Mutation response for table \"users\"",
|
||||
"enumValues": null,
|
||||
"fields": [
|
||||
{
|
||||
|
@ -1637,6 +1637,158 @@
|
|||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"description": "Fields to be updated",
|
||||
"name": "set",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "INPUT_OBJECT",
|
||||
"name": "users_set_input",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"name": "email",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"deprecationReason": null,
|
||||
"description": "Update row in table \"users\" by PK",
|
||||
"isDeprecated": false,
|
||||
"name": "update_users_by_pk",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "users_mutation_by_pk_response",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"description": "Fields to be updated",
|
||||
"name": "set",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "INPUT_OBJECT",
|
||||
"name": "songs_set_input",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"name": "rowid",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "Int",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"deprecationReason": null,
|
||||
"description": "Update row in table \"songs\" by PK",
|
||||
"isDeprecated": false,
|
||||
"name": "update_songs_by_pk",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "songs_mutation_by_pk_response",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"name": "email",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"deprecationReason": null,
|
||||
"description": "Delete row in table \"users\" by PK",
|
||||
"isDeprecated": false,
|
||||
"name": "delete_users_by_pk",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "users_mutation_by_pk_response",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"description": null,
|
||||
"name": "rowid",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "Int",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"deprecationReason": null,
|
||||
"description": "Delete row in table \"songs\" by PK",
|
||||
"isDeprecated": false,
|
||||
"name": "delete_songs_by_pk",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "OBJECT",
|
||||
"name": "songs_mutation_by_pk_response",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
|
@ -1990,6 +2142,45 @@
|
|||
"name": "songs_set_input",
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"description": "Response for a PK-based mutation on table \"users\"",
|
||||
"enumValues": null,
|
||||
"fields": [
|
||||
{
|
||||
"args": [],
|
||||
"deprecationReason": null,
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"name": "affected_rows",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "Int",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"deprecationReason": null,
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"name": "returning",
|
||||
"type": {
|
||||
"kind": "OBJECT",
|
||||
"name": "users_row",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"kind": "OBJECT",
|
||||
"name": "users_mutation_by_pk_response",
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"description": "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.",
|
||||
"enumValues": null,
|
||||
|
@ -2177,7 +2368,7 @@
|
|||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"description": "Mutation response for songs",
|
||||
"description": "Mutation response for table \"songs\"",
|
||||
"enumValues": null,
|
||||
"fields": [
|
||||
{
|
||||
|
@ -2435,6 +2626,45 @@
|
|||
"name": "users_insert_input",
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"description": "Response for a PK-based mutation on table \"songs\"",
|
||||
"enumValues": null,
|
||||
"fields": [
|
||||
{
|
||||
"args": [],
|
||||
"deprecationReason": null,
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"name": "affected_rows",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "Int",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"deprecationReason": null,
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"name": "returning",
|
||||
"type": {
|
||||
"kind": "OBJECT",
|
||||
"name": "songs_row",
|
||||
"ofType": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"inputFields": null,
|
||||
"interfaces": [],
|
||||
"kind": "OBJECT",
|
||||
"name": "songs_mutation_by_pk_response",
|
||||
"possibleTypes": null
|
||||
},
|
||||
{
|
||||
"description": null,
|
||||
"enumValues": null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue