mirror of
https://github.com/hasura/graphql-engine.git
synced 2025-01-07 08:13:18 +03:00
fix(server): skip insert when no values provided for SQLServer
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9564 GitOrigin-RevId: 7d95ee428b8da7e246d9f1040f04d8abe359b667
This commit is contained in:
parent
720a5a1aaf
commit
98fdeda54e
@ -16,7 +16,7 @@ test-bigquery: build remove-tix-file start-api-test-postgres
|
|||||||
|
|
||||||
.PHONY: test-sqlserver
|
.PHONY: test-sqlserver
|
||||||
## test-sqlserver: run tests for MS SQL Server backend
|
## test-sqlserver: run tests for MS SQL Server backend
|
||||||
test-sqlserver: build remove-tix-file start-api-test-backends
|
test-sqlserver: build remove-tix-file start-api-tests-backends
|
||||||
HASURA_TEST_BACKEND_TYPE=SQLServer \
|
HASURA_TEST_BACKEND_TYPE=SQLServer \
|
||||||
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
||||||
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
||||||
@ -24,7 +24,7 @@ test-sqlserver: build remove-tix-file start-api-test-backends
|
|||||||
|
|
||||||
.PHONY: test-citus
|
.PHONY: test-citus
|
||||||
## test-citus: run tests for Citus backend
|
## test-citus: run tests for Citus backend
|
||||||
test-citus: build remove-tix-file start-api-test-backends
|
test-citus: build remove-tix-file start-api-tests-backends
|
||||||
HASURA_TEST_BACKEND_TYPE=Citus \
|
HASURA_TEST_BACKEND_TYPE=Citus \
|
||||||
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
||||||
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
||||||
@ -32,7 +32,7 @@ test-citus: build remove-tix-file start-api-test-backends
|
|||||||
|
|
||||||
.PHONY: test-data-connectors
|
.PHONY: test-data-connectors
|
||||||
## test-data-connectors: run tests for Data Connectors
|
## test-data-connectors: run tests for Data Connectors
|
||||||
test-data-connectors: build remove-tix-file start-api-test-backends
|
test-data-connectors: build remove-tix-file start-api-tests-backends
|
||||||
HASURA_TEST_BACKEND_TYPE=DataConnector \
|
HASURA_TEST_BACKEND_TYPE=DataConnector \
|
||||||
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
||||||
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
||||||
@ -40,7 +40,7 @@ test-data-connectors: build remove-tix-file start-api-test-backends
|
|||||||
|
|
||||||
.PHONY: test-cockroach
|
.PHONY: test-cockroach
|
||||||
## test-cockroach: run tests for Cockroach backend
|
## test-cockroach: run tests for Cockroach backend
|
||||||
test-cockroach: build remove-tix-file start-api-test-backends
|
test-cockroach: build remove-tix-file start-api-tests-backends
|
||||||
HASURA_TEST_BACKEND_TYPE=Cockroach \
|
HASURA_TEST_BACKEND_TYPE=Cockroach \
|
||||||
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \
|
||||||
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
POSTGRES_AGENT=$(POSTGRES_AGENT_PATH) \
|
||||||
|
@ -150,3 +150,36 @@ tests = do
|
|||||||
|]
|
|]
|
||||||
|
|
||||||
shouldReturnYaml testEnvironment actual expected
|
shouldReturnYaml testEnvironment actual expected
|
||||||
|
|
||||||
|
it "Upsert with no objects does not break" \testEnvironment -> do
|
||||||
|
let expected :: Value
|
||||||
|
expected =
|
||||||
|
[yaml|
|
||||||
|
data:
|
||||||
|
insert_hasura_somedefaults:
|
||||||
|
affected_rows: 0
|
||||||
|
returning: []
|
||||||
|
|]
|
||||||
|
|
||||||
|
actual :: IO Value
|
||||||
|
actual =
|
||||||
|
postGraphql
|
||||||
|
testEnvironment
|
||||||
|
[graphql|
|
||||||
|
mutation {
|
||||||
|
insert_hasura_somedefaults(
|
||||||
|
objects: []
|
||||||
|
if_matched: {
|
||||||
|
match_columns: name,
|
||||||
|
update_columns: []
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
affected_rows
|
||||||
|
returning {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
|
shouldReturnYaml testEnvironment actual expected
|
||||||
|
@ -12,6 +12,7 @@ import Data.List.NonEmpty qualified as NE
|
|||||||
import Harness.Backend.Citus qualified as Citus
|
import Harness.Backend.Citus qualified as Citus
|
||||||
import Harness.Backend.Cockroach qualified as Cockroach
|
import Harness.Backend.Cockroach qualified as Cockroach
|
||||||
import Harness.Backend.Postgres qualified as Postgres
|
import Harness.Backend.Postgres qualified as Postgres
|
||||||
|
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||||
import Harness.GraphqlEngine (postGraphql)
|
import Harness.GraphqlEngine (postGraphql)
|
||||||
import Harness.Quoter.Graphql (graphql)
|
import Harness.Quoter.Graphql (graphql)
|
||||||
import Harness.Quoter.Yaml (interpolateYaml)
|
import Harness.Quoter.Yaml (interpolateYaml)
|
||||||
@ -41,6 +42,11 @@ spec = do
|
|||||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||||
[ Cockroach.setupTablesAction schema testEnv
|
[ Cockroach.setupTablesAction schema testEnv
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
(Fixture.fixture $ Fixture.Backend Sqlserver.backendTypeMetadata)
|
||||||
|
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||||
|
[ Sqlserver.setupTablesAction schema testEnv
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -104,13 +110,11 @@ tests = do
|
|||||||
insert_#{schemaName}_article(
|
insert_#{schemaName}_article(
|
||||||
objects: [
|
objects: [
|
||||||
{
|
{
|
||||||
id: 1,
|
|
||||||
title: "Article 1",
|
title: "Article 1",
|
||||||
content: "Sample article content",
|
content: "Sample article content",
|
||||||
author_id: 1
|
author_id: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
|
||||||
title: "Article 2",
|
title: "Article 2",
|
||||||
content: "Sample article content",
|
content: "Sample article content",
|
||||||
author_id: 2
|
author_id: 2
|
||||||
|
@ -162,16 +162,20 @@ buildInsertTx tableName withAlias stringifyNum insert queryTags = do
|
|||||||
|
|
||||||
Tx.unitQueryE defaultMSSQLTxErrorHandler (createInsertedTempTableQuery `withQueryTags` queryTags)
|
Tx.unitQueryE defaultMSSQLTxErrorHandler (createInsertedTempTableQuery `withQueryTags` queryTags)
|
||||||
|
|
||||||
-- Choose between running a regular @INSERT INTO@ statement or a @MERGE@ statement
|
-- check we have any values to insert, SQLServer doesn't appear to have a
|
||||||
-- depending on the @if_matched@ field.
|
-- nice syntax for "insert no rows please"
|
||||||
--
|
unless (null $ _aiInsertObject $ _aiData insert)
|
||||||
-- Affected rows will be inserted into the #inserted temporary table regardless.
|
$
|
||||||
case ifMatchedField of
|
-- Choose between running a regular @INSERT INTO@ statement or a @MERGE@ statement
|
||||||
Nothing -> do
|
-- depending on the @if_matched@ field.
|
||||||
-- Insert values into the table using INSERT query
|
--
|
||||||
let insertQuery = toQueryFlat $ TQ.fromInsert $ TSQL.fromInsert insert
|
-- Affected rows will be inserted into the #inserted temporary table regardless.
|
||||||
Tx.unitQueryE mutationMSSQLTxErrorHandler (insertQuery `withQueryTags` queryTags)
|
case ifMatchedField of
|
||||||
Just ifMatched -> buildUpsertTx tableName insert ifMatched queryTags
|
Nothing -> do
|
||||||
|
-- Insert values into the table using INSERT query
|
||||||
|
let insertQuery = toQueryFlat $ TQ.fromInsert $ TSQL.fromInsert insert
|
||||||
|
Tx.unitQueryE mutationMSSQLTxErrorHandler (insertQuery `withQueryTags` queryTags)
|
||||||
|
Just ifMatched -> buildUpsertTx tableName insert ifMatched queryTags
|
||||||
|
|
||||||
-- Build a response to the user using the values in the temporary table named #inserted
|
-- Build a response to the user using the values in the temporary table named #inserted
|
||||||
(responseText, checkConditionInt) <- buildInsertResponseTx stringifyNum withAlias insert queryTags
|
(responseText, checkConditionInt) <- buildInsertResponseTx stringifyNum withAlias insert queryTags
|
||||||
@ -225,6 +229,7 @@ buildUpsertTx tableName insert ifMatched queryTags = do
|
|||||||
toQueryFlat
|
toQueryFlat
|
||||||
$ TQ.fromInsertValuesIntoTempTable
|
$ TQ.fromInsertValuesIntoTempTable
|
||||||
$ TSQL.toInsertValuesIntoTempTable tempTableNameValues insert
|
$ TSQL.toInsertValuesIntoTempTable tempTableNameValues insert
|
||||||
|
|
||||||
Tx.unitQueryE mutationMSSQLTxErrorHandler (insertValuesIntoTempTableQuery `withQueryTags` queryTags)
|
Tx.unitQueryE mutationMSSQLTxErrorHandler (insertValuesIntoTempTableQuery `withQueryTags` queryTags)
|
||||||
|
|
||||||
-- Run the MERGE query and store the mutated rows in #inserted temporary table
|
-- Run the MERGE query and store the mutated rows in #inserted temporary table
|
||||||
|
Loading…
Reference in New Issue
Block a user