v2.0.10-preview
medusajs/medusav2.0.10-previewSep 18, 2024by olivermrbl
AI Summary
This preview release introduces a new Query tool to replace Remote Query and adds observability support via OpenTelemetry for HTTP requests and workflows.
Key Highlights
- Introduction of the new `Query` tool with a consistent API
- Migration guide from Remote Query to Query
- Observability features (tracing) for workflows and HTTP via OpenTelemetry
- New `types` flag for CLI commands to generate types
New Features
- Run nested async workflows
- Add tracing to workflow steps
- Parse filters based on loaded modules graph
- Rework create variant flow in dashboard
Full Release Notes
<!--

# Medusa Preview Release update #10
CMS_BREAK -->
## Update existing project
Ensure your **Medusa** dependencies in `package.json` are using the `preview` tag:
```json
{
"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:
```tsx
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's `query({ ... })`
**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:
```ts
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:
```diff
// 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 of `remoteQuery` from the dependency container
- Use `query.graph({ ... })` instead of `query({ .. })`
- 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:
```ts
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](https://docs.medusajs.com/v2/advanced-development/modules/query#main).
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](https://docs.medusajs.com/v2/debugging-and-testing/instrumentation).
## Features
* feat: run nested async workflows by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/9119
* feat(dashboard,types): added inbound shipping placeholder + shipping summary details by @riqwan in https://github.com/medusajs/medusa/pull/9150
* feat: add tracing to workflow steps by @thetutlage in https://github.com/medusajs/medusa/pull/9140
* feat(modules-sdk): Parse filters based on loaded modules graph by @adrien2p in https://github.com/medusajs/medusa/pull/9158
* feat(dashboard): rework create variant flow by @fPolic in https://github.com/medusajs/medusa/pull/9132
## Bugs
* fix(link-modules): table name by @carlos-r-l-rodrigues in https://github.com/medusajs/medusa/pull/9151
* fix(core-flows): fixes case where inventory attempts delete when input is empty by @riqwan in https://github.com/medusajs/medusa/pull/9156
* fix: migrate old links tables before performing a sync by @thetutlage in https://github.com/medusajs/medusa/pull/9164
* fix: import open telemetry dependencies lazily by @thetutlage in https://github.com/medusajs/medusa/pull/9161
## Documentation
* docs: replace ModuleRegistrationName with Modules by @shahednasser in https://github.com/medusajs/medusa/pull/9142
* docs: update store cURL examples in OAS by @shahednasser in https://github.com/medusajs/medusa/pull/9099
* docs: update query usage across docs by @shahednasser in https://github.com/medusajs/medusa/pull/9120
* docs: update docs across projects following publishable API key change in store routes by @shahednasser in https://github.com/medusajs/medusa/pull/9098
* docs: use require instead of import in medusa-config.js by @shahednasser in https://github.com/medusajs/medusa/pull/9102
* oas: update authorization header in cURL examples by @shahednasser in https://github.com/medusajs/medusa/pull/9100
* docs-util: fixes for circular references, PAK in examples, namespaces by @shahednasser in https://github.com/medusajs/medusa/pull/9091
* docs: added documentation on instrumentation by @shahednasser in https://github.com/medusajs/medusa/pull/9160
* chore(oas): [8/n] improve oas schemas by @shahednasser in https://github.com/medusajs/medusa/pull/9163
* chore(oas): [7/n] improve oas schemas by @shahednasser in https://github.com/medusajs/medusa/pull/9162
* chore(oas): [9/n] improve oas schemas by @shahednasser in https://github.com/medusajs/medusa/pull/9166
## Other Changes
* docs: Rename remoteQuery to query and add db instrumentation flag by @thetutlage in https://github.com/medusajs/medusa/pull/9159
**Full Changelog**: https://github.com/medusajs/medusa/compare/v2.0.9-preview...v2.0.10