GraphQL (GroupBy fieldname) in SpringBoot and MySQL

GraphQL (GroupBy fieldname) in SpringBoot and MySQL


0

I have just started to learn GraphQL, I am using GraphQL with SpringBoot and MySQL.
I have a table in MySQL, "Employee" which looks as follows

ID NAME EXPERIENCE DEPARTMENT_NAME
1 Alex 7 Sales
2 Josh 6 Marketing
3 Hans 3 Sales
4 Max 8 Marketing

and ofcourse i have POJO in SpringBoot

class Employee {
  
   Long ID;
  String NAME;
  Integer EXPERIENCE;
  String DEPARTMENT_NAME

  //getters setters

}

I want to get all Employees by
a) grouping it based on DEPARTMENT NAME and
b) inside each group i want to sort by EXPERIENCE in descending order
in GraphQL Response like shown below (Notice that field DEPARTMENT NAME is not inside nested fields)

{
  "Sales": [
    {
      "ID": 1,
      "NAME": "Alex",
      "EXPERIENCE": 7
    },
    {
      "ID": 3,
      "NAME": "Hans",
      "EXPERIENCE": 3
    }
  ],
  
  
  "Marketing": [
    {
      "ID": 4,
      "NAME": "Max",
      "EXPERIENCE": 8
    },
    {
      "ID": 2,
      "NAME": "Josh",
      "EXPERIENCE": 6
    }
  ]
}

My Question is,

  1. First of all, is GraphQL even the right solution, or is RestAPI better solution. Am asking purely from design point of view.
  2. Is writing GraphQLResolver<> the only approach for this, if yes, can you suggest me how to go about it, or any resource?

I tried searching if there are any answers related to this on StackOverflow, I found few related ones but it did not answer the question correctly.


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *