Skip to content
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

Merged
merged 1 commit into from May 9, 2024

Conversation

stephenh
Copy link
Collaborator

@stephenh stephenh commented May 9, 2024

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.

field.otherMetadata().allFields[field.otherFieldName] ??
fail(`No field ${field.otherMetadata().type}.${field.otherFieldName}`);
const otherFieldName =
otherField.kind === "poly" ? `${field.otherFieldName}@${meta.type}` : field.otherFieldName;
Copy link
Collaborator Author

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 cases

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.
@stephenh stephenh force-pushed the fix-tests-for-cte-filtering branch from 5c166ce to 16898a7 Compare May 9, 2024 14:37
expect(reverseReactiveHint(Author, Author, "firstName")).toEqual([
{ entity: Author, fields: ["firstName"], path: [] },
]);
expect(reverse(Author, Author, "firstName")).toEqual([{ entity: "Author", fields: ["firstName"], path: [] }]);
Copy link
Collaborator Author

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("@");
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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)) {
Copy link
Collaborator Author

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

@stephenh stephenh merged commit 3185237 into main May 9, 2024
5 checks passed
@stephenh stephenh deleted the fix-tests-for-cte-filtering branch May 9, 2024 14:44
stephenh pushed a commit that referenced this pull request May 9, 2024
## [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))
@stephenh
Copy link
Collaborator Author

stephenh commented May 9, 2024

🎉 This PR is included in version 1.164.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant