@pothos/plugin-drizzle 0.15.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -462,6 +462,7 @@ export function wrapConnectionResult<T extends {}>(
462
462
  cursor: (node: T) => string,
463
463
  resolveNode?: (node: Record<string, unknown>) => unknown,
464
464
  parent?: unknown,
465
+ totalCount?: number | (() => MaybePromise<number>) | null,
465
466
  ) {
466
467
  const gotFullResults = results.length === Math.abs(limit);
467
468
  const hasNextPage = args.before ? true : args.last ? false : gotFullResults;
@@ -471,6 +472,7 @@ export function wrapConnectionResult<T extends {}>(
471
472
  const connection = {
472
473
  parent,
473
474
  args,
475
+ totalCount,
474
476
  edges: [] as ({ cursor: string; node: unknown } | null)[],
475
477
  pageInfo: {
476
478
  startCursor: null as string | null,
@@ -513,14 +515,16 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
513
515
  info: GraphQLResolveInfo,
514
516
  typeName: string,
515
517
  config: PothosDrizzleSchemaConfig,
516
- options: Omit<DrizzleCursorConnectionQueryOptions, 'orderBy' | 'config' | 'table'>,
518
+ options: Omit<DrizzleCursorConnectionQueryOptions, 'orderBy' | 'config' | 'table'> & {
519
+ totalCount?: () => MaybePromise<number>;
520
+ },
517
521
  resolve: (
518
522
  queryFn: (query: QueryForDrizzleConnection<SchemaTypes, TableRelationalConfig>) => SelectionMap,
519
523
  ) => MaybePromise<readonly T[]>,
520
524
  parent: unknown,
521
525
  ) {
522
526
  const table = config.relations[tableName];
523
- let query: DBQueryConfig<'many'>;
527
+ let query: DBQueryConfig<'many'> | undefined;
524
528
  let formatter: (node: Record<string, unknown>) => string;
525
529
  const results = await resolve((q = {}) => {
526
530
  const { cursorColumns, ...connectionQuery } = drizzleCursorConnectionQuery({
@@ -562,12 +566,29 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
562
566
  return results;
563
567
  }
564
568
 
569
+ // Handle totalCountOnly case where resolve returns [] without calling query function
570
+ if (!query) {
571
+ return {
572
+ parent,
573
+ args: options.args,
574
+ totalCount: options.totalCount,
575
+ edges: [],
576
+ pageInfo: {
577
+ startCursor: null,
578
+ endCursor: null,
579
+ hasPreviousPage: false,
580
+ hasNextPage: false,
581
+ },
582
+ };
583
+ }
584
+
565
585
  return wrapConnectionResult(
566
586
  results,
567
587
  options.args,
568
- query!.limit as number,
588
+ query.limit as number,
569
589
  formatter!,
570
590
  undefined,
571
591
  parent,
592
+ options.totalCount,
572
593
  );
573
594
  }