@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dts/connection-helpers.d.ts +2 -1
  3. package/dts/connection-helpers.d.ts.map +1 -1
  4. package/dts/drizzle-field-builder.d.ts.map +1 -1
  5. package/dts/global-types.d.ts +1 -1
  6. package/dts/global-types.d.ts.map +1 -1
  7. package/dts/types.d.ts +1 -3
  8. package/dts/types.d.ts.map +1 -1
  9. package/dts/utils/cursors.d.ts +1 -1
  10. package/dts/utils/cursors.d.ts.map +1 -1
  11. package/dts/utils/refs.d.ts +1 -1
  12. package/dts/utils/refs.d.ts.map +1 -1
  13. package/esm/connection-helpers.d.ts +2 -1
  14. package/esm/connection-helpers.d.ts.map +1 -1
  15. package/esm/connection-helpers.js.map +1 -1
  16. package/esm/drizzle-field-builder.d.ts.map +1 -1
  17. package/esm/drizzle-field-builder.js +1 -1
  18. package/esm/drizzle-field-builder.js.map +1 -1
  19. package/esm/field-builder.js +1 -1
  20. package/esm/field-builder.js.map +1 -1
  21. package/esm/global-types.d.ts +1 -1
  22. package/esm/global-types.d.ts.map +1 -1
  23. package/esm/schema-builder.js +6 -5
  24. package/esm/schema-builder.js.map +1 -1
  25. package/esm/types.d.ts +1 -3
  26. package/esm/types.d.ts.map +1 -1
  27. package/esm/types.js.map +1 -1
  28. package/esm/utils/cursors.d.ts +1 -1
  29. package/esm/utils/cursors.d.ts.map +1 -1
  30. package/esm/utils/cursors.js +2 -2
  31. package/esm/utils/cursors.js.map +1 -1
  32. package/esm/utils/refs.d.ts +1 -1
  33. package/esm/utils/refs.d.ts.map +1 -1
  34. package/esm/utils/refs.js +6 -1
  35. package/esm/utils/refs.js.map +1 -1
  36. package/lib/connection-helpers.js.map +1 -1
  37. package/lib/drizzle-field-builder.js +1 -1
  38. package/lib/drizzle-field-builder.js.map +1 -1
  39. package/lib/field-builder.js +1 -1
  40. package/lib/field-builder.js.map +1 -1
  41. package/lib/schema-builder.js +6 -5
  42. package/lib/schema-builder.js.map +1 -1
  43. package/lib/types.js.map +1 -1
  44. package/lib/utils/cursors.js +2 -2
  45. package/lib/utils/cursors.js.map +1 -1
  46. package/lib/utils/refs.js +6 -1
  47. package/lib/utils/refs.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/connection-helpers.ts +2 -1
  50. package/src/drizzle-field-builder.ts +2 -0
  51. package/src/field-builder.ts +1 -0
  52. package/src/global-types.ts +1 -1
  53. package/src/schema-builder.ts +8 -4
  54. package/src/types.ts +2 -7
  55. package/src/utils/cursors.ts +9 -1
  56. package/src/utils/refs.ts +13 -2
@@ -152,6 +152,7 @@ fieldBuilderProto.drizzleConnection = function drizzleConnection<
152
152
  return resolve(q as never, parent, args as never, context, info) as never;
153
153
  // );
154
154
  },
155
+ parent,
155
156
  );
156
157
  },
157
158
  },
@@ -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 DrizzleObjectRef<Types>
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<
@@ -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, name)
30
+ ? new DrizzleObjectRef(options.variant, table)
31
31
  : (getRefFromModel(table, this, 'object') as ObjectRef<SchemaTypes, unknown>);
32
32
 
33
- ref.name = name ?? table;
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
- const ref = new DrizzleInterfaceRef(name, table);
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,
@@ -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(results, options.args, query!.limit as number, formatter!);
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 { SchemaTypes } from '@pothos/core';
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
- return cache.get(name)! as never;
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
  }