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

findOneInChannel supports only string array type relations key, but accepts objects as well and then fails #2809

Closed
mschipperheyn opened this issue Apr 24, 2024 · 5 comments
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@mschipperheyn
Copy link
Collaborator

mschipperheyn commented Apr 24, 2024

Describe the bug
findOneInChannel accepts a typeorm options object to among other things allows you to select additional relations. TypeOrm allows two ways to do it, one the common array of string keys ['relation1', 'relation1.child'], which is deprecated and the second one which is an object { relation1: { child: true } }.

However, Vendure permits both styles but only processes the string array. The second style results in a confusing error Cannot read properties of undefined (reading 'propertyPath')

You can see that here, only an incoming property array is processed and any passed relations object is passed as is

To Reproduce
Steps to reproduce the behavior:

  1. Create a class with a relation
  2. Execute a query like
this.connection
      .findOneInChannel(ctx, Customer, id, ctx.channelId, { relations: {.addresses: true }  })
  1. See error

Expected behavior
Also process incoming relations object

Environment (please complete the following information):

  • @vendure/core version: 2.2.0
  • Nodejs version 20
  • Database (mysql/postgres etc): postgres

Additional context

@carathorys
Copy link
Contributor

Hi @michaelbromley!
I think the issue persists somewhere deep in the EntityHydrator service:
When I try to hydrate a custom entity's relations, sometimes I'm getting the very same error message:
Cannot read properties of undefined (reading 'propertyPath')

I think it somehow related to the @OneToMany relations, in our scenario we have a Company entity, which can have multiple addresses.
The error only occours when I'm trying to load this type of relation with the entity hydrator.
If we're loading it directly with a query it works as we would expect.

@michaelbromley
Copy link
Member

@carathorys thanks for the report. If you are able to put together a minimal reproduction, you could create a new issue.

@carathorys
Copy link
Contributor

@michaelbromley
I've created a repository where I'm able to reproduce the issue:
https://github.com/carathorys/vendure-entity-hydrator-issue
I'm still able to load the relations when I'm loading it with the entity, I've created an example GQL (you can try it out):

query DataWithJoin {
  getDataWithJoin(id: "1") {
    customFields {
      myCustomEntity {
        id
      }
    }
  }
}

When I'm trying to load the relations with EntityHydrator, I'll face the issue (example GQL is here)

query DataWithHydratrion {
  getDataWithEntityHydrator(id: "1") {
    customFields {
      myCustomEntity {
        id
      }
    }
  }
}

@carathorys
Copy link
Contributor

FYI:
This issue seems to be within TypeORM, and if you define the other side of the relation, it doesn't seems to be happen.
typeorm/typeorm#2283 (comment)

@michaelbromley
Copy link
Member

@carathorys thanks for the update 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants