-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Defining eager: true
on customField stops custom entity to load own eager relations
#2687
Comments
Hi, Thanks for the report. Would you be able to create a minimal reproduction I could use to quickly investigate this? Ideally something like a single-file plugin I can paste into my own config file, plus queries/mutations I can copy-paste that clearly demonstrate the problem. If you have time to do that it will really help me rapidly find a fix :) |
Sure makes sense. I try to do that as fast as possible. Thanks for your help 👍🏻 |
Ok I could create a minimal reproduction plugin. You'll find it here: https://gist.github.com/tschortsch/5e11413dda42f6df0a7106834306c05d#file-eager-relations-bug-plugin-ts. To reproduce the bug you have to do the following:
This will create an Hope this helps! |
Thanks for supplying the reproduction gist. Note that I had to change these lines to get the mutation to work to: if (!orderLine) {
const result = await this.orderService.addItemToOrder(ctx, sessionOrder.id, 1, 1);
if (isGraphQlErrorResult(result)) {
throw result.message;
} else {
orderLine = result.lines[result.lines.length - 1];
}
} This looks like a potential TypeORM bug. What I'm going to do is leave this for now and test it with the upcoming v2.2 in which we have made a major upgrade to TypeORM from v0.3.11 to v0.3.20. If the issue still remains there I'll dive deeper. |
An issue was fixed in v2.2.1 that may resolve this (see commit referenced above) |
Upgraded to v2.2.2 but the eager relation is still not resolved when the customField relation is set to |
Describe the bug
I've created a custom entity
Cut
which looks like the following:On the OrderLine I created a customField called
cuts
which is a ManyToMany relation to theCut
entity above:I had to set
eager: true
because otherwise theaddItemToOrder
mutation would ignore thecustomField.cuts
when checking if an orderLine already exists for the given productVariant withOrderModifier.getExistingOrderLine()
(here: https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/src/service/helpers/order-modifier/order-modifier.ts#L131). This is because thecuts
relations is not resolved in theorder
without loading the relation eagerly.But as soon as I define this customField to be resolved eagerly all subrelations of this entity (in this case the
code
field) are not loaded eagerly anymore. I guess this happens because of this logic here: https://github.com/vendure-ecommerce/vendure/blob/master/packages/core/src/api/config/generate-resolvers.ts#L214 which directly returns the translated entity instead of resolving the relation again. It was introduced in this change tianyingchun@3211d75 which fixes the translation of the entity. When I skip the line above locally thecode
-relation of theCut
entity is resolved eagerly again.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: