使用graphql查询连接3个表

问题描述 投票:1回答:1

我想加入3个表,就像我们在基于主键和外键的mysql中一样。

我可以使用graphql(http://graphql.org/)这样做我的表结构以及graphql查询如下。谢谢

query($companyId:String){
  Data{
    reach{
     department {
       departmentId
       departmentName
       description
     }
      companyDepartment(companyId:$companyId) {
        primaryId
        departmentId
        companyId
        createdDate
        modifiedDate
        modifiedBy
      }
      company(companyId:$companyId) {
        companyId
        companyName
      }
    }
  }
}
graphql graphql-js express-graphql
1个回答
1
投票

你必须打破思路,用Graph方式模型思考:)

类型公司(节点)< - CompanyDepartmentConection(连接边缘的名称) - >类型部门(节点)

基于这个非常有用的article,无论如何我会为你做的,例如。架构

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
}
© www.soinside.com 2019 - 2024. All rights reserved.