Description
Hello, I've been working on a new app, and spent quite a bit of time trying to figure out a good way to resolve this issue, but was unable to. Our team is pretty new to GraphQL and Graphback, so I might have missed something obvious here. We've got a few many-to-many relationships in our DB that use through tables, and we've noticed that as it stands, that implementation is leaking into the FE clients in a way that's making it hard to read/update/manipulate those relationships:
type CommodityTypesTrucks implements Node {
id: ID!
commodityType: CommodityType!
truck: Truck!
}
type CommodityType implements Node {
id: ID!
"""
@index
"""
shipper: Shipper!
"""
@oneToMany(field: 'commodityType')
"""
truck: [CommodityTypesTrucks!]!
}
type Truck {
id: ID!
shipper: Shipper!
name: String!
"""
@oneToMany(field: 'truck')
"""
commodityTypes: [CommodityTypesTrucks!]!
}
We've built the schema in this way based on the recommendation here, but in the generated CRUD API, this through table is actually exposed, so queries are required to look like:
query {
getTruck(id:1) {
commodityTypes: {
commodityType: {
id,
name,
}
}
}
}
Additionally, creating a new relationship seems to require a custom mutation unless we want to expose the creation of that through-table row to the frontend.
I'm wondering if exposing the implementation of a many-to-many relationship like this to clients is expected, as I certainly didn't expect it, and whether there's a way to collapse that relationship by default when generating the schema/CRUD API.