Preview Release Update #10
Update existing project
Ensure your Medusa dependencies in package.json
are using the preview
tag:
{
"dependencies": {
"@medusajs/medusa": "preview",
"@medusajs/pricing": "preview",
"@medusajs/product": "preview",
...
}
}
To ensure an upgrade to a new version is completed correctly, run the following sequence of commands:
rm -rf node_modules
rm yarn.lock // or package-lock.json
yarn // If you are using yarn berry, you need to create the lock-file first
Highlights
Introduced a new query tool
We have introduced a new tool, Query, for querying data across modules in your application. Over time, it will replace Remote Query, which has been deprecated in the latest version. The underlying query engine of Query and Remote Query is the same, but we have changed the query API and eliminated redundant configurations that had built up over time.
There are two significant differences between the two tools:
- The result returned by Query takes the same shape regardless of the query input, which is different from that of Remote Query's that differed depending on whether pagination was applied or not.
- The call signature of Query is
query.graph({ ... })
, which is different from Remote Query'squery({ ... })
Query Result
With Query, you will always receive a result with data
and metadata
. The data contains your requested resources and the metadata contains information about the applied pagination. We recommend consuming it like so:
const { data, metadata } = await query...
Call signature
With Query, you query data across your modules with query.graph({ ... })
.
For example, in an API Route, the difference between how you consume Query vs. Remote Query is as follows:
// API Route
-const query = req.container.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
-
-const result = await query({ ... })
+const query = req.container.resolve(ContainerRegistrationKeys.QUERY)
+
+const { data, metadata } = await query.graph({ ... })
Migrating to Query
To migrate from Remote Query to Query, the following changes are needed:
- Resolve
query
instead ofremoteQuery
from the dependency container - Use
query.graph({ ... })
instead ofquery({ .. })
- Update query options to fit the new format*
*The changes to the query options format are:
- Entrypoint has been renamed:
entryPoint
->entity
- Filters has been moved to a top-level option:
variables: { filters: { ... } }
->filters: { ... }
- Pagination has been moved to a top-level option:
variables: { pagination: { ... } }
->pagination: { ... }
- Context has been moved to a top-level option:
variables: { context: { ... } }
->context: { ... }
- Variables has been removed entirely from the API
Here's an example using all options:
const { data, metadata } = await query.graph({
entity: "product",
fields: ["id", "title", "variants.calculated_price"],
filters: {
variants: {
sku: "SHIRT-1234"
},
},
pagination: { take: 10, skip: 0 },
context: {
variants: {
calculated_price: QueryContext({ currency_code: "usd" })
}
}
})
In this example, we:
- Retrieve the first 10 products that match our query
- Only with the fields:
id
,title
, and the calculated price of variants,variants.calculated_price
- Filtered by product variants
sku
- With computed variant prices based on a dynamic
QueryContext
Alongside the tool, we have shipped a new option, types
, to our CLI commands start
and develop
. If specified, we will attempt to generate types for all data models in existing and custom modules in your project and place them in a new top-level folder .medusa
in your project. The types should significantly improve the developer experience of Query by giving you intellisense of the data you can query in your application.
You can read more about Query in our documentation.
Remote Query will be removed in a later preview version and will not be part of the official release of Medusa 2.0. However, because the required changes are minimal, we recommend upgrading now to avoid issues in the future.
Introduced observability
We have introduced observability into our framework, enabling traces for HTTP requests, workflow executions, and database queries. Our instrumentation is built on top of OpenTelemetry, which allows you to export traces to any platform compatible with OpenTelemetry events.
Read more about tracing in Medusa and how to get started in our documentation.
Features
- feat: run nested async workflows by @carlos-r-l-rodrigues in #9119
- feat(dashboard,types): added inbound shipping placeholder + shipping summary details by @riqwan in #9150
- feat: add tracing to workflow steps by @thetutlage in #9140
- feat(modules-sdk): Parse filters based on loaded modules graph by @adrien2p in #9158
- feat(dashboard): rework create variant flow by @fPolic in #9132
Bugs
- fix(link-modules): table name by @carlos-r-l-rodrigues in #9151
- fix(core-flows): fixes case where inventory attempts delete when input is empty by @riqwan in #9156
- fix: migrate old links tables before performing a sync by @thetutlage in #9164
- fix: import open telemetry dependencies lazily by @thetutlage in #9161
Documentation
- docs: replace ModuleRegistrationName with Modules by @shahednasser in #9142
- docs: update store cURL examples in OAS by @shahednasser in #9099
- docs: update query usage across docs by @shahednasser in #9120
- docs: update docs across projects following publishable API key change in store routes by @shahednasser in #9098
- docs: use require instead of import in medusa-config.js by @shahednasser in #9102
- oas: update authorization header in cURL examples by @shahednasser in #9100
- docs-util: fixes for circular references, PAK in examples, namespaces by @shahednasser in #9091
- docs: added documentation on instrumentation by @shahednasser in #9160
- chore(oas): [8/n] improve oas schemas by @shahednasser in #9163
- chore(oas): [7/n] improve oas schemas by @shahednasser in #9162
- chore(oas): [9/n] improve oas schemas by @shahednasser in #9166
Other Changes
- docs: Rename remoteQuery to query and add db instrumentation flag by @thetutlage in #9159
Full Changelog: v2.0.9-preview...v2.0.10