diff --git a/server/src-lib/Hasura/RQL/GBoolExp.hs b/server/src-lib/Hasura/RQL/GBoolExp.hs index cd91580ea7c91..6dbd0a09dfe43 100644 --- a/server/src-lib/Hasura/RQL/GBoolExp.hs +++ b/server/src-lib/Hasura/RQL/GBoolExp.hs @@ -267,8 +267,8 @@ mkColCompExp mkColCompExp qual lhsCol = \case AEQ val -> equalsBoolExpBuilder lhs val ANE val -> notEqualsBoolExpBuilder lhs val - AIN vals -> S.BEEqualsAny lhs vals - ANIN vals -> S.BENot $ S.BEEqualsAny lhs vals + AIN vals -> handleEmptyAny vals + ANIN vals -> S.BENot $ handleEmptyAny vals AGT val -> S.BECompare S.SGT lhs val ALT val -> S.BECompare S.SLT lhs val AGTE val -> S.BECompare S.SGTE lhs val @@ -299,6 +299,9 @@ mkColCompExp qual lhsCol = \case toTextArray arr = S.SETyAnn (S.SEArray $ map (txtEncoder . PGValText) arr) S.textArrType + handleEmptyAny [] = S.BELit False + handleEmptyAny vals = S.BEEqualsAny lhs vals + getColExpDeps :: QualifiedTable -> AnnBoolExpFld a -> [SchemaDependency] getColExpDeps tn = \case AVCol colInfo _ -> diff --git a/server/tests-py/queries/graphql_query/boolexp/basic/select_author_article_where_in_empty_array.yaml b/server/tests-py/queries/graphql_query/boolexp/basic/select_author_article_where_in_empty_array.yaml new file mode 100644 index 0000000000000..62a7d9faebd80 --- /dev/null +++ b/server/tests-py/queries/graphql_query/boolexp/basic/select_author_article_where_in_empty_array.yaml @@ -0,0 +1,20 @@ +description: Select author and their articles (in empty array) +url: /v1alpha1/graphql +status: 200 +response: + data: + author: [] +query: + query: | + query { + author ( + where: {name: {_in: [] }} + ) { + name + articles{ + id + title + content + } + } + } diff --git a/server/tests-py/queries/graphql_query/boolexp/basic/select_author_article_where_nin_empty_array.yaml b/server/tests-py/queries/graphql_query/boolexp/basic/select_author_article_where_nin_empty_array.yaml new file mode 100644 index 0000000000000..5494506e97fb1 --- /dev/null +++ b/server/tests-py/queries/graphql_query/boolexp/basic/select_author_article_where_nin_empty_array.yaml @@ -0,0 +1,39 @@ +description: Select author and their articles (not in empty array) +url: /v1alpha1/graphql +status: 200 +response: + data: + author: + - name: Author 1 + articles: + - id: 1 + title: Article 1 + content: Sample article content 1 + - id: 2 + title: Article 2 + content: Sample article content 2 + - name: Author 2 + articles: + - id: 3 + title: Article 3 + content: Sample article content 3 + - name: Author 3 + articles: + - id: 4 + title: Article 4 + content: Sample article content 4 + +query: + query: | + query { + author ( + where: {name: {_nin: [] }} + ) { + name + articles{ + id + title + content + } + } + } diff --git a/server/tests-py/test_graphql_queries.py b/server/tests-py/test_graphql_queries.py index edf323d6fce86..d06a98636f689 100644 --- a/server/tests-py/test_graphql_queries.py +++ b/server/tests-py/test_graphql_queries.py @@ -145,6 +145,12 @@ def test_author_article_where_less_than_or_equal(self, hge_ctx): def test_author_article_where_in(self, hge_ctx): check_query_f(hge_ctx, self.dir() + '/select_author_article_where_in.yaml') + def test_author_article_where_in_empty_array(self, hge_ctx): + check_query_f(hge_ctx, self.dir() + '/select_author_article_where_in_empty_array.yaml') + + def test_author_article_where_nin_empty_array(self, hge_ctx): + check_query_f(hge_ctx, self.dir() + '/select_author_article_where_nin_empty_array.yaml') + def test_author_article_where_nin(self, hge_ctx): check_query_f(hge_ctx, self.dir() + '/select_author_article_where_nin.yaml')