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

feat: query.index #11348

Merged
merged 32 commits into from
Feb 12, 2025
Merged

feat: query.index #11348

merged 32 commits into from
Feb 12, 2025

Conversation

carlos-r-l-rodrigues
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues commented Feb 6, 2025

What:

  • query.index helper. It queries the index module, and aggregate the rest of requested fields/relations if needed like query.graph.

Not covered in this PR:

  • Hydrate only sub entities returned by the query. Example: 1 out of 5 variants have returned, it should only hydrate the data of the single entity, currently it will merge all the variants of the product.
  • Generate types of indexed data

example:

const query = container.resolve(ContainerRegistrationKeys.QUERY)
       
await query.index({
 entity: "product",
 fields: [
   "id",
   "description",
   "status",
   "variants.sku",
   "variants.barcode",
   "variants.material",
   "variants.options.value",
   "variants.prices.amount",
   "variants.prices.currency_code",
   "variants.inventory_items.inventory.sku",
   "variants.inventory_items.inventory.description",
 ],
 filters: {
   "variants.sku": { $like: "%-1" },
   "variants.prices.amount": { $gt: 30 },
 },
 pagination: {
   order: {
     "variants.prices.amount": "DESC",
   },
 },
})

This query return all products where at least one variant has the title ending in -1 and at least one price bigger than 30.

The Index Module only hold the data used to paginate and filter, and the returned object is:

{
  "id": "prod_01JKEAM2GJZ14K64R0DHK0JE72",
  "title": null,
  "variants": [
    {
      "id": "variant_01JKEAM2HC89GWS95F6GF9C6YA",
      "sku": "extra-variant-1",
      "prices": [
        {
          "id": "price_01JKEAM2JADEWWX72F8QDP6QXT",
          "amount": 80,
          "currency_code": "USD"
        }
      ]
    }
  ]
}

All the rest of the fields will be hydrated from their respective modules, and the final result will be:

{
  "id": "prod_01JKEAY2RJTF8TW9A23KTGY1GD",
  "description": "extra description",
  "status": "draft",
  "variants": [
    {
      "sku": "extra-variant-1",
      "barcode": null,
      "material": null,
      "id": "variant_01JKEAY2S945CRZ6X4QZJ7GVBJ",
      "options": [
        {
          "value": "Red"
        }
      ],
      "prices": [
        {
          "amount": 20,
          "currency_code": "CAD",
          "id": "price_01JKEAY2T2EEYSWZHPGG11B7W7"
        },
        {
          "amount": 80,
          "currency_code": "USD",
          "id": "price_01JKEAY2T2NJK2E5468RK84CAR"
        }
      ],
      "inventory_items": [
        {
          "variant_id": "variant_01JKEAY2S945CRZ6X4QZJ7GVBJ",
          "inventory_item_id": "iitem_01JKEAY2SNY2AWEHPZN0DDXVW6",
          "inventory": {
            "sku": "extra-variant-1",
            "description": "extra variant 1",
            "id": "iitem_01JKEAY2SNY2AWEHPZN0DDXVW6"
          }
        }
      ]
    }
  ]
}

Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 0:38am
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 0:38am
5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:38am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:38am
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:38am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:38am
resources-docs ⬜️ Ignored (Inspect) Visit Preview Feb 12, 2025 0:38am

Copy link

changeset-bot bot commented Feb 6, 2025

🦋 Changeset detected

Latest commit: 77f4195

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 65 packages
Name Type
@medusajs/orchestration Patch
@medusajs/modules-sdk Patch
@medusajs/types Patch
@medusajs/index Patch
integration-tests-http Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/cli Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@olivermrbl
Copy link
Contributor

/snapshot-this

@carlos-r-l-rodrigues
Copy link
Contributor Author

/snapshot-this

Copy link
Contributor

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: d6c03ee

@olivermrbl
Copy link
Contributor

/snapshot-this

Copy link
Contributor

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: 8d10731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants