graphback icon indicating copy to clipboard operation
graphback copied to clipboard

[Discussion]: Future of relationships

Open machi1990 opened this issue 5 years ago • 6 comments

This is an issue that kind of wraps up all the things we can improve around relationship supports:

  • [ ] Review the RelationshipMetadataBuilder,
  • [ ] Properly supporting manyToOne, not properly documented, some validation are wrong e.g https://github.com/aerogear/graphback/issues/2019
  • [ ] Supporting manyToMany relationships e.g https://github.com/aerogear/graphback/issues/1342, https://github.com/aerogear/graphback/issues/328, https://github.com/aerogear/graphback/issues/1185, https://github.com/aerogear/graphback/issues/1342, https://github.com/aerogear/graphback/issues/1494
  • [ ] Implicit relationships https://github.com/aerogear/graphback/issues/936 and embedded fields https://github.com/aerogear/graphback/issues/1723
  • [ ] https://github.com/aerogear/graphback/issues/1661
  • [ ] https://github.com/aerogear/graphback/issues/930 I felt the need to aggregate these issues here and launch the discussion if needed.

machi1990 avatar Sep 09 '20 12:09 machi1990

/cc @craicoverflow, @wtrocki Automatically generated comment to notify maintainers

machi1990 avatar Sep 09 '20 12:09 machi1990

Thank you for creating this issue @machi1990 - this refactor has been on the cards for a while now. The current implementation is pretty hard to extend and is preventing us from easily adding direct many-to-many relationships and implicit relationships.

craicoverflow avatar Sep 09 '20 12:09 craicoverflow

Awesome work @machi1990 and @craicoverflow . Now we can make this work with context of all issues we see

wtrocki avatar Sep 09 '20 13:09 wtrocki

I've found that relationships caused issues with duplicate relationships, so could not complete #2057

In my attempt to allow implicit relationships in https://github.com/aerogear/graphback/pull/1873/files I had refactored relationships so that they would be stored in a config map, instead of an array. This gives many benefits, including:

  • No duplication of relationships since the key is unique in the config map
  • Easy to access the relationship you want (currently you have to perform a filter/find in an array)

Example:

interface ModelRelationshipConfigMap {
  [modelName: string]: ModelFieldRelationshipConfigMap
}

interface ModelFieldRelationshipConfigMap {
  [fieldName: string]: FieldRelationshipMetadata
}

const relationships: ModelRelationshipConfigMap = {
  Note: {
    comments: {...}
  },
  Comment: {
    note: {...}
  }
}

I think when this issue is actioned, this format shoulbe be implemented.

craicoverflow avatar Sep 17 '20 11:09 craicoverflow

I've found that relationships caused issues with duplicate relationships, so could not complete #2057

In my attempt to allow implicit relationships in https://github.com/aerogear/graphback/pull/1873/files I had refactored relationships so that they would be stored in a config map, instead of an array. This gives many benefits, including:

  • No duplication of relationships since the key is unique in the config map
  • Easy to access the relationship you want (currently you have to perform a filter/find in an array)

Example:

interface ModelRelationshipConfigMap {
  [modelName: string]: ModelFieldRelationshipConfigMap
}

interface ModelFieldRelationshipConfigMap {
  [fieldName: string]: FieldRelationshipMetadata
}

const relationships: ModelRelationshipConfigMap = {
  Note: {
    comments: {...}
  },
  Comment: {
    note: {...}
  }
}

I think when this issue is actioned, this format shoulbe be implemented.

+1, a very good idea.

machi1990 avatar Sep 17 '20 11:09 machi1990

I have had chance to review relationships as I needed information form graphback that field is an relationship and sadly could not use it because of the way we do it (we build all relationships and there is no single helper to determine relationship for the model.

Ended up writing my own helper detached from the core.

wtrocki avatar Sep 23 '20 16:09 wtrocki