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,
- First of all, is GraphQL even the right solution, or is RestAPI better solution. Am asking purely from design point of view.
- 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.