Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Preventing Leaking Through-Table Implementations #2278

Open
teddy-has-opinions opened this issue Mar 15, 2021 · 0 comments
Open

Preventing Leaking Through-Table Implementations #2278

teddy-has-opinions opened this issue Mar 15, 2021 · 0 comments
Labels
question Further information is requested

Comments

@teddy-has-opinions
Copy link

teddy-has-opinions commented Mar 15, 2021

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.

@teddy-has-opinions teddy-has-opinions added the question Further information is requested label Mar 15, 2021
@teddy-has-opinions teddy-has-opinions changed the title Preventing Leaking Through-Table Abstractions Preventing Leaking Through-Table Implementations Mar 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant