@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.
- package/CHANGELOG.md +17 -0
- package/README.md +419 -51
- package/dts/drizzle-field-builder.d.ts +14 -3
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +6 -0
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +6 -2
- package/dts/utils/cursors.d.ts.map +1 -1
- package/esm/drizzle-field-builder.d.ts +16 -3
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/drizzle-field-builder.js +144 -8
- package/esm/drizzle-field-builder.js.map +1 -1
- package/esm/field-builder.js +33 -2
- package/esm/field-builder.js.map +1 -1
- package/esm/types.d.ts +6 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/cursors.d.ts +6 -2
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/cursors.js +18 -2
- package/esm/utils/cursors.js.map +1 -1
- package/lib/drizzle-field-builder.js +142 -6
- package/lib/drizzle-field-builder.js.map +1 -1
- package/lib/field-builder.js +33 -2
- package/lib/field-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/cursors.js +18 -2
- package/lib/utils/cursors.js.map +1 -1
- package/package.json +5 -5
- package/src/drizzle-field-builder.ts +246 -3
- package/src/field-builder.ts +40 -1
- package/src/types.ts +20 -1
- package/src/utils/cursors.ts +24 -3
package/src/utils/cursors.ts
CHANGED
|
@@ -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
|
|
588
|
+
query.limit as number,
|
|
569
589
|
formatter!,
|
|
570
590
|
undefined,
|
|
571
591
|
parent,
|
|
592
|
+
options.totalCount,
|
|
572
593
|
);
|
|
573
594
|
}
|