You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
From the Slack discussion:
It's not obvious which relations are loaded for entities returned by Vendure's services, e.g.: OrderService.findOne(): Promise<Order | undefined> loads many relations, while OrderService.findOneByCode(): Promise<Order | undefined> loads none.
Loading all relations in every service method obviously has a huge performance impact.
The EntityHydrator can be used to ensure that certain relations are loaded, but it comes with a performance impact over loading the required relations directly.
Still, in any case, there remains a risk of inadvertently accessing an unhydrated relation.
Describe the solution you'd like
Vendure's services could make use of TypeScript's Omit<> type to indicate which relations of the returned entities are unhydrated. The rough idea in the Slack thread was to wrap the methods of TransactionalConnection to achieve this.
For performance improvement, we could add an optional relations?: EntityRelationPaths<>[] parameter to the standard .find...() methods, e.g.
Describe alternatives you've considered
Using EntityHydrator works well, but has worse performance than loading the required relations directly, and has a risk of accessing relations which are usually (but not always) loaded and hence possibly forgotten to explicitly hydrate.
Additional context
I wonder, as a first, partial fix, if it might be possible to set a service method's return type based on the relations parameter (for methods which implement it), without wrapping TypeORM.
The text was updated successfully, but these errors were encountered:
Relates to #1506. This commit applies the new `@Relations()` decorator to most of the resolvers and
some key entity field resolvers. Also relates to #1407 in that we are introducing a new "relations"
argument to many of the `find*()` methods of the service layer. However, I've not been able to spend
the time needed to get the corresponding type-safety part done. This can be explored separately
later.
I would say that for certain entities and queries there is a presumption on which relations will be loaded without adding entity resolvers to load relations that are not part of the query.
I would recommend that any relation should always have an entity field resolver that gets the data. So that if someone goes outside of the box, they don't run into unexpected errors
Thanks for your report!
Most services in the latest versions of Vendure support passing in relations now, for example OrderService.findOneByCode(ctx, '12354', ['customer']). If your custom code needs specific relations, you should always be explicit about it. It does automatically change the TS return type yet.
If you are missing the relations argument in any of the services, I suggest creating a separate/specific GH issue for that.
Is your feature request related to a problem? Please describe.
From the Slack discussion:
OrderService.findOne(): Promise<Order | undefined>
loads many relations, whileOrderService.findOneByCode(): Promise<Order | undefined>
loads none.EntityHydrator
can be used to ensure that certain relations are loaded, but it comes with a performance impact over loading the required relations directly.Describe the solution you'd like
Omit<>
type to indicate which relations of the returned entities are unhydrated. The rough idea in the Slack thread was to wrap the methods ofTransactionalConnection
to achieve this.relations?: EntityRelationPaths<>[]
parameter to the standard.find...()
methods, e.g.Describe alternatives you've considered
Using
EntityHydrator
works well, but has worse performance than loading the required relations directly, and has a risk of accessing relations which are usually (but not always) loaded and hence possibly forgotten to explicitly hydrate.Additional context
I wonder, as a first, partial fix, if it might be possible to set a service method's return type based on the
relations
parameter (for methods which implement it), without wrapping TypeORM.The text was updated successfully, but these errors were encountered: