graphback
graphback copied to clipboard
[Discussion]: Future of relationships
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
manyToManyrelationships 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.
/cc @craicoverflow, @wtrocki Automatically generated comment to notify maintainers
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.
Awesome work @machi1990 and @craicoverflow . Now we can make this work with context of all issues we see
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.
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.
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.