Skip to content

Putting data on edges (or not) #52

@eapache-opslevel

Description

@eapache-opslevel

This is a design topic which has been discussed a bunch internally at my current company, and which is not addressed in the design tutorial. IIRC at Shopify we ended up at (what I believe to be) the correct answer without much discussion and never really thought about it, but in hindsight I think that was a fluke, and it's worth making an official design ruling on. This should probably be worked into the design tutorial, or tacked on as another appendix or something.

My current belief is:

While there are some cases where putting data directly on connection edge types is OK, there are many where it ends up causing issues, and should be avoided; it is best to adopt the simple rule never to put data on edge types. This may result in a few extra types in the schema, but simplifies reading/interpretation because it becomes safe to assume that edge types are always just boilerplate and can be safely ignored.

The cases where putting data on edges can cause issues include:

  • When you have a many-to-many relation, with connections running both ways from A to B and also from B to A. Putting data directly on the edge would require you to duplicate fields between the A-to-B-edge type and the B-to-A-edge type.
  • When you have several types (A, B, C), all with one-to-many relationships to the same type (X). This is solvable, but you would have to remember to create/use AXEdge and BXEdge etc. instead of the standard/default generated XEdge, which can't reasonably have edge-data for two or more different relationships.
  • When you have a mutation operating on the relationship between an A and a B, in which case that mutation would have to duplicate fields from the edge type, or return an edge type directly (in addition to whichever of A or B isn't covered by the edge), which is gross.
  • Probably others I'm not thinking of right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions