|
1
|
import { ChildDocs } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `Service Factory Reference`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
This section of the documentation provides a reference to the methods generated for services extending the service factory (`MedusaService`) and how to use them. |
|
10
|
|
|
11
|
<Note title="Tip"> |
|
12
|
|
|
13
|
Refer to the [Service Factory](!docs!/learn/fundamentals/modules/service-factory) documentation to learn more. |
|
14
|
|
|
15
|
</Note> |
|
16
|
|
|
17
|
## Method Names |
|
18
|
|
|
19
|
When your module's main service extends the service factory, Medusa will: |
|
20
|
|
|
21
|
1. Generate [data-management methods in your main service](#main-service-methods) for each of the data models passed to the `MedusaService` function. |
|
22
|
2. Generate [internal services](#internal-generated-service-methods) for each of the data models passed to the `MedusaService` function, which can be resolved in loaders. |
|
23
|
|
|
24
|
### Main Service Methods |
|
25
|
|
|
26
|
The names of the generated methods for a service extending the service factory are of the format `{operationName}{DataModelName}`, where: |
|
27
|
|
|
28
|
- `{operationName}` is the name of the operation. For example, `create`. |
|
29
|
- `{DataModelName}` is the pascal-case version of the data model's key that's passed in the object parameter of `MedusaService`. The name is pluralized for all operations except the `retrieve` operation. |
|
30
|
|
|
31
|
Some examples of method names: |
|
32
|
|
|
33
|
- `createPosts` (`Post` data model) |
|
34
|
- `createMyPosts` (`MyPost` data model) |
|
35
|
- `retrievePost` (`Post` data model) |
|
36
|
- `listPosts` (`Post` data model) |
|
37
|
|
|
38
|
### Internal Generated Service Methods |
|
39
|
|
|
40
|
The internal services are useful when you need to perform database operations in loaders, as they're executed before the module's services are registered. Learn more in the [Module Container](!docs!/learn/fundamentals/modules/container) documentation. |
|
41
|
|
|
42
|
For the internal services, the method names are only the operation name, without the data model name. |
|
43
|
|
|
44
|
For example, a `Post` data model would have a `postService` with methods like `create`, `retrieve`, `update`, and `delete`. |
|
45
|
|
|
46
|
--- |
|
47
|
|
|
48
|
## Methods Reference |
|
49
|
|
|
50
|
<Note> |
|
51
|
|
|
52
|
The reference uses only the operation name to refer to the method. |
|
53
|
|
|
54
|
</Note> |
|
55
|
|
|
56
|
<ChildDocs showItems={["Methods"]} hideTitle /> |