diff --git a/packages/query-graphql/src/types/connection/array-connection.type.ts b/packages/query-graphql/src/types/connection/array-connection.type.ts index 0249cc30d..d4ee00233 100644 --- a/packages/query-graphql/src/types/connection/array-connection.type.ts +++ b/packages/query-graphql/src/types/connection/array-connection.type.ts @@ -11,9 +11,13 @@ export function getOrCreateArrayConnectionType( class AbstractConnection extends Array { static resolveType = [TItemClass]; - static async createFromPromise(queryMany: QueryMany, query: Query): Promise { + static async createFromPromise>( + queryMany: QueryMany, + query: Q, + ): Promise { + // remove paging from the query because the ArrayConnection does not support paging. const { paging, ...rest } = query; - return queryMany(rest); + return queryMany(rest as Q); } } return AbstractConnection; diff --git a/packages/query-graphql/src/types/connection/cursor/cursor-connection.type.ts b/packages/query-graphql/src/types/connection/cursor/cursor-connection.type.ts index c61ee5861..33ffc34cc 100644 --- a/packages/query-graphql/src/types/connection/cursor/cursor-connection.type.ts +++ b/packages/query-graphql/src/types/connection/cursor/cursor-connection.type.ts @@ -47,9 +47,9 @@ export function getOrCreateCursorConnectionType( return this; } - static async createFromPromise( - queryMany: QueryMany, - query: Query, + static async createFromPromise>( + queryMany: QueryMany, + query: Q, count?: Count, ): Promise { const { pageInfo, edges, totalCount } = await pager.page(queryMany, query, count ?? DEFAULT_COUNT); diff --git a/packages/query-graphql/src/types/connection/cursor/pager/pager.ts b/packages/query-graphql/src/types/connection/cursor/pager/pager.ts index 9442c383e..b714746b0 100644 --- a/packages/query-graphql/src/types/connection/cursor/pager/pager.ts +++ b/packages/query-graphql/src/types/connection/cursor/pager/pager.ts @@ -18,9 +18,9 @@ const DEFAULT_PAGING_META = (query: Query): PagingMeta implements Pager> { constructor(readonly strategy: PagerStrategy) {} - async page( - queryMany: QueryMany, - query: CursorQueryArgsType, + async page>( + queryMany: QueryMany, + query: Q, count: Count, ): Promise> { const pagingMeta = this.getPageMeta(query); @@ -41,9 +41,9 @@ export class CursorPager implements Pager> { return pagingMeta.opts.limit > 0; } - private async runQuery( - queryMany: QueryMany, - query: Query, + private async runQuery>( + queryMany: QueryMany, + query: Q, pagingMeta: PagingMeta>, ): Promise> { const { opts } = pagingMeta; diff --git a/packages/query-graphql/src/types/connection/cursor/pager/strategies/keyset.pager-strategy.ts b/packages/query-graphql/src/types/connection/cursor/pager/strategies/keyset.pager-strategy.ts index 963680d98..94822e380 100644 --- a/packages/query-graphql/src/types/connection/cursor/pager/strategies/keyset.pager-strategy.ts +++ b/packages/query-graphql/src/types/connection/cursor/pager/strategies/keyset.pager-strategy.ts @@ -38,7 +38,7 @@ export class KeysetPagerStrategy implements PagerStrategy { return !opts.payload || !opts.payload.fields.length; } - createQuery(query: Query, opts: KeySetPagingOpts, includeExtraNode: boolean): Query { + createQuery>(query: Q, opts: KeySetPagingOpts, includeExtraNode: boolean): Q { const paging = { limit: opts.limit }; if (includeExtraNode) { // Add 1 to the limit so we will fetch an additional node diff --git a/packages/query-graphql/src/types/connection/cursor/pager/strategies/limit-offset.pager-strategy.ts b/packages/query-graphql/src/types/connection/cursor/pager/strategies/limit-offset.pager-strategy.ts index 691269364..1432a1245 100644 --- a/packages/query-graphql/src/types/connection/cursor/pager/strategies/limit-offset.pager-strategy.ts +++ b/packages/query-graphql/src/types/connection/cursor/pager/strategies/limit-offset.pager-strategy.ts @@ -21,7 +21,7 @@ export class LimitOffsetPagerStrategy implements PagerStrategy { return opts.offset === 0; } - createQuery(query: Query, opts: OffsetPagingOpts, includeExtraNode: boolean): Query { + createQuery>(query: Q, opts: OffsetPagingOpts, includeExtraNode: boolean): Q { const { isBackward } = opts; const paging = { limit: opts.limit, offset: opts.offset }; if (includeExtraNode) { diff --git a/packages/query-graphql/src/types/connection/cursor/pager/strategies/pager-strategy.ts b/packages/query-graphql/src/types/connection/cursor/pager/strategies/pager-strategy.ts index 58fb1c3e1..51c436e3e 100644 --- a/packages/query-graphql/src/types/connection/cursor/pager/strategies/pager-strategy.ts +++ b/packages/query-graphql/src/types/connection/cursor/pager/strategies/pager-strategy.ts @@ -34,6 +34,6 @@ export interface PagerStrategy { toCursor(dto: DTO, index: number, opts: CursorPagingOpts, query: Query): string; fromCursorArgs(cursor: CursorPagingType): CursorPagingOpts; isEmptyCursor(opts: CursorPagingOpts): boolean; - createQuery(query: Query, opts: CursorPagingOpts, includeExtraNode: boolean): Query; + createQuery>(query: Q, opts: CursorPagingOpts, includeExtraNode: boolean): Q; checkForExtraNode(nodes: DTO[], opts: CursorPagingOpts): DTO[]; } diff --git a/packages/query-graphql/src/types/connection/interfaces.ts b/packages/query-graphql/src/types/connection/interfaces.ts index fc3c10ebd..6fbac5819 100644 --- a/packages/query-graphql/src/types/connection/interfaces.ts +++ b/packages/query-graphql/src/types/connection/interfaces.ts @@ -63,7 +63,7 @@ export type InferConnectionTypeFromStrategy = S ? CursorConnectionType : never; -export type QueryMany = (query: Query) => Promise; +export type QueryMany> = (query: Q) => Promise; export type Count = (filter: Filter) => Promise; export type CountFn = () => Promise; @@ -73,15 +73,15 @@ export type PagerResult = { }; export interface Pager { - page(queryMany: QueryMany, query: Query, count: Count): Promise; + page>(queryMany: QueryMany, query: Q, count: Count): Promise; } export interface StaticConnectionType extends Class> { resolveType: ReturnTypeFuncValue; - createFromPromise( - queryMany: QueryMany, - query: Query & Record, + createFromPromise>( + queryMany: QueryMany, + query: Q, count?: Count, ): Promise>; } diff --git a/packages/query-graphql/src/types/connection/offset/offset-connection.type.ts b/packages/query-graphql/src/types/connection/offset/offset-connection.type.ts index 20d8a565a..15ebe2024 100644 --- a/packages/query-graphql/src/types/connection/offset/offset-connection.type.ts +++ b/packages/query-graphql/src/types/connection/offset/offset-connection.type.ts @@ -43,9 +43,9 @@ export function getOrCreateOffsetConnectionType( return this; } - static async createFromPromise( - queryMany: QueryMany, - query: Query, + static async createFromPromise>( + queryMany: QueryMany, + query: Q, count?: Count, ): Promise { const { pageInfo, nodes, totalCount } = await pager.page(queryMany, query, count ?? DEFAULT_COUNT); diff --git a/packages/query-graphql/src/types/connection/offset/pager/pager.ts b/packages/query-graphql/src/types/connection/offset/pager/pager.ts index 6baa5f1a1..811d0b0da 100644 --- a/packages/query-graphql/src/types/connection/offset/pager/pager.ts +++ b/packages/query-graphql/src/types/connection/offset/pager/pager.ts @@ -15,7 +15,11 @@ const DEFAULT_PAGING_META = (query: Query): OffsetPagingMeta => ( }); export class OffsetPager implements Pager> { - async page(queryMany: QueryMany, query: Query, count: Count): Promise> { + async page>( + queryMany: QueryMany, + query: Q, + count: Count, + ): Promise> { const pagingMeta = this.getPageMeta(query); if (!this.isValidPaging(pagingMeta)) { return EMPTY_PAGING_RESULTS(); @@ -28,9 +32,9 @@ export class OffsetPager implements Pager> { return pagingMeta.opts.limit > 0; } - private async runQuery( - queryMany: QueryMany, - query: Query, + private async runQuery>( + queryMany: QueryMany, + query: Q, pagingMeta: OffsetPagingMeta, ): Promise> { const windowedQuery = this.createQuery(query, pagingMeta); @@ -63,7 +67,7 @@ export class OffsetPager implements Pager> { return { nodes, pageInfo, totalCount }; } - private createQuery(query: OffsetQueryArgsType, pagingMeta: OffsetPagingMeta): Query { + private createQuery>(query: Q, pagingMeta: OffsetPagingMeta): Q { const { limit, offset } = pagingMeta.opts; return { ...query, paging: { limit: limit + 1, offset } }; }