server/mssql: fix table_by_pk query returning empty array

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2810
GitOrigin-RevId: ed8e694d491d7bd28da0b39da2b1f1150d2e3735
This commit is contained in:
Rakesh Emmadi 2021-11-10 11:01:43 +05:30 committed by hasura-bot
parent ec60386f9c
commit 95be515a60
4 changed files with 42 additions and 10 deletions

View File

@ -9,6 +9,8 @@
### Bug fixes and improvements
(Add entries below in the order of server, console, cli, docs, others)
- server: fix mssql `table_by_pk` query returning empty array (fix #7784)
## v2.1.0-beta.2
### Action transforms

View File

@ -496,12 +496,23 @@ parens p = "(" <+> IndentPrinter 1 p <+> ")"
-- | Wrap a select with things needed when using FOR JSON.
wrapFor :: For -> Printer -> Printer
wrapFor for' inner = nullToArray
wrapFor for' inner = coalesceNull
where
nullToArray =
coalesceNull =
case for' of
NoFor -> rooted
JsonFor _ -> SeqPrinter ["SELECT ISNULL((", rooted, "), '[]')"]
JsonFor forJson ->
SeqPrinter
[ "SELECT ISNULL((",
rooted,
"), '",
emptyarrayOrNull forJson,
"')"
]
emptyarrayOrNull ForJson {..} =
case jsonCardinality of
JsonSingleton -> "null"
JsonArray -> "[]"
rooted =
case for' of
JsonFor ForJson {jsonRoot, jsonCardinality = JsonSingleton} ->

View File

@ -0,0 +1,14 @@
description: select query on author with id = 4
url: /v1/graphql
status: 200
response:
data:
author_by_pk: null
query:
query: |
query {
author_by_pk(id: 4){
id
name
}
}

View File

@ -306,7 +306,6 @@ class TestGraphQLQueryBasicCommon:
def test_select_query_multiple_columns_obj_fkey(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/select_multiple_columns_obj_fkey.yaml", transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'
@ -331,6 +330,12 @@ class TestGraphQLQueryBasicMSSQL:
def test_nodes_aggregates_conditions_mssql(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + "/nodes_aggregates_conditions_mssql.yaml", transport)
def test_select_query_author_pk(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_author_by_pkey.yaml', transport)
def test_select_query_author_pk_null(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_author_by_pkey_null.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'
@ -344,12 +349,6 @@ class TestGraphQLQueryBasicPostgres:
def test_select_various_postgres_types(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_test_types_postgres.yaml', transport)
# TODO: https://github.com/hasura/graphql-engine-mono/issues/866
# This test currently fails on MSSQL.
# Move to TestGraphQLQueryBasicCommon once linked issue is fixed.
def test_select_query_author_pk(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_author_by_pkey.yaml', transport)
def test_select_query_invalid_escape_sequence(self, hge_ctx, transport):
transport = 'http'
check_query_f(hge_ctx, self.dir() + "/select_query_invalid_escape_sequence.yaml", transport)
@ -384,6 +383,12 @@ class TestGraphQLQueryBasicPostgres:
assert st_code == 400, resp
assert resp['error'] == "Expecting object { table, columns }."
def test_select_query_author_pk(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_author_by_pkey.yaml', transport)
def test_select_query_author_pk_null(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_author_by_pkey_null.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'