这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/src-lib/Hasura/RQL/DML/Returning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ mkMutFldExp :: MutFld -> S.SQLExp
mkMutFldExp = \case
MCount -> S.SEUnsafe "count(*)"
MExp t -> S.SELit t
MRet retFlds -> S.SEFnApp "json_agg" [mkRetFldsExp retFlds] Nothing
MRet retFlds -> S.toEmptyArrWhenNull $
S.SEFnApp "json_agg" [mkRetFldsExp retFlds] Nothing

mkSelWith :: S.CTE -> MutFlds -> S.SelectWith
mkSelWith cte mutFlds =
Expand Down
5 changes: 2 additions & 3 deletions server/src-lib/Hasura/RQL/DML/Select.hs
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ wrapFinalSel initSel extCols =
}
where
rowExp = S.mkRowExp $ map mkInnerSelExtr extCols
rowToJSONedCol = S.SEFnApp "coalesce"
[ S.SEFnApp "json_agg" [rowExp] Nothing
, S.SELit "[]"] Nothing
rowToJSONedCol = S.toEmptyArrWhenNull $
S.SEFnApp "json_agg" [rowExp] Nothing

getSelectDeps
:: SelectData
Expand Down
3 changes: 3 additions & 0 deletions server/src-lib/Hasura/SQL/DML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ mkSQLOpExp
-> SQLExp -- result
mkSQLOpExp op lhs rhs = SEOpApp op [lhs, rhs]

toEmptyArrWhenNull :: SQLExp -> SQLExp
toEmptyArrWhenNull e = SEFnApp "coalesce" [e, SELit "[]"] Nothing

getExtrAlias :: Extractor -> Maybe Alias
getExtrAlias (Extractor _ ma) = ma

Expand Down
1 change: 1 addition & 0 deletions server/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ gqlSpecFiles =
, "update_mutation/person_inc.yaml"
, "update_mutation/person_error_01.yaml"
, "delete_mutation/article.yaml"
, "delete_mutation/article_returning.yaml"
]

readTestCase :: FilePath -> IO TestCase
Expand Down
15 changes: 15 additions & 0 deletions server/test/testcases/delete_mutation/article_returning.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description: Delete mutation on article with returning
url: /v1alpha1/graphql
status: 200
query:
query: |
mutation delete_article {
delete_article (
where: {id: {_eq: 5}}
) {
affected_rows
returning{
id
}
}
}