docs: rename remoteLink and remoteQueryConfig (#10836)
* docs: rename remoteLink and remoteQueryConfig * change version number
This commit is contained in:
@@ -81,18 +81,18 @@ The column's configurations object accepts the following properties:
|
||||
|
||||
## Set Custom Column when Creating Link
|
||||
|
||||
The object you pass to the remote link's `create` method accepts a `data` property. Its value is an object whose keys are custom column names, and values are the value of the custom column for this link.
|
||||
The object you pass to Link's `create` method accepts a `data` property. Its value is an object whose keys are custom column names, and values are the value of the custom column for this link.
|
||||
|
||||
For example:
|
||||
|
||||
<Note>
|
||||
|
||||
Learn more about the remote link, how to resolve it, and its methods in [this chapter](../remote-link/page.mdx).
|
||||
Learn more about Link, how to resolve it, and its methods in [this chapter](../link/page.mdx).
|
||||
|
||||
</Note>
|
||||
|
||||
```ts
|
||||
await remoteLink.create({
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "123",
|
||||
},
|
||||
@@ -145,14 +145,14 @@ In the `fields` array you pass `metadata`, which is the custom column to retriev
|
||||
|
||||
## Update Custom Column's Value
|
||||
|
||||
The remote link's `create` method updates a link's data if the link between the specified records already exists.
|
||||
Link's `create` method updates a link's data if the link between the specified records already exists.
|
||||
|
||||
So, to update the value of a custom column in a created link, use the `create` method again passing it a new value for the custom column.
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
await remoteLink.create({
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "123",
|
||||
},
|
||||
|
||||
+22
-19
@@ -1,14 +1,20 @@
|
||||
export const metadata = {
|
||||
title: `${pageNumber} Remote Link`,
|
||||
title: `${pageNumber} Link`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you’ll learn what the remote link is and how to use it to manage links.
|
||||
In this chapter, you’ll learn what Link is and how to use it to manage links.
|
||||
|
||||
## What is the Remote Link?
|
||||
<Note>
|
||||
|
||||
The remote link is a class with utility methods to manage links between data models. It’s registered in the Medusa container under the `remoteLink` registration name.
|
||||
As of [Medusa v2.2.0](https://github.com/medusajs/medusa/releases/tag/v2.2.0), Remote Link has been deprecated in favor of Link. They have the same usage, so you only need to change the key used to resolve the tool from the Medusa container as explained below.
|
||||
|
||||
</Note>
|
||||
|
||||
## What is Link?
|
||||
|
||||
Link is a class with utility methods to manage links between data models. It’s registered in the Medusa container under the `link` registration name.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -20,16 +26,13 @@ import {
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
RemoteLink,
|
||||
} from "@medusajs/framework/modules-sdk"
|
||||
|
||||
export async function POST(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const remoteLink: RemoteLink = req.scope.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
const link = req.scope.resolve(
|
||||
ContainerRegistrationKeys.LINK
|
||||
)
|
||||
|
||||
// ...
|
||||
@@ -42,7 +45,7 @@ You can use its methods to manage links, such as create or delete links.
|
||||
|
||||
## Create Link
|
||||
|
||||
To create a link between records of two data models, use the `create` method of the remote link.
|
||||
To create a link between records of two data models, use the `create` method of Link.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -51,7 +54,7 @@ import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
// ...
|
||||
|
||||
await remoteLink.create({
|
||||
await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
@@ -65,7 +68,7 @@ The `create` method accepts as a parameter an object. The object’s keys are th
|
||||
|
||||
<Note title="Important">
|
||||
|
||||
The keys (names of linked modules) must be in the same direction of the link definition.
|
||||
The keys (names of linked modules) must be in the same [direction](../directions/page.mdx) of the link definition.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -77,7 +80,7 @@ So, in the example above, you link a record of the `MyCustom` data model in a `h
|
||||
|
||||
## Dismiss Link
|
||||
|
||||
To remove a link between records of two data models, use the `dismiss` method of the remote link.
|
||||
To remove a link between records of two data models, use the `dismiss` method of Link.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -86,7 +89,7 @@ import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
// ...
|
||||
|
||||
await remoteLink.dismiss({
|
||||
await link.dismiss({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
@@ -100,7 +103,7 @@ The `dismiss` method accepts the same parameter type as the [create method](#cre
|
||||
|
||||
<Note title="Important">
|
||||
|
||||
The keys (names of linked modules) must be in the same direction of the link definition.
|
||||
The keys (names of linked modules) must be in the same [direction](../directions/page.mdx) of the link definition.
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -108,7 +111,7 @@ The keys (names of linked modules) must be in the same direction of the link def
|
||||
|
||||
## Cascade Delete Linked Records
|
||||
|
||||
If a record is deleted, use the `delete` method of the remote link to delete all linked records.
|
||||
If a record is deleted, use the `delete` method of Link to delete all linked records.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -119,7 +122,7 @@ import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
await productModuleService.deleteVariants([variant.id])
|
||||
|
||||
await remoteLink.delete({
|
||||
await link.delete({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
@@ -132,7 +135,7 @@ This deletes all records linked to the deleted product.
|
||||
|
||||
## Restore Linked Records
|
||||
|
||||
If a record that was previously soft-deleted is now restored, use the `restore` method of the remote link to restore all linked records.
|
||||
If a record that was previously soft-deleted is now restored, use the `restore` method of Link to restore all linked records.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -143,7 +146,7 @@ import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
await productModuleService.restoreProducts(["prod_123"])
|
||||
|
||||
await remoteLink.restore({
|
||||
await link.restore({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: "prod_123",
|
||||
},
|
||||
@@ -346,12 +346,18 @@ The `validateAndTransformQuery` accepts two parameters:
|
||||
|
||||
After applying this middleware, your API route now accepts the `fields`, `offset`, `limit`, and `order` query parameters mentioned above.
|
||||
|
||||
The middleware transforms these parameters to configurations that you can pass to Query in your API route handler. These configurations are stored in the `remoteQueryConfig` parameter of the `MedusaRequest` object.
|
||||
The middleware transforms these parameters to configurations that you can pass to Query in your API route handler. These configurations are stored in the `queryConfig` parameter of the `MedusaRequest` object.
|
||||
|
||||
<Note>
|
||||
|
||||
As of [Medusa v2.2.0](https://github.com/medusajs/medusa/releases/tag/v2.2.0), `remoteQueryConfig` has been depercated in favor of `queryConfig`. Their usage is still the same, only the property name has changed.
|
||||
|
||||
</Note>
|
||||
|
||||
For example, Create the file `src/api/customs/route.ts` with the following content:
|
||||
|
||||
export const queryConfigHighlights = [
|
||||
["17", "req.remoteQueryConfig", "Pass the parsed request Query configurations to the Query graph execution."]
|
||||
["17", "req.queryConfig", "Pass the parsed request Query configurations to the Query graph execution."]
|
||||
]
|
||||
|
||||
```ts title="src/api/customs/route.ts"
|
||||
@@ -371,7 +377,7 @@ export const GET = async (
|
||||
|
||||
const { data: myCustoms } = await query.graph({
|
||||
entity: "my_custom",
|
||||
...req.remoteQueryConfig,
|
||||
...req.queryConfig,
|
||||
})
|
||||
|
||||
res.json({ my_customs: myCustoms })
|
||||
@@ -380,7 +386,7 @@ export const GET = async (
|
||||
|
||||
This adds a `GET` API route at `/customs`, which is the API route you added the middleware for.
|
||||
|
||||
In the API route, you pass `req.remoteQueryConfig` to `query.graph`. `remoteQueryConfig` has properties like `fields` and `pagination` to configure the query based on the default values you specified in the middleware, and the query parameters passed in the request.
|
||||
In the API route, you pass `req.queryConfig` to `query.graph`. `queryConfig` has properties like `fields` and `pagination` to configure the query based on the default values you specified in the middleware, and the query parameters passed in the request.
|
||||
|
||||
### Test it Out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user