@@ -111,6 +111,20 @@ interface MultiIndexFieldQueryRequest {
111111 accessibility ?: Accessibility ;
112112}
113113
114+ interface FieldAggregation {
115+ histogram : AggregationsData ;
116+ totalCount : number ;
117+ }
118+
119+ interface IndexAggregation {
120+ [ field : string ] : FieldAggregation | number ;
121+ totalCount : number ;
122+ }
123+
124+ interface MultiIndexFieldAggregationResponse {
125+ [ index : string ] : IndexAggregation ;
126+ }
127+
114128export const explorerTags = guppyApi . enhanceEndpoints ( {
115129 addTagTypes : [ 'AGGS' , 'COUNTS' , 'STATS' , 'TABLE_DATA' , 'RAW_DATA' ] as const ,
116130} ) ;
@@ -463,8 +477,10 @@ export const explorerApi = explorerTags.injectEndpoints({
463477 _meta ,
464478 args ,
465479 ) : number => {
480+ if ( ! ( 'data' in response ) || ! response . data ) return 0 ;
481+
466482 return (
467- response ?. data [ `${ args ?. indexPrefix ?? '' } _aggregation` ] [ args . type ]
483+ response ?. data ?. [ `${ args ?. indexPrefix ?? '' } _aggregation` ] [ args . type ]
468484 ?. _totalCount ?? 0
469485 ) ;
470486 } ,
@@ -617,7 +633,7 @@ export const explorerApi = explorerTags.injectEndpoints({
617633 } ,
618634 } ) ,
619635 getGetMultiIndexAggregation : builder . query <
620- Record < string , any > ,
636+ MultiIndexFieldAggregationResponse ,
621637 MultiIndexFieldQueryRequest
622638 > ( {
623639 query : ( {
@@ -632,17 +648,23 @@ export const explorerApi = explorerTags.injectEndpoints({
632648 } ,
633649 { } as Record < string , GQLFilter > ,
634650 ) ;
635- const query = buildMultiIndexAggregationQuery ( indexAndFields ) ;
651+ const query = buildMultiIndexAggregationQuery (
652+ indexAndFields ,
653+ accessibility ,
654+ ) ;
636655 return {
637656 query,
638657 variables : {
639658 ...filters ,
640- accessibility,
641659 } ,
642660 } ;
643661 } ,
644- transformResponse : ( response : Record < string , any > ) => {
645- return response ?. data ?. _aggregation ?? { } ;
662+ transformResponse : ( response : {
663+ data : { _aggregation ?: IndexAggregation } ;
664+ } ) => {
665+ if ( ! response ?. data ?. _aggregation ) return { } ;
666+
667+ return response . data . _aggregation ;
646668 } ,
647669 } ) ,
648670 generalGQL : builder . query < Record < string , unknown > , guppyApiSliceRequest > ( {
@@ -676,18 +698,18 @@ export const useGetIndexFields = (index: string, indexPrefix = '') => {
676698
677699const buildMultiIndexAggregationQuery = (
678700 indexesAndFields : Array < QueryAggsParams > ,
701+ accessibility = Accessibility . ALL ,
679702 filterBasename : string = 'filter' ,
680703) => {
681704 const filterNames = indexesAndFields . reduce (
682705 ( acc , curr ) => acc + `$${ curr . type } ${ filterBasename } : JSON,` ,
683706 '' ,
684707 ) ;
685708
686- let queryString = `query getAggs (${ filterNames } ) {` ;
709+ let queryString = `query getMultiIndexAggs (${ filterNames } ) {` ;
687710
688711 indexesAndFields . forEach ( ( indexQuery ) => {
689- queryString += ` ${ indexQuery . type } _aggregation {
690- ${ indexQuery . type } (filter: ${ indexQuery . type } ${ filterBasename } , filterSelf: ${ indexQuery . filterSelf ? 'true' : 'false' } , accessibility: ${ indexQuery . accessibility } ) { _totalCount
712+ queryString += ` ${ indexQuery . indexPrefix ?? '' } _aggregation { ${ indexQuery . type } (filter: $${ indexQuery . type } ${ filterBasename } , filterSelf: ${ indexQuery . filterSelf ? 'true' : 'false' } , accessibility: ${ accessibility } ) { totalCount:_totalCount
691713 ` ;
692714 queryString += indexQuery . fields . map ( ( field : string ) =>
693715 histogramQueryStrForEachField ( field ) ,
0 commit comments