fix: remote query types (#12712)
* fix: remote query types * fix: breaking types * Create eleven-falcons-return.md
This commit is contained in:
6
.changeset/eleven-falcons-return.md
Normal file
6
.changeset/eleven-falcons-return.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/modules-sdk": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
fix: remote query types
|
||||
@@ -155,7 +155,7 @@ export class Query {
|
||||
queryOptions: RemoteQueryInput<TEntry>,
|
||||
options?: RemoteJoinerOptions
|
||||
): Promise<GraphResultSet<TEntry>> {
|
||||
const normalizedQuery = toRemoteQuery<TEntry>(
|
||||
const normalizedQuery = toRemoteQuery(
|
||||
queryOptions,
|
||||
this.#remoteQuery.getEntitiesMap()
|
||||
)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
RemoteQueryEntryPoints,
|
||||
RemoteQueryFilters,
|
||||
RemoteQueryGraph,
|
||||
RemoteQueryInput,
|
||||
@@ -31,7 +30,7 @@ const ARGUMENTS = "__args"
|
||||
|
||||
export function toRemoteQuery<const TEntity extends string>(
|
||||
config: {
|
||||
entity: TEntity | keyof RemoteQueryEntryPoints
|
||||
entity: TEntity
|
||||
fields: RemoteQueryInput<TEntity>["fields"]
|
||||
filters?: RemoteQueryFilters<TEntity>
|
||||
pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]>
|
||||
|
||||
@@ -25,57 +25,102 @@ export type RemoteQueryObjectFromStringResult<
|
||||
__value: object
|
||||
}
|
||||
|
||||
export type RemoteQueryInput<TEntry extends string> = {
|
||||
/**
|
||||
* The name of the entity to retrieve. For example, `product`.
|
||||
*/
|
||||
entity: TEntry | keyof RemoteQueryEntryPoints
|
||||
/**
|
||||
* The fields and relations to retrieve in the entity.
|
||||
*/
|
||||
fields: ObjectToRemoteQueryFields<
|
||||
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
|
||||
> extends never
|
||||
? string[]
|
||||
:
|
||||
| ObjectToRemoteQueryFields<
|
||||
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
|
||||
>[]
|
||||
| string[]
|
||||
/**
|
||||
* Pagination configurations for the returned list of items.
|
||||
*/
|
||||
pagination?: {
|
||||
/**
|
||||
* The number of items to skip before retrieving the returned items.
|
||||
*/
|
||||
skip?: number
|
||||
/**
|
||||
* The maximum number of items to return.
|
||||
*/
|
||||
take?: number
|
||||
/**
|
||||
* Sort by field names in ascending or descending order.
|
||||
*/
|
||||
order?: IndexOrderBy<TEntry>
|
||||
}
|
||||
/**
|
||||
* Filters to apply on the retrieved items.
|
||||
*/
|
||||
filters?: RemoteQueryFilters<TEntry>
|
||||
/**
|
||||
* Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context.
|
||||
*/
|
||||
context?: QueryContextType
|
||||
/**
|
||||
* Apply a `withDeleted` flag on the retrieved data to retrieve soft deleted items.
|
||||
*/
|
||||
withDeleted?: boolean
|
||||
/**
|
||||
* Strategy will be send to the entry module called method
|
||||
*/
|
||||
strategy?: "joined" | "select-in"
|
||||
}
|
||||
export type RemoteQueryInput<TEntry extends string> =
|
||||
TEntry extends keyof RemoteQueryEntryPoints
|
||||
? {
|
||||
/**
|
||||
* The name of the entity to retrieve. For example, `product`.
|
||||
*/
|
||||
entity: TEntry
|
||||
/**
|
||||
* The fields and relations to retrieve in the entity.
|
||||
*/
|
||||
fields: ObjectToRemoteQueryFields<
|
||||
RemoteQueryEntryPoints[TEntry]
|
||||
> extends never
|
||||
? string[]
|
||||
:
|
||||
| ObjectToRemoteQueryFields<RemoteQueryEntryPoints[TEntry]>[]
|
||||
| string[]
|
||||
/**
|
||||
* Pagination configurations for the returned list of items.
|
||||
*/
|
||||
pagination?: {
|
||||
/**
|
||||
* The number of items to skip before retrieving the returned items.
|
||||
*/
|
||||
skip?: number
|
||||
/**
|
||||
* The maximum number of items to return.
|
||||
*/
|
||||
take?: number
|
||||
/**
|
||||
* Sort by field names in ascending or descending order.
|
||||
*/
|
||||
order?: IndexOrderBy<TEntry>
|
||||
}
|
||||
/**
|
||||
* Filters to apply on the retrieved items.
|
||||
*/
|
||||
filters?: RemoteQueryFilters<TEntry>
|
||||
/**
|
||||
* Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context.
|
||||
*/
|
||||
context?: QueryContextType
|
||||
/**
|
||||
* Apply a `withDeleted` flag on the retrieved data to retrieve soft deleted items.
|
||||
*/
|
||||
withDeleted?: boolean
|
||||
/**
|
||||
* Strategy will be send to the entry module called method
|
||||
*/
|
||||
strategy?: "joined" | "select-in"
|
||||
}
|
||||
: {
|
||||
/**
|
||||
* The name of the entity to retrieve. For example, `product`.
|
||||
*/
|
||||
entity: TEntry
|
||||
/**
|
||||
* The fields and relations to retrieve in the entity.
|
||||
*/
|
||||
fields: ObjectToRemoteQueryFields<any> extends never
|
||||
? string[]
|
||||
: ObjectToRemoteQueryFields<any>[] | string[]
|
||||
/**
|
||||
* Pagination configurations for the returned list of items.
|
||||
*/
|
||||
pagination?: {
|
||||
/**
|
||||
* The number of items to skip before retrieving the returned items.
|
||||
*/
|
||||
skip?: number
|
||||
/**
|
||||
* The maximum number of items to return.
|
||||
*/
|
||||
take?: number
|
||||
/**
|
||||
* Sort by field names in ascending or descending order.
|
||||
*/
|
||||
order?: IndexOrderBy<TEntry>
|
||||
}
|
||||
/**
|
||||
* Filters to apply on the retrieved items.
|
||||
*/
|
||||
filters?: RemoteQueryFilters<TEntry>
|
||||
/**
|
||||
* Apply a query context on the retrieved data. For example, to retrieve product prices for a certain context.
|
||||
*/
|
||||
context?: QueryContextType
|
||||
/**
|
||||
* Apply a `withDeleted` flag on the retrieved data to retrieve soft deleted items.
|
||||
*/
|
||||
withDeleted?: boolean
|
||||
/**
|
||||
* Strategy will be send to the entry module called method
|
||||
*/
|
||||
strategy?: "joined" | "select-in"
|
||||
}
|
||||
|
||||
export type RemoteQueryGraph<TEntry extends string> = {
|
||||
__TConfig: RemoteQueryObjectConfig<TEntry>
|
||||
|
||||
@@ -20,7 +20,7 @@ type ExtractFiltersOperators<
|
||||
? never
|
||||
: Key extends ExcludedProps
|
||||
? never
|
||||
: T[Key] extends string | number | boolean | Date
|
||||
: NonNullable<T[Key]> extends string | number | boolean | Date
|
||||
? T[Key] | T[Key][] | OperatorMap<T[Key] | T[Key][]>
|
||||
: T[Key] extends Array<infer R>
|
||||
? TypeOnly<R> extends { __typename: any }
|
||||
|
||||
Reference in New Issue
Block a user