@pothos/plugin-drizzle 0.10.1 → 0.10.3
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 +12 -0
- package/dts/connection-helpers.d.ts +2 -1
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts +1 -1
- package/dts/global-types.d.ts.map +1 -1
- package/dts/types.d.ts +1 -3
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +1 -1
- package/dts/utils/cursors.d.ts.map +1 -1
- package/dts/utils/refs.d.ts +1 -1
- package/dts/utils/refs.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +2 -1
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/connection-helpers.js.map +1 -1
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/drizzle-field-builder.js +1 -1
- package/esm/drizzle-field-builder.js.map +1 -1
- package/esm/field-builder.js +1 -1
- package/esm/field-builder.js.map +1 -1
- package/esm/global-types.d.ts +1 -1
- package/esm/global-types.d.ts.map +1 -1
- package/esm/schema-builder.js +6 -5
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +1 -3
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/cursors.d.ts +1 -1
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/cursors.js +2 -2
- package/esm/utils/cursors.js.map +1 -1
- package/esm/utils/refs.d.ts +1 -1
- package/esm/utils/refs.d.ts.map +1 -1
- package/esm/utils/refs.js +6 -1
- package/esm/utils/refs.js.map +1 -1
- package/lib/connection-helpers.js.map +1 -1
- package/lib/drizzle-field-builder.js +1 -1
- package/lib/drizzle-field-builder.js.map +1 -1
- package/lib/field-builder.js +1 -1
- package/lib/field-builder.js.map +1 -1
- package/lib/schema-builder.js +6 -5
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/cursors.js +2 -2
- package/lib/utils/cursors.js.map +1 -1
- package/lib/utils/refs.js +6 -1
- package/lib/utils/refs.js.map +1 -1
- package/package.json +3 -3
- package/src/connection-helpers.ts +2 -1
- package/src/drizzle-field-builder.ts +2 -0
- package/src/field-builder.ts +1 -0
- package/src/global-types.ts +1 -1
- package/src/schema-builder.ts +8 -4
- package/src/types.ts +2 -7
- package/src/utils/cursors.ts +9 -1
- package/src/utils/refs.ts +13 -2
package/src/field-builder.ts
CHANGED
package/src/global-types.ts
CHANGED
|
@@ -194,7 +194,7 @@ declare global {
|
|
|
194
194
|
|
|
195
195
|
drizzleInterfaceFields: <
|
|
196
196
|
Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelationsConfig'],
|
|
197
|
-
TableConfig extends TableRelationalConfig = Type extends
|
|
197
|
+
TableConfig extends TableRelationalConfig = Type extends DrizzleInterfaceRef<Types>
|
|
198
198
|
? Type[typeof drizzleTableKey]
|
|
199
199
|
: Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
|
|
200
200
|
Shape extends {} = Type extends DrizzleInterfaceRef<
|
package/src/schema-builder.ts
CHANGED
|
@@ -27,10 +27,10 @@ schemaBuilderProto.drizzleObject = function drizzleObject(table, { select, field
|
|
|
27
27
|
const name = options.variant ?? options.name ?? table;
|
|
28
28
|
|
|
29
29
|
const ref = options.variant
|
|
30
|
-
? new DrizzleObjectRef(options.variant,
|
|
30
|
+
? new DrizzleObjectRef(options.variant, table)
|
|
31
31
|
: (getRefFromModel(table, this, 'object') as ObjectRef<SchemaTypes, unknown>);
|
|
32
32
|
|
|
33
|
-
ref.name = name
|
|
33
|
+
ref.name = name;
|
|
34
34
|
|
|
35
35
|
this.objectType(ref, {
|
|
36
36
|
...(options as {}),
|
|
@@ -52,9 +52,13 @@ schemaBuilderProto.drizzleInterface = function drizzleInterface(
|
|
|
52
52
|
table,
|
|
53
53
|
{ select, fields, ...options },
|
|
54
54
|
) {
|
|
55
|
-
const name = options.name ?? table;
|
|
55
|
+
const name = options.variant ?? options.name ?? table;
|
|
56
|
+
|
|
57
|
+
const ref = options.variant
|
|
58
|
+
? new DrizzleInterfaceRef(options.variant, table)
|
|
59
|
+
: (getRefFromModel(table, this, 'interface') as InterfaceRef<SchemaTypes, unknown>);
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
ref.name = name;
|
|
58
62
|
|
|
59
63
|
this.interfaceType(ref, {
|
|
60
64
|
...(options as {}),
|
package/src/types.ts
CHANGED
|
@@ -113,14 +113,9 @@ export type DrizzleInterfaceOptions<
|
|
|
113
113
|
Shape,
|
|
114
114
|
Selection,
|
|
115
115
|
Interfaces extends InterfaceParam<Types>[],
|
|
116
|
-
> = Omit<
|
|
117
|
-
InterfaceTypeOptions<Types, InterfaceRef<Types, Shape>, Shape, Interfaces> & {
|
|
118
|
-
name: string;
|
|
119
|
-
select?: Selection;
|
|
120
|
-
},
|
|
121
|
-
'fields'
|
|
122
|
-
> &
|
|
116
|
+
> = Omit<InterfaceTypeOptions<Types, InterfaceRef<Types, Shape>, Shape, Interfaces>, 'fields'> &
|
|
123
117
|
NameOrVariant & {
|
|
118
|
+
select?: Selection;
|
|
124
119
|
fields?: (
|
|
125
120
|
t: DrizzleObjectFieldBuilder<
|
|
126
121
|
Types,
|
package/src/utils/cursors.ts
CHANGED
|
@@ -513,6 +513,7 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
|
|
|
513
513
|
resolve: (
|
|
514
514
|
queryFn: (query: QueryForDrizzleConnection<SchemaTypes, TableRelationalConfig>) => SelectionMap,
|
|
515
515
|
) => MaybePromise<readonly T[]>,
|
|
516
|
+
parent: unknown,
|
|
516
517
|
) {
|
|
517
518
|
const table = config.relations.tablesConfig[tableName];
|
|
518
519
|
let query: DBQueryConfig<'many'>;
|
|
@@ -557,5 +558,12 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
|
|
|
557
558
|
return results;
|
|
558
559
|
}
|
|
559
560
|
|
|
560
|
-
return wrapConnectionResult(
|
|
561
|
+
return wrapConnectionResult(
|
|
562
|
+
results,
|
|
563
|
+
options.args,
|
|
564
|
+
query!.limit as number,
|
|
565
|
+
formatter!,
|
|
566
|
+
undefined,
|
|
567
|
+
parent,
|
|
568
|
+
);
|
|
561
569
|
}
|
package/src/utils/refs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { PothosSchemaError, type SchemaTypes } from '@pothos/core';
|
|
2
2
|
import { DrizzleInterfaceRef, type DrizzleRef } from '../interface-ref';
|
|
3
3
|
import { DrizzleObjectRef } from '../object-ref';
|
|
4
4
|
|
|
@@ -21,5 +21,16 @@ export function getRefFromModel<Types extends SchemaTypes>(
|
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const ref = cache.get(name) as unknown as DrizzleRef<Types>;
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
(type === 'interface' && !(ref instanceof DrizzleInterfaceRef)) ||
|
|
28
|
+
(type === 'object' && !(ref instanceof DrizzleObjectRef))
|
|
29
|
+
) {
|
|
30
|
+
throw new PothosSchemaError(
|
|
31
|
+
`Drizzle table ${name} was created as both an object and interface. Use 'variant' instead of 'name' in one of the implementations`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return ref;
|
|
25
36
|
}
|