-
-
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
feat(core): Add ability to get variants for a specific product in productVariants query #786
feat(core): Add ability to get variants for a specific product in productVariants query #786
Conversation
Hi, Could you rebase this PR onto the master branch? - there were some failing tests which I've now fixed, so then we can make sure your changes are passing in CI too. |
cce19c7
to
11004e8
Compare
Hello! I've just done a rebase onto the master branch. The problem exists for any product which has hundreds of variants. |
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.
Generally looks good - just see my comment about a possible way to do this with less code duplication. Also, an e2e test for this would be good - do you feel confident to add one? If so it would go here
const rawConnection = this.connection.rawConnection; | ||
const qb = this.connection.getRepository(ctx, ProductVariant).createQueryBuilder('productvariant'); | ||
|
||
const filter = parseFilterParams(rawConnection, ProductVariant, options.filter); |
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 notice that quite a significant amount of logic here is being duplicated from the ListQueryBuilder.build()
method. I am wondering whether it would be possible to use the ListQueryBuilder, and then add the required clauses (ie. .andWhere('productvariant.productId = :productId', { productId })
to the returned SelectQueryBuilder object.
Did you try that approach yet?
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.
Hello! Thank you! I agree that would be better to use ListQueryBuilder.build()
here. I will do it.
11004e8
to
c1f5216
Compare
Hello! I implemented |
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.
Thanks, the changes look good!
Just one (very minor) change to the e2e test, and then rebase to latest master because my own bugs will make the ealsticsearch e2e test fail at the current commit 🙃
…ductVariants query
c1f5216
to
0ef5a62
Compare
Hello! I did a rebase and replaced |
Thank you for your contribution! 👍 |
In Vendure we have 2 ways to receive product variants by using product and productVariants queries.
product query finds all product variants for a specific product and in case the product has a lot of variants, the performance of this query will be very slow.
productVariants query has options for pagination and filtering but by using this query we cannot receive variants only for a specific product.
Changes in this pull request will fix this problem. So, in the result, we will have the ability to fetch either all variants or only for the specific product by using the productVariants query.