Prisma1: Relation metadata

Created on 24 Feb 2017  路  9Comments  路  Source: prisma/prisma1

After reading Apollo's latest article, what is called in Graphcool a Relation (a term I guess coming from the world of relational databases) sounds actually pretty similar to the term Connection used in GraphQL, esp. Relay. Are these named intentionally differently, or should they be seen as synonyms?

Anyway I'd like to be able to add metadata to a Relation, which currently doesn't seem possible. E.g if I have a Module with several Tracks, I could add an addedAt property to their relation. Or if I have a User who can listen to various Tracks, I'd like to add metadata like playCount or lastPlayedAt.

areapi

Most helpful comment

Yes, of course I understand that workaround. But I do think it is a valid and valuable feature, to have a clear concept of connection with metadata provided to the user. Also in a backend of any reasonable size, it will not be very manageable to have models and meta-models all floating around in a flat list. In terms of namespace and mental model, it appears more logical to me to edit connection metadata directly in the Relations panel.

I'm a bit puzzled as to why this got closed so fast. The choice as to what should be or not be in the GraphQL spec is one thing, and what should be in the Graphcool console is another. I do think this is a valid feature request, even if you may consider it too early as it might not be a priority when you're trying to first target small projects.

All 9 comments

A GraphQL schema consists of queries and mutations that rely on certain types, like object types, scalars and so on. Models or relations are not defined as part of the GraphQL spec, but are used as an intermediate step that allows you to describe your data model that will be mapped to an automatically
generated GraphQL schema.

In your situation, you would create a CourseModule model, a CourseTracks model and TrackAddition model for example that acts as a meta model for the relation. In this model you can add the addedAt field and a one-to-many relation to CourseModule and a one-to-one relation to CourseTracks, so one CourseModule has many TrackAddition nodes, while a TrackAddition node has one CourseTracks node.

Yes, of course I understand that workaround. But I do think it is a valid and valuable feature, to have a clear concept of connection with metadata provided to the user. Also in a backend of any reasonable size, it will not be very manageable to have models and meta-models all floating around in a flat list. In terms of namespace and mental model, it appears more logical to me to edit connection metadata directly in the Relations panel.

I'm a bit puzzled as to why this got closed so fast. The choice as to what should be or not be in the GraphQL spec is one thing, and what should be in the Graphcool console is another. I do think this is a valid feature request, even if you may consider it too early as it might not be a priority when you're trying to first target small projects.

I'm sorry, closing the feature request was overly hasty. I'm currently preparing an FAQ article of how to handle this situation the best way with the current options, so in my mind I had solved this feature request.

However, I agree that our current mental model of connections/relations is not easy enough in some cases (at least those that need additional information per connected nodes) and we should explore how to simplify these situations. So thanks for your feedback on this! :slightly_smiling_face:

Update: FAQ article

Other case mentioned in https://github.com/graphcool/console/issues/1016: store in the connection metadata the order of related nodes.

This could also be used to order items in a relation directly without the need of managing it yourself with an integer field (position, for example), or an ordered list of ids.

Also a +1 on this from me. Metadata that belongs to the 'edge' should be defined on that type. Forcing towards a 'meta-type' is overly complicated.

I'm currently using the workaround listed in marktani's answer for issue #1016

However, the ordering is on the relationship, and not embedded in either the parent or the child, especially for MxN. Having an intermediate entity each time I need ordering is becoming painful as I need to create a new entity for each ordered relationship, and then I need to add the code to manage the ordering. And its another level of selection before you get to the entity you require. So far I haven refactored that out as I've yet to work out the commonalities to make this less painful.

The ability to select the related individual types and have their order preserved in the JS Array on output seems to be fundamental and how JS works. I expect that an array [1, 2, 3 ] always returns the same order and thus the UI should also allow selecting, storing (as relationship metadata) and reordering of selected items at minimum. +1

Please continue discussion on this proposal https://github.com/graphcool/graphcool/issues/746

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomaswright picture thomaswright  路  3Comments

akoenig picture akoenig  路  3Comments

sorenbs picture sorenbs  路  3Comments

dohomi picture dohomi  路  3Comments

sedubois picture sedubois  路  3Comments