Skip to content

Conversation

@tomas862
Copy link
Member

get by ids functionality added

@gemini-code-assist
Copy link

Summary of Changes

Hello @tomas862, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the MagentoProductQuery class by transforming it into a flexible GraphQL query builder. The primary goal is to enable fetching products by a list of IDs, which is achieved through a new getByIdsQuery static method. This change also involves a substantial refactoring of existing query definitions, moving from hardcoded constants to dynamic generation via static methods and reusable query fragments, leading to a more maintainable and extensible query interface.

Highlights

  • New getByIds Functionality: Introduced a new static method getByIdsQuery() to fetch Magento products using a list of product IDs, enhancing product retrieval capabilities.
  • Refactored Query Structure: Transformed the class from holding static GraphQL query constants to a dynamic query builder using static methods and private item body constants, improving modularity and reusability.
  • Dynamic Query Generation: Implemented private helper methods (buildPaginatedQuery and buildByIdsQuery) to construct GraphQL queries programmatically, centralizing query logic and reducing redundancy.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant improvement by refactoring the GraphQL query generation in MagentoProductQuery from string constants to static builder methods. This change enhances maintainability, reduces code duplication, and makes the query generation more robust. The addition of the getByIdsQuery functionality is also a valuable new feature.

While the refactoring is well-executed, I've identified a high-severity issue in the new getByIdsQuery implementation where missing pagination parameters could lead to incomplete data being returned. I've included suggestions to fix this.

Additionally, it appears this pull request may be incomplete. Several files in the repository (MagentoQueryBuilder, MagentoQueryBuilderTest, and magento-sync.php) still reference the old DEFAULT_QUERY constant that has been removed. This will cause fatal errors. Please ensure all references to the removed constants are updated to use the new static methods.

Comment on lines +212 to +213
query GetProductsByIds(\$ids: [String!]) {
products(filter: { entity_id: { in: \$ids } }) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The products query in Magento is paginated by default, typically returning 20 items per page. When fetching by a list of IDs, if more than 20 IDs are provided, only the first 20 products will be returned, leading to silent data loss. To ensure all requested products are fetched, you should add a $pageSize variable to the query. The caller will then be responsible for providing this value, which should ideally be the count of the IDs being requested.

query GetProductsByIds(\$ids: [String!], \$pageSize: Int) {
    products(filter: { entity_id: { in: \$ids } }, pageSize: \$pageSize) {

Comment on lines +152 to +154
* Variables:
* - $ids: [String!] (e.g., ["325465", "1924192", "1924190"])
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation for variables should be updated to include $pageSize. The caller needs to be aware that they must provide this parameter to prevent unexpected pagination from Magento, which could lead to incomplete data being returned when fetching a large number of products by ID.

     * Variables:
     * - $ids: [String!] (e.g., ["325465", "1924192", "1924190"])
     * - $pageSize: Int (e.g., the number of IDs, to fetch all products at once)
     */

@tomas862 tomas862 merged commit b8e2867 into main Dec 15, 2025
1 check failed
@tomas862 tomas862 deleted the feature/added-get-by-ids-and-transofrmed-to-static-fn-call branch December 15, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants