docs: additions and improvements to modules and DML documentation (#7854)
* docs: additions and improvements to modules and DML documentation * small wording fix
This commit is contained in:
@@ -14,8 +14,6 @@ So, resources in the module, such as services or loaders, can only resolve other
|
||||
|
||||
- `logger`: A utility to log message in the Medusa application's logs.
|
||||
|
||||
{/* TODO add other relevant resources, such as event bus */}
|
||||
|
||||
---
|
||||
|
||||
## Resolve Resources
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
export const metadata = {
|
||||
title: `${pageNumber} Module Isolation`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn about how modules are isolated, and what that means for your custom development.
|
||||
|
||||
<Note title="Summary">
|
||||
|
||||
- Modules can't access resources, such as services, from other modules.
|
||||
- You can use Medusa's tools, explained in the next chapters, to extend modules or implement features across modules.
|
||||
|
||||
</Note>
|
||||
|
||||
## How are Modules Isolated?
|
||||
|
||||
A module is unaware of any resources other than its own, such as services or data models. This means it can't access these resources if they're implemented in another module.
|
||||
|
||||
For example, your custom module can't resolve the Product Module's main service or have direct relationships from its data model to another module's data model.
|
||||
|
||||
---
|
||||
|
||||
## Customize and Implement Features Across Modules
|
||||
|
||||
In your Medusa application, you want to implement features that span across modules, or you want to extend existing modules to add new features.
|
||||
|
||||
For example, you want to extend the Product Module to add new properties to the `Product` data model.
|
||||
|
||||
Medusa provides the tools to implement these use cases while maintaining isolation between modules.
|
||||
|
||||
The next chapters explain these tools and how to use them in your custom development.
|
||||
@@ -73,7 +73,7 @@ export async function GET(
|
||||
|
||||
const query = remoteQueryObjectFromString({
|
||||
entryPoint: "my_custom",
|
||||
fields: ["id", "test"],
|
||||
fields: ["id", "name"],
|
||||
})
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -172,3 +172,24 @@ For example, the following methods are generated for the code snippet above:
|
||||
Except for the `retrieve` method, the suffixed data model's name is plural.
|
||||
|
||||
</Note>
|
||||
|
||||
### Using a Constructor
|
||||
|
||||
If you implement the `constructor` of your service, make sure to call `super` passing it `...arguments`.
|
||||
|
||||
For example:
|
||||
|
||||
```ts highlights={[["8"]]}
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
import MyCustom from "./models/my-custom"
|
||||
|
||||
class HelloModuleService extends MedusaService({
|
||||
MyCustom,
|
||||
}){
|
||||
constructor() {
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
export default HelloModuleService
|
||||
```
|
||||
Reference in New Issue
Block a user