committed by
GitHub
parent
48cc00e991
commit
827b32cffd
@@ -3,9 +3,8 @@ import {
|
||||
RemoteQueryFilters,
|
||||
RemoteQueryGraph,
|
||||
RemoteQueryInput,
|
||||
RemoteQueryObjectConfig,
|
||||
} from "@medusajs/types"
|
||||
import { QueryContext, QueryFilter, isObject } from "@medusajs/utils"
|
||||
import { isObject, QueryContext } from "@medusajs/utils"
|
||||
import { parseAndAssignFilters } from "./parse-filters"
|
||||
|
||||
const FIELDS = "__fields"
|
||||
@@ -15,6 +14,7 @@ const ARGUMENTS = "__args"
|
||||
* convert a specific API configuration to a remote query object
|
||||
*
|
||||
* @param config
|
||||
* @param entitiesMap
|
||||
*
|
||||
* @example
|
||||
* const remoteQueryObject = toRemoteQuery({
|
||||
@@ -32,7 +32,7 @@ const ARGUMENTS = "__args"
|
||||
export function toRemoteQuery<const TEntity extends string>(
|
||||
config: {
|
||||
entity: TEntity | keyof RemoteQueryEntryPoints
|
||||
fields: RemoteQueryObjectConfig<TEntity>["fields"]
|
||||
fields: RemoteQueryInput<TEntity>["fields"]
|
||||
filters?: RemoteQueryFilters<TEntity>
|
||||
pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]>
|
||||
context?: Record<string, any>
|
||||
@@ -60,11 +60,11 @@ export function toRemoteQuery<const TEntity extends string>(
|
||||
continue
|
||||
}
|
||||
|
||||
if (QueryContext.isQueryContext(src) || QueryFilter.isQueryFilter(src)) {
|
||||
if (QueryContext.isQueryContext(src)) {
|
||||
const normalizedFilters = { ...src } as any
|
||||
delete normalizedFilters.__type
|
||||
|
||||
const prop = QueryFilter.isQueryFilter(src) ? "filters" : "context"
|
||||
const prop = "context"
|
||||
|
||||
if (topLevel) {
|
||||
target[ARGUMENTS] ??= {}
|
||||
@@ -110,7 +110,7 @@ export function toRemoteQuery<const TEntity extends string>(
|
||||
}
|
||||
|
||||
if (config.pagination) {
|
||||
joinerQuery[entity][ARGUMENTS] ??= {}
|
||||
joinerQuery[entity][ARGUMENTS] ??= {} as any
|
||||
joinerQuery[entity][ARGUMENTS] = {
|
||||
...joinerQuery[entity][ARGUMENTS],
|
||||
...config.pagination,
|
||||
|
||||
Reference in New Issue
Block a user