chore(core-flows,types): add TSDocs for useQueryGraphStep (#10042)
This commit is contained in:
1 parent
be700e31f2
commit
5fb73e6698
3 files changed
+116
-1
No files matched your search
@@ -26,6 +26,91 @@ const step = createStep(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This step fetches data across modules using the Query.
|
||||||
|
*
|
||||||
|
* Learn more in the [Query documentation](https://docs.medusajs.com/learn/advanced-development/module-links/query).
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* To retrieve a list of records of a data model:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import {
|
||||||
|
* createWorkflow
|
||||||
|
* } from "@medusajs/framework/workflows-sdk"
|
||||||
|
* import {
|
||||||
|
* useQueryGraphStep
|
||||||
|
* } from "@medusajs/medusa/core-flows"
|
||||||
|
*
|
||||||
|
* const helloWorldWorkflow = createWorkflow(
|
||||||
|
* "hello-world",
|
||||||
|
* () => {
|
||||||
|
* const { data: products } = useQueryGraphStep({
|
||||||
|
* entity: "product",
|
||||||
|
* fields: [
|
||||||
|
* "*",
|
||||||
|
* "variants.*"
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To retrieve a single item instead of a an array:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const { data: products } = useQueryGraphStep({
|
||||||
|
* entity: "product",
|
||||||
|
* fields: [
|
||||||
|
* "*",
|
||||||
|
* "variants.*"
|
||||||
|
* ],
|
||||||
|
* filters: {
|
||||||
|
* id: "123"
|
||||||
|
* }
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To throw an error if a record isn't found matching the specified ID:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const { data: products } = useQueryGraphStep({
|
||||||
|
* entity: "product",
|
||||||
|
* fields: [
|
||||||
|
* "*",
|
||||||
|
* "variants.*"
|
||||||
|
* ],
|
||||||
|
* filters: {
|
||||||
|
* id: "123"
|
||||||
|
* },
|
||||||
|
* options: {
|
||||||
|
* throwIfKeyNotFound: true
|
||||||
|
* }
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To set pagination configurations:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const { data: products } = useQueryGraphStep({
|
||||||
|
* entity: "product",
|
||||||
|
* fields: [
|
||||||
|
* "*",
|
||||||
|
* "variants.*"
|
||||||
|
* ],
|
||||||
|
* filters: {
|
||||||
|
* id: "123"
|
||||||
|
* },
|
||||||
|
* pagination: {
|
||||||
|
* take: 10,
|
||||||
|
* skip: 10,
|
||||||
|
* order: {
|
||||||
|
* created_at: "DESC"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
export const useQueryGraphStep = <const TEntry extends string>(
|
export const useQueryGraphStep = <const TEntry extends string>(
|
||||||
input: UseQueryGraphStepInput<TEntry>
|
input: UseQueryGraphStepInput<TEntry>
|
||||||
): ReturnType<StepFunction<UseQueryGraphStepInput<TEntry>, GraphResultSet<TEntry>>> =>
|
): ReturnType<StepFunction<UseQueryGraphStepInput<TEntry>, GraphResultSet<TEntry>>> =>
|
||||||
|
|||||||
@@ -50,7 +50,13 @@ export const useRemoteQueryStepId = "use-remote-query"
|
|||||||
/**
|
/**
|
||||||
* This step fetches data across modules using the remote query.
|
* This step fetches data across modules using the remote query.
|
||||||
*
|
*
|
||||||
* Learn more in the [Remote Query documentation](https://docs.medusajs.com/advanced-development/modules/remote-query).
|
* Learn more in the [Remote Query documentation](https://docs.medusajs.com/learn/advanced-development/module-links/query).
|
||||||
|
*
|
||||||
|
* :::note
|
||||||
|
*
|
||||||
|
* This step is deprecated. Use {@link useQueryGraphStep} instead.
|
||||||
|
*
|
||||||
|
* :::
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -25,7 +25,13 @@ export type RemoteQueryObjectFromStringResult<
|
|||||||
|
|
||||||
export type RemoteQueryInput<TEntry extends string> = {
|
export type RemoteQueryInput<TEntry extends string> = {
|
||||||
// service: string This property is still supported under the hood but part of the type due to types missmatch towards fields
|
// service: string This property is still supported under the hood but part of the type due to types missmatch towards fields
|
||||||
|
/**
|
||||||
|
* The name of the entity to retrieve. For example, `product`.
|
||||||
|
*/
|
||||||
entity: TEntry | keyof RemoteQueryEntryPoints
|
entity: TEntry | keyof RemoteQueryEntryPoints
|
||||||
|
/**
|
||||||
|
* The fields and relations to retrieve in the entity.
|
||||||
|
*/
|
||||||
fields: ObjectToRemoteQueryFields<
|
fields: ObjectToRemoteQueryFields<
|
||||||
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
|
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
|
||||||
> extends never
|
> extends never
|
||||||
@@ -33,12 +39,30 @@ export type RemoteQueryInput<TEntry extends string> = {
|
|||||||
: ObjectToRemoteQueryFields<
|
: ObjectToRemoteQueryFields<
|
||||||
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
|
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
|
||||||
>[]
|
>[]
|
||||||
|
/**
|
||||||
|
* Pagination configurations for the returned list of items.
|
||||||
|
*/
|
||||||
pagination?: {
|
pagination?: {
|
||||||
|
/**
|
||||||
|
* The number of items to skip before retrieving the returned items.
|
||||||
|
*/
|
||||||
skip: number
|
skip: number
|
||||||
|
/**
|
||||||
|
* The maximum number of items to return.
|
||||||
|
*/
|
||||||
take?: number
|
take?: number
|
||||||
|
/**
|
||||||
|
* Sort by field names in ascending or descending order.
|
||||||
|
*/
|
||||||
order?: IndexOrderBy<TEntry>
|
order?: IndexOrderBy<TEntry>
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Filters to apply on the retrieved items.
|
||||||
|
*/
|
||||||
filters?: RemoteQueryFilters<TEntry>
|
filters?: RemoteQueryFilters<TEntry>
|
||||||
|
/**
|
||||||
|
* Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context.
|
||||||
|
*/
|
||||||
context?: any
|
context?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user