mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
Return correct type when an update_many has no arguments
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10954 GitOrigin-RevId: 214163f4f4764ea66194bf26bfe202a807771e90
This commit is contained in:
parent
e34620a5f3
commit
4e6394355d
@ -121,6 +121,7 @@ tests = do
|
||||
}
|
||||
]
|
||||
) {
|
||||
affected_rows
|
||||
returning {
|
||||
id
|
||||
title
|
||||
@ -134,6 +135,7 @@ tests = do
|
||||
[interpolateYaml|
|
||||
data:
|
||||
insert_#{schemaName}_article:
|
||||
affected_rows: 2
|
||||
returning:
|
||||
- id: 1
|
||||
title: "Article 1"
|
||||
@ -156,6 +158,7 @@ tests = do
|
||||
insert_#{schemaName}_article(
|
||||
objects: []
|
||||
) {
|
||||
affected_rows
|
||||
returning {
|
||||
id
|
||||
title
|
||||
@ -169,6 +172,7 @@ tests = do
|
||||
[interpolateYaml|
|
||||
data:
|
||||
insert_#{schemaName}_article:
|
||||
affected_rows: 0
|
||||
returning: []
|
||||
|]
|
||||
|
||||
|
@ -69,6 +69,29 @@ schema =
|
||||
tests :: SpecWith TestEnvironment
|
||||
tests = do
|
||||
describe "Update many objects" do
|
||||
it "When no updates are provided" \testEnvironment -> do
|
||||
let expected :: Value
|
||||
expected =
|
||||
[yaml|
|
||||
data:
|
||||
update_hasura_author_many: []
|
||||
|]
|
||||
|
||||
actual :: IO Value
|
||||
actual =
|
||||
postGraphql
|
||||
testEnvironment
|
||||
[graphql|
|
||||
mutation {
|
||||
update_hasura_author_many(
|
||||
updates: []
|
||||
) {
|
||||
affected_rows
|
||||
}
|
||||
}
|
||||
|]
|
||||
|
||||
shouldReturnYaml testEnvironment actual expected
|
||||
it "When many equals zero" \testEnvironment -> do
|
||||
let expected :: Value
|
||||
expected =
|
||||
|
@ -45,7 +45,7 @@ import Hasura.Backends.Postgres.Translate.Select qualified as DS
|
||||
import Hasura.Backends.Postgres.Types.Function qualified as Postgres
|
||||
import Hasura.Backends.Postgres.Types.Update qualified as Postgres
|
||||
import Hasura.Base.Error (QErr)
|
||||
import Hasura.EncJSON (EncJSON, encJFromJValue)
|
||||
import Hasura.EncJSON (EncJSON, encJFromJValue, encJFromList)
|
||||
import Hasura.Function.Cache
|
||||
import Hasura.GraphQL.Execute.Backend
|
||||
( BackendExecute (..),
|
||||
@ -307,7 +307,9 @@ convertUpdate sourceName modelSourceType env manager logger userInfo updateOpera
|
||||
pure $ concat whereModelsList
|
||||
let modelNames = [ModelNameInfo (modelName, modelType, sourceName, modelSourceType)] <> (argModelNames) <> preUpdatePermissionModelNames <> postUpdateCheckModelNames <> (returnModels)
|
||||
if Postgres.updateVariantIsEmpty $ IR._auUpdateVariant updateOperation
|
||||
then pure $ (OnBaseMonad $ pure $ IR.buildEmptyMutResp $ IR._auOutput preparedUpdate, modelNames)
|
||||
then case mutationUpdateVariant of
|
||||
Postgres.SingleBatch _ -> pure $ (OnBaseMonad $ pure $ IR.buildEmptyMutResp (IR._auOutput preparedUpdate), modelNames)
|
||||
Postgres.MultipleBatches _ -> pure (OnBaseMonad $ pure (encJFromList []), modelNames)
|
||||
else
|
||||
pure
|
||||
$ ( OnBaseMonad
|
||||
|
Loading…
Reference in New Issue
Block a user