@pothos/plugin-drizzle 0.13.0 → 0.14.0

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 (47) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +2 -2
  3. package/dts/drizzle-field-builder.d.ts.map +1 -1
  4. package/dts/global-types.d.ts.map +1 -1
  5. package/dts/utils/config.d.ts.map +1 -1
  6. package/dts/utils/drizzle-graphql.d.ts +1 -0
  7. package/dts/utils/drizzle-graphql.d.ts.map +1 -1
  8. package/dts/utils/usage.d.ts +1 -1
  9. package/esm/drizzle-field-builder.d.ts.map +1 -1
  10. package/esm/drizzle-field-builder.js +2 -1
  11. package/esm/drizzle-field-builder.js.map +1 -1
  12. package/esm/global-types.d.ts.map +1 -1
  13. package/esm/model-loader.js +2 -2
  14. package/esm/model-loader.js.map +1 -1
  15. package/esm/utils/config.d.ts.map +1 -1
  16. package/esm/utils/config.js +8 -12
  17. package/esm/utils/config.js.map +1 -1
  18. package/esm/utils/cursors.js +2 -2
  19. package/esm/utils/cursors.js.map +1 -1
  20. package/esm/utils/drizzle-graphql.d.ts +1 -0
  21. package/esm/utils/drizzle-graphql.d.ts.map +1 -1
  22. package/esm/utils/drizzle-graphql.js +1 -1
  23. package/esm/utils/drizzle-graphql.js.map +1 -1
  24. package/esm/utils/map-query.js +1 -2
  25. package/esm/utils/map-query.js.map +1 -1
  26. package/esm/utils/usage.d.ts +1 -1
  27. package/lib/drizzle-field-builder.js +2 -1
  28. package/lib/drizzle-field-builder.js.map +1 -1
  29. package/lib/model-loader.js +1 -1
  30. package/lib/model-loader.js.map +1 -1
  31. package/lib/utils/config.js +7 -11
  32. package/lib/utils/config.js.map +1 -1
  33. package/lib/utils/cursors.js +1 -1
  34. package/lib/utils/cursors.js.map +1 -1
  35. package/lib/utils/drizzle-graphql.js +233 -230
  36. package/lib/utils/drizzle-graphql.js.map +1 -1
  37. package/lib/utils/map-query.js +1 -2
  38. package/lib/utils/map-query.js.map +1 -1
  39. package/package.json +7 -7
  40. package/src/drizzle-field-builder.ts +2 -1
  41. package/src/global-types.ts +0 -4
  42. package/src/model-loader.ts +2 -2
  43. package/src/utils/config.ts +8 -12
  44. package/src/utils/cursors.ts +2 -2
  45. package/src/utils/drizzle-graphql.ts +1 -0
  46. package/src/utils/map-query.ts +1 -1
  47. package/src/utils/usage.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  import { createContextCache, type SchemaTypes } from '@pothos/core';
2
- import { type AnyRelations, type Column, getTableColumns, isTable, type Table } from 'drizzle-orm';
2
+ import { type AnyRelations, type Column, getColumns, isTable, type Table } from 'drizzle-orm';
3
3
  import type { DrizzleClient } from '../types';
4
4
 
5
5
  export interface PothosDrizzleSchemaConfig {
@@ -17,14 +17,12 @@ const configCache = createContextCache(
17
17
  relations = (builder.options.drizzle.client as DrizzleClient)._.relations;
18
18
  }
19
19
 
20
- const columnNameMappings: Record<string, string> = {};
20
+ const columnNameMappings = new Map<Column, string>();
21
21
 
22
22
  Object.values(relations).forEach(({ table }) => {
23
23
  if (isTable(table)) {
24
- Object.entries(getTableColumns(table)).forEach(([tsName, col]) => {
25
- if (col.uniqueName) {
26
- columnNameMappings[col.uniqueName] = tsName;
27
- }
24
+ Object.entries(getColumns(table)).forEach(([tsName, col]) => {
25
+ columnNameMappings.set(col, tsName);
28
26
  });
29
27
  }
30
28
  });
@@ -32,15 +30,13 @@ const configCache = createContextCache(
32
30
  return {
33
31
  skipDeferredFragments: builder.options.drizzle.skipDeferredFragments ?? true,
34
32
  columnToTsName: (column) => {
35
- if (!column.uniqueName) {
36
- throw new Error(`Column ${String(column.name)} has no uniqueName`);
37
- }
33
+ const tsName = columnNameMappings.get(column);
38
34
 
39
- if (!(column.uniqueName in columnNameMappings)) {
40
- throw new Error(`Typescript name not found for ${column.uniqueName}`);
35
+ if (!tsName) {
36
+ throw new Error(`Typescript name not found for column ${String(column.name)}`);
41
37
  }
42
38
 
43
- return columnNameMappings[column.uniqueName];
39
+ return tsName;
44
40
  },
45
41
  getPrimaryKey: (tableName) => {
46
42
  const tableConfig = builder.options.drizzle.getTableConfig(
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  type Column,
10
10
  type DBQueryConfig,
11
- getTableColumns,
11
+ getColumns,
12
12
  type SQL,
13
13
  type Table,
14
14
  type TableRelationalConfig,
@@ -322,7 +322,7 @@ function parseOrderBy(
322
322
  normalized.push({ direction: 'asc', column: field });
323
323
  }
324
324
  } else {
325
- const tableColumns = getTableColumns(table.table as Table);
325
+ const tableColumns = getColumns(table.table as Table);
326
326
  Object.entries(
327
327
  orderBy as {
328
328
  [k: string]: 'asc' | 'desc' | undefined;
@@ -1,3 +1,4 @@
1
+ export {};
1
2
  // import {
2
3
  // type Column,
3
4
  // type SQL,
@@ -567,7 +567,7 @@ export function getIndirectType(type: GraphQLNamedType, info: GraphQLResolveInfo
567
567
 
568
568
  while (targetType.extensions?.pothosIndirectInclude) {
569
569
  targetType = info.schema.getType(
570
- (targetType.extensions?.pothosIndirectInclude as IndirectInclude).getType(),
570
+ (targetType.extensions.pothosIndirectInclude as IndirectInclude).getType(),
571
571
  )!;
572
572
  }
573
573
 
@@ -1,6 +1,6 @@
1
1
  export const usageSymbol = Symbol.for('Pothos.isUsed');
2
2
 
3
- export function wrapWithUsageCheck<T extends Object>(obj: T): T {
3
+ export function wrapWithUsageCheck<T extends object>(obj: T): T {
4
4
  const result = {};
5
5
  let used = true;
6
6