-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix: Add tests for previous reactive hint fix, with more fixes. #1080
Conversation
field.otherMetadata().allFields[field.otherFieldName] ?? | ||
fail(`No field ${field.otherMetadata().type}.${field.otherFieldName}`); | ||
const otherFieldName = | ||
otherField.kind === "poly" ? `${field.otherFieldName}@${meta.type}` : field.otherFieldName; |
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 extract this to maybeAddTypeFilterSuffix
so it could be used across the relation case
s
This adds a test to reproduce the prior "walk through a different subtype that does not have the relation" error, as well as applies the fix to m2o and m2m handling as well. There is also a related fix that runtime filtering of the type filter, i.e. `publisher@Publisher` should pass for subtypes of `Publisher` like either a `LargePublisher` or `SmallPublisher`, and previously we were only exact-matching on the type name.
5c166ce
to
16898a7
Compare
expect(reverseReactiveHint(Author, Author, "firstName")).toEqual([ | ||
{ entity: Author, fields: ["firstName"], path: [] }, | ||
]); | ||
expect(reverse(Author, Author, "firstName")).toEqual([{ entity: "Author", fields: ["firstName"], path: [] }]); |
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 added a helper method to turn entity
into a string name, to stop blowing up Jest diffs on the entity constructors.
@@ -264,11 +288,11 @@ export async function followReverseHint(entities: Entity[], reverseHint: string[ | |||
// And "walk backwards" through the reverse hint | |||
while (paths.length) { | |||
const path = paths.shift()!; | |||
const [fieldName, viaPolyType] = path.split("@"); | |||
const [fieldName, viaType] = path.split("@"); |
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.
Renamed to just viaType
since it's used for both polys & CTE/inheritance now
if (viaPolyType) { | ||
const loaded: Entity = await loadPromise; | ||
return loaded && getMetadata(loaded).type === viaPolyType ? loaded : undefined; | ||
function maybeApplyTypeFilter(loadPromise: Promise<Entity | Entity[]>, viaType: string | undefined) { |
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.
Took out the async/await
if (meta.type === typeName) return true; | ||
// Otherwise see if the entity is a subtype of the typeName, i.e. if our poly/type | ||
// filter is `@Publisher`, and we're a `SmallPublisher`, that's valid to traverse. | ||
for (const other of getSubMetas(meta)) { |
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.
Now we allow subtypes of the filter to pass
## [1.164.3](v1.164.2...v1.164.3) (2024-05-09) ### Bug Fixes * Add tests for previous reactive hint fix, with more fixes. ([#1080](#1080)) ([3185237](3185237))
🎉 This PR is included in version 1.164.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This adds a test to reproduce the prior "walk through a different subtype that does not have the relation" error, as well as applies the fix to m2o and m2m handling as well.
There is also a related fix that runtime filtering of the type filter, i.e.
publisher@Publisher
should pass for subtypes ofPublisher
like either aLargePublisher
orSmallPublisher
, and previously we were only exact-matching on the type name.