8000 Preventing Leaking Through-Table Implementations · Issue #2278 · aerogear/graphback · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
Preventing Leaking Through-Table Implementations #2278
Open
@teddy-has-opinions

Description

@teddy-has-opinions

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0