I use NestJj,PostgreSQL and Graphql for Back-End,
Flutter,graphql_flutter for Front End.
I have a collection store like this :
I want to get the following result:
[
    {
        type:'A',
        details:[
            {name:'Food1'}    
        ]
    },
    {
        type:'Expense',
        details:[
            {name:'gym'},
            {name:'Dinner'}
        ]
    },
    {
        type:'Revenue',
        details:[
            {name:'Revenue'}    
        ]
    }
]
For show on the device :
 How can I query?
Could you help me?
How can I query?
Could you help me?

 
                        
I'm not sure if you'll be able to build that structure at the level of SQL. What you can do is to extract the data from the table wit the structure as it is and then map it at the level of JS.
P.S. I'm pretty sure that's not the answer you've expected but it will solve your issue.