这是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
11 changes: 5 additions & 6 deletions server/src-lib/Hasura/RQL/DML/Select/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ data BaseNode
txtToAlias :: Text -> S.Alias
txtToAlias = S.Alias . Iden

aggFldToExp :: Iden -> AggFlds -> S.SQLExp
aggFldToExp pfx aggFlds = jsonRow
aggFldToExp :: AggFlds -> S.SQLExp
aggFldToExp aggFlds = jsonRow
where
jsonRow = S.applyJsonBuildObj (concatMap aggToFlds aggFlds)
withAls fldName sqlExp = [S.SELit fldName, sqlExp]
Expand All @@ -177,7 +177,7 @@ aggFldToExp pfx aggFlds = jsonRow

colFldsToExtr op (t, PCFCol col) =
[ S.SELit t
, S.SEFnApp op [S.SEIden $ mkBaseTableColAls pfx col] Nothing
, S.SEFnApp op [S.SEIden $ toIden col] Nothing
]
colFldsToExtr _ (t, PCFExp e) =
[ S.SELit t , S.SELit e]
Expand Down Expand Up @@ -397,8 +397,7 @@ aggSelToAggNode pfx als aggSel =
mkBaseNode pfx (FieldName t) selFld tabFrm tabPerm tabArgs

selFldToExtr (t, fld) = (:) (S.SELit t) $ pure $ case fld of
TAFAgg flds ->
aggFldToExp pfx flds
TAFAgg flds -> aggFldToExp flds
TAFNodes _ ->
let jsonAgg = S.SEFnApp "json_agg" [S.SEIden $ Iden t] ordBy
in S.SEFnApp "coalesce" [jsonAgg, S.SELit "[]"] Nothing
Expand Down Expand Up @@ -454,7 +453,7 @@ mkBaseNode pfx fldAls annSelFlds tableFrom tablePerm tableArgs =

mkColExp (PCFCol c) =
let qualCol = S.mkQIdenExp (mkBaseTableAls pfx) (toIden c)
colAls = mkBaseTableColAls pfx c
colAls = toIden c
in Just (S.Alias colAls, qualCol)
mkColExp _ = Nothing

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
description: Deeply nested query with aggregate select
url: /v1alpha1/graphql
status: 200
response:
data:
article:
- id: 1
title: Article 1
content: Sample article content 1
author:
id: 1
name: Author 1
articles:
- id: 1
title: Article 1
content: Sample article content 1
author:
articles_aggregate:
aggregate:
count: 2
avg:
author_id: 1
nodes:
- id: 1
title: Article 1
content: Sample article content 1
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
articles_aggregate:
aggregate:
count: 2
avg:
author_id: 1
nodes:
- id: 1
title: Article 1
content: Sample article content 1
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
id: 1
name: Author 1
articles:
- id: 1
title: Article 1
content: Sample article content 1
author:
articles_aggregate:
aggregate:
count: 2
avg:
author_id: 1
nodes:
- id: 1
title: Article 1
content: Sample article content 1
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
articles_aggregate:
aggregate:
count: 2
avg:
author_id: 1
nodes:
- id: 1
title: Article 1
content: Sample article content 1
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 2
title: Article 2
content: Sample article content 2
author:
id: 1
name: Author 1
articles_aggregate:
aggregate:
count: 2
max:
author_id: 1
- id: 3
title: Article 3
content: Sample article content 3
author:
id: 2
name: Author 2
articles:
- id: 3
title: Article 3
content: Sample article content 3
author:
articles_aggregate:
aggregate:
count: 1
avg:
author_id: 2
nodes:
- id: 3
title: Article 3
content: Sample article content 3
author:
id: 2
name: Author 2
articles_aggregate:
aggregate:
count: 1
max:
author_id: 2

query:
query: |
query {
article{
id
title
content
author{
id
name
articles{
id
title
content
author{
articles_aggregate{
aggregate{
count
avg{
author_id
}
}
nodes{
id
title
content
author{
id
name
articles_aggregate{
aggregate{
count
max{
author_id
}
}
}
}
}
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions server/tests-py/test_graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def test_author_agg_with_articles(self, hge_ctx):
def test_author_agg_with_articles_where(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/author_agg_with_articles_where.yaml')

def test_article_deeply_nested_aggregate(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/article_deeply_nested_aggregate.yaml')

@classmethod
def dir(cls):
return 'queries/graphql_query/aggregations'
Expand Down