How to group GraphQL query result with individual key as array

337 Views Asked by At

I'm using GraphQL with .NET Core. I have query like below. As I'm new in GraphQL.NET, I can't understand how to group individual key as array.

`{
    readingQuery{
             readingsDBFilter(buildingId: 30, objectId: 1, datafieldId: 1, startTime: "02-05-201812-00-00-AM", endTime: "30-05-201811-59-00-PM"){
                             value,
                            unix
                        }
    }
}`    

I have Output Like this

`{
    "data": {
        "readingQuery": {
            "readingsDBFilter": [
               {
                    "value": 0.66,
                    "unix": 1525254180000
                },
                {
                    "value": 0.68,
                    "unix": 1525254240000
                }
           ]
       }
   }
}`

But, Is it possible to return result like this from query.

`{
    "data": {
        "readingQuery": {
            "readingsDBFilter": [
                {
                    "value":[ 0.66, 0.68],
                    "unix": [1525254180000, 1525254240000]
                }
            ]
        }
    }
}`
1

There are 1 best solutions below

0
On

Looks like you need to group values from different records I guess you have two option here 1) try to group it on SQL level (maybe better to create dateview) 2) do it on runtime level, in code. from my point of view - it's bad. any grouping in code it's much slower then the same operation in db-level