-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Auto-create relation id fields via PatchSchema #1807
feat: Auto-create relation id fields via PatchSchema #1807
Conversation
Otherwise any mutations done within the updateCollection function will not be fully applied. This becomes important soon when we add fields within that function.
Codecov ReportPatch coverage:
@@ Coverage Diff @@
## develop #1807 +/- ##
===========================================
+ Coverage 75.74% 75.75% +0.01%
===========================================
Files 209 209
Lines 22200 22211 +11
===========================================
+ Hits 16814 16825 +11
- Misses 4222 4223 +1
+ Partials 1164 1163 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 5 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving as long as the comments get resolved :)
Users { | ||
name | ||
foo { | ||
name | ||
} | ||
foobar { | ||
name | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: To make it more explicit to the reader that foobar_id
is set, I suggested returning it in the selection set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, will add.
- Add foobar_id to selection set
Schema: ` | ||
type Users { | ||
name: String | ||
} | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Although it is interesting to show that this is possible, it would be nice to have a test also for two separate schemas. It would help to show that the relation_id
field is only set on the primary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it is interesting to show that this is possible, it would be nice to have a test also for two separate schemas
I'm not sure I follow what makes this interesting, it is just a normal one-many relationship and adding a second schema to the test just complicates things.
It would help to show that the relation_id field is only set on the primary.
I can't see how that would help, how do you see it? I do think it is worth adding a test though to verify that the _id field does not exist on the many side.
- Assert _id field does not exist on many side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow what makes this interesting, it is just a normal one-many relationship and adding a second schema to the test just complicates things.
It's interesting that we show that we can add self-referencing relationships. But that mean that everything is happening on the one collection. Having two separate collections would ensure that the operation isn't broken when it's not just one collection being manipulated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean, but that is not specific to the changes in this PR (this feature actually is one of the least relevant, as it never cares which object it is hosted on). I'll add a ticket to close the test gap for other related behaviour though.
- Add test-ticket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind it is very related as we need to ensure that the auto-creation is behaving properly for all objects involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
integration test which involves 2 add operations
This is why it should be done in another ticket. It should be tested with a simpler use case that isn't cluttered with irrelevancies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is irrelevant to the changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't too different to trying to force a developer working on filters group by to test with a range of groupby order configurations, just because orderby isnt properly tested yet. OrderBy should be tested, but in a simpler context where extras dont confuse the test. It also means that if groupBy-filter is removed as a feature, groupBy-orderby is still tested.
And please remember, I am not objecting to the testing of PatchSchema relation definitions for multiple objects (even though it is technically not needed given the implementation). I am say it should be done in another ticket, as it is not relevant here and will only complicate and dirty both work items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it as related to the change in this PR. You're using an integration test to test the feature. The integration test doesn't care where the auto-create happens. It just cares that it happens. The most common way of having references is from one object to an other. Not from object to self. It would be quite appropriate to have a test that ensures that the feature works in the most common reference pattern where 2 objects are involved. It would also ensure that a change in the future doesn't result in only one side of the relationship having the relation id auto created.
If you really don't want to do it here, it should probably be done shortly so we don't forget about it.
Schema: ` | ||
type Users { | ||
name: String | ||
} | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Same as above. It would be nice to have a test for two separate schemas. In this case it would help show that the relation_id
is set on both sides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. It would be nice to have a test for two separate schemas
Leaving that convo against the other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Just 1 todo
@@ -244,6 +244,20 @@ func (db *db) updateCollection( | |||
return db.getCollectionByName(ctx, txn, desc.Name) | |||
} | |||
|
|||
for _, field := range desc.Schema.Fields { | |||
if field.RelationType.IsSet(client.Relation_Type_ONE) { | |||
idFieldName := field.Name + "_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todo: instead use the defined id constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change, cheers.
- const _id
) ## Relevant issue(s) Resolves sourcenetwork#1773 ## Description Auto-creates relation id fields via PatchSchema if not explicitly defined by the user.
Relevant issue(s)
Resolves #1773
Description
Auto-creates relation id fields via PatchSchema if not explicitly defined by the user.