Tallyb / loopback-graphql

Adding graphql to loopback, based on Apollo Server
MIT License
201 stars 18 forks source link

Support relation of "through model" #13

Open JonnyBGod opened 7 years ago

JonnyBGod commented 7 years ago

Just a placeholder for tracking since it is difficult to track from project.

MichaelPlaxico commented 7 years ago

@JonnyBGod, @Tallyb, just to be sure, currently, attempting to query a relation with this structure is unsupported? I guess I should also ask--is this package being supported any longer? Seems to have been abandoned.

graphQL

{
  user(id: "59e943fe9c2121128398230b") {
    roles {
      totalCount
      roles {
        id
        name
      }
    }
  } 
}

user.json

...
  "relations": {
    "roles": {
      "type": "hasMany",
      "model": "role",
      "through": "userRole",
      "foreignKey": "userId"
    }
  },

...

role.json

...
  "relations": {
    "users": {
      "type": "hasMany",
      "model": "user",
      "through": "userRole",
      "foreignKey": "roleId"
    }
  },
...

user-role.json

...
  "relations": {
    "roles": {
      "type": "belongsTo",
      "model": "role",
      "foreignKey": "roleId"
    },
    "users": {
      "type": "belongsTo",
      "model": "user",
      "foreignKey": "userId"
    }
  },
...