Owais
Owais

Reputation: 860

join 3 tables using graphql query

I want to join 3 tables just like we do in mysql based on primary and foreign keys.

Can I do such using graphql(http://graphql.org/) My table structure along with graphql query is below. Thanks

query($companyId:String){
  Data{
    reach{
     department {
       departmentId
       departmentName
       description
     }
      companyDepartment(companyId:$companyId) {
        primaryId
        departmentId
        companyId
        createdDate
        modifiedDate
        modifiedBy
      }
      company(companyId:$companyId) {
        companyId
        companyName
      }
    }
  }
}

Upvotes: 1

Views: 5147

Answers (1)

AgBorkowski
AgBorkowski

Reputation: 1071

You must break your mind and think in Graph way model :)

Type Company(node) <- CompanyDepartmentConection (name of connection edge) -> Type Department(node)

based on this very useful article, anyway i do for you eg. Schema

Concept

interface Node {
  id: ID!
  name: String
}

type Company implements Node {
  id: ID!
  name: String
  departmentsConnection: CompanyDepartmentConnection
}
type CompanyDepartmentConnection {
  pageInfo: PageInfo!
  edges: [CompanyDepartmentEdge]
}
type CompanyDepartmentEdge {
  cursor: String!
  node: Company
  linkedAt: DateTime
}

Upvotes: 3

Related Questions