fix: remote query types (#12712)

* fix: remote query types

* fix: breaking types

* Create eleven-falcons-return.md
This commit is contained in:
Harminder Virk
2025-06-12 15:49:26 +05:30
committed by GitHub
parent 8a88748982
commit b316924572
5 changed files with 105 additions and 55 deletions
+6
View 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>, queryOptions: RemoteQueryInput<TEntry>,
options?: RemoteJoinerOptions options?: RemoteJoinerOptions
): Promise<GraphResultSet<TEntry>> { ): Promise<GraphResultSet<TEntry>> {
const normalizedQuery = toRemoteQuery<TEntry>( const normalizedQuery = toRemoteQuery(
queryOptions, queryOptions,
this.#remoteQuery.getEntitiesMap() this.#remoteQuery.getEntitiesMap()
) )
@@ -1,5 +1,4 @@
import { import {
RemoteQueryEntryPoints,
RemoteQueryFilters, RemoteQueryFilters,
RemoteQueryGraph, RemoteQueryGraph,
RemoteQueryInput, RemoteQueryInput,
@@ -31,7 +30,7 @@ const ARGUMENTS = "__args"
export function toRemoteQuery<const TEntity extends string>( export function toRemoteQuery<const TEntity extends string>(
config: { config: {
entity: TEntity | keyof RemoteQueryEntryPoints entity: TEntity
fields: RemoteQueryInput<TEntity>["fields"] fields: RemoteQueryInput<TEntity>["fields"]
filters?: RemoteQueryFilters<TEntity> filters?: RemoteQueryFilters<TEntity>
pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]> pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]>
@@ -25,22 +25,22 @@ export type RemoteQueryObjectFromStringResult<
__value: object __value: object
} }
export type RemoteQueryInput<TEntry extends string> = { export type RemoteQueryInput<TEntry extends string> =
TEntry extends keyof RemoteQueryEntryPoints
? {
/** /**
* The name of the entity to retrieve. For example, `product`. * The name of the entity to retrieve. For example, `product`.
*/ */
entity: TEntry | keyof RemoteQueryEntryPoints entity: TEntry
/** /**
* The fields and relations to retrieve in the entity. * The fields and relations to retrieve in the entity.
*/ */
fields: ObjectToRemoteQueryFields< fields: ObjectToRemoteQueryFields<
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints] RemoteQueryEntryPoints[TEntry]
> extends never > extends never
? string[] ? string[]
: :
| ObjectToRemoteQueryFields< | ObjectToRemoteQueryFields<RemoteQueryEntryPoints[TEntry]>[]
RemoteQueryEntryPoints[TEntry & keyof RemoteQueryEntryPoints]
>[]
| string[] | string[]
/** /**
* Pagination configurations for the returned list of items. * Pagination configurations for the returned list of items.
@@ -76,6 +76,51 @@ export type RemoteQueryInput<TEntry extends string> = {
*/ */
strategy?: "joined" | "select-in" 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> = { export type RemoteQueryGraph<TEntry extends string> = {
__TConfig: RemoteQueryObjectConfig<TEntry> __TConfig: RemoteQueryObjectConfig<TEntry>
@@ -20,7 +20,7 @@ type ExtractFiltersOperators<
? never ? never
: Key extends ExcludedProps : Key extends ExcludedProps
? never ? 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] | T[Key][] | OperatorMap<T[Key] | T[Key][]>
: T[Key] extends Array<infer R> : T[Key] extends Array<infer R>
? TypeOnly<R> extends { __typename: any } ? TypeOnly<R> extends { __typename: any }