nestjs +graphQL - nested response shape for data from same table

Viewed 51

I am trying to create a nestjs + graphql API which would pull the data from database based on user's request. I am following code first approach. I have to expose an API which would return the below nested response shape, though the all data are from single table.

Table Columns: EmployeeNo, departmentId, DepartmentName

Expected Response Shape:

{
EmployeeNo
  Department {
            departmentId, 
            DepartmentName
   }
}

I used TypeORM and trying to figure out how to have nestjs+graphql return response shape like above hen all the fields are available in single table as different columns. Do I need to have two entities pointing to same table? will it work?

Any suggestion would be helpful. Thanks in Advance!

0 Answers
Related