@vantreeseba/drizzle-graphql 8.2.0 → 8.2.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/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Column, Table, Relation, SQL, TablesRelationalConfig, One, Many } from 'drizzle-orm';
2
- import { MySqlDatabase } from 'drizzle-orm/mysql-core';
2
+ import { MySqlAsyncDatabase } from 'drizzle-orm/mysql-core';
3
3
  import { PgAsyncDatabase } from 'drizzle-orm/pg-core';
4
- import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
4
+ import { SQLiteAsyncDatabase } from 'drizzle-orm/sqlite-core';
5
5
  import { ASTNode, GraphQLError, GraphQLScalarType, GraphQLOutputType, GraphQLInputType, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLSchema, GraphQLInputObjectType, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLEnumType } from 'graphql';
6
6
  import { ResolveTree } from 'graphql-parse-resolve-info';
7
7
  export { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from 'graphql-scalars';
@@ -698,16 +698,16 @@ type Relations<TTable extends string = string, TConfig extends Record<string, Re
698
698
  config: (helpers: unknown) => TConfig;
699
699
  };
700
700
 
701
- type AnyDrizzleDB<TSchema extends Record<string, any>> = PgAsyncDatabase<any, TSchema> | BaseSQLiteDatabase<any, any, TSchema> | MySqlDatabase<any, any, TSchema>;
701
+ type AnyDrizzleDB<TSchema extends Record<string, any>> = PgAsyncDatabase<any, TSchema> | SQLiteAsyncDatabase<any, any, TSchema> | MySqlAsyncDatabase<any, TSchema>;
702
702
  /**
703
703
  * The tables a database handle knows about, keyed by their schema key.
704
704
  *
705
- * Two shapes reach this type, because drizzle-orm v1 changed what a database's generic slot
706
- * holds. SQLite and MySQL handles still carry the schema module itself, so the tables are
707
- * picked out of it directly. PostgreSQL handles carry only the relations config built by
708
- * `buildRelations` — a `Record<string, { table; name; relations }>` — so the tables are read
709
- * off its `table` members instead. Without the second branch every PG-derived type collapses
710
- * to `never`.
705
+ * Two shapes reach this type. Every dialect's handle now carries the relations config built
706
+ * by `buildRelations` — a `Record<string, { table; name; relations }>` — so the tables are
707
+ * read off its `table` members. The second branch keeps working for a plain schema module
708
+ * passed in directly, which is what a caller writing `ExtractTables<typeof schema>` hands it.
709
+ * The two branches differ in one detail: a module's members are `readonly`, a
710
+ * relations config's are not, so the derived entity types are `readonly` only on that path.
711
711
  */
712
712
  type ExtractTables<TSchema extends Record<string, Table | unknown>> = TSchema extends TablesRelationalConfig ? {
713
713
  [K in keyof TSchema]: TSchema[K]['table'] extends infer TTable extends Table ? TTable : never;
@@ -1013,9 +1013,9 @@ type GeneratedOutputs<TSchema extends Record<string, Table>, IsReturnless extend
1013
1013
  } : {
1014
1014
  [TName in keyof TSchema as TName extends string ? Capitalize<TName> : never]: GraphQLObjectType;
1015
1015
  });
1016
- type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends Record<string, unknown> = TDatabase extends AnyDrizzleDB<infer ISchema> ? ISchema : never, TSchemaTables extends ExtractTables<TSchema> = ExtractTables<TSchema>, TSchemaRelations extends ExtractRelations<TSchema> = ExtractRelations<TSchema>, TInputs extends GeneratedInputs<TSchemaTables> = GeneratedInputs<TSchemaTables>, TOutputs extends GeneratedOutputs<TSchemaTables, TDatabase extends MySqlDatabase<any, any, any, any> ? true : false> = GeneratedOutputs<TSchemaTables, TDatabase extends MySqlDatabase<any, any, any, any> ? true : false>> = {
1016
+ type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends Record<string, unknown> = TDatabase extends AnyDrizzleDB<infer ISchema> ? ISchema : never, TSchemaTables extends ExtractTables<TSchema> = ExtractTables<TSchema>, TSchemaRelations extends ExtractRelations<TSchema> = ExtractRelations<TSchema>, TInputs extends GeneratedInputs<TSchemaTables> = GeneratedInputs<TSchemaTables>, TOutputs extends GeneratedOutputs<TSchemaTables, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false> = GeneratedOutputs<TSchemaTables, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false>> = {
1017
1017
  queries: QueriesCore<TSchemaTables, TSchemaRelations, TInputs, TOutputs>;
1018
- mutations: MutationsCore<TSchemaTables, TInputs, TOutputs, TDatabase extends MySqlDatabase<any, any, any, any> ? true : false>;
1018
+ mutations: MutationsCore<TSchemaTables, TInputs, TOutputs, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false>;
1019
1019
  inputs: TInputs;
1020
1020
  types: TOutputs;
1021
1021
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Column, Table, Relation, SQL, TablesRelationalConfig, One, Many } from 'drizzle-orm';
2
- import { MySqlDatabase } from 'drizzle-orm/mysql-core';
2
+ import { MySqlAsyncDatabase } from 'drizzle-orm/mysql-core';
3
3
  import { PgAsyncDatabase } from 'drizzle-orm/pg-core';
4
- import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
4
+ import { SQLiteAsyncDatabase } from 'drizzle-orm/sqlite-core';
5
5
  import { ASTNode, GraphQLError, GraphQLScalarType, GraphQLOutputType, GraphQLInputType, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLSchema, GraphQLInputObjectType, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLEnumType } from 'graphql';
6
6
  import { ResolveTree } from 'graphql-parse-resolve-info';
7
7
  export { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from 'graphql-scalars';
@@ -698,16 +698,16 @@ type Relations<TTable extends string = string, TConfig extends Record<string, Re
698
698
  config: (helpers: unknown) => TConfig;
699
699
  };
700
700
 
701
- type AnyDrizzleDB<TSchema extends Record<string, any>> = PgAsyncDatabase<any, TSchema> | BaseSQLiteDatabase<any, any, TSchema> | MySqlDatabase<any, any, TSchema>;
701
+ type AnyDrizzleDB<TSchema extends Record<string, any>> = PgAsyncDatabase<any, TSchema> | SQLiteAsyncDatabase<any, any, TSchema> | MySqlAsyncDatabase<any, TSchema>;
702
702
  /**
703
703
  * The tables a database handle knows about, keyed by their schema key.
704
704
  *
705
- * Two shapes reach this type, because drizzle-orm v1 changed what a database's generic slot
706
- * holds. SQLite and MySQL handles still carry the schema module itself, so the tables are
707
- * picked out of it directly. PostgreSQL handles carry only the relations config built by
708
- * `buildRelations` — a `Record<string, { table; name; relations }>` — so the tables are read
709
- * off its `table` members instead. Without the second branch every PG-derived type collapses
710
- * to `never`.
705
+ * Two shapes reach this type. Every dialect's handle now carries the relations config built
706
+ * by `buildRelations` — a `Record<string, { table; name; relations }>` — so the tables are
707
+ * read off its `table` members. The second branch keeps working for a plain schema module
708
+ * passed in directly, which is what a caller writing `ExtractTables<typeof schema>` hands it.
709
+ * The two branches differ in one detail: a module's members are `readonly`, a
710
+ * relations config's are not, so the derived entity types are `readonly` only on that path.
711
711
  */
712
712
  type ExtractTables<TSchema extends Record<string, Table | unknown>> = TSchema extends TablesRelationalConfig ? {
713
713
  [K in keyof TSchema]: TSchema[K]['table'] extends infer TTable extends Table ? TTable : never;
@@ -1013,9 +1013,9 @@ type GeneratedOutputs<TSchema extends Record<string, Table>, IsReturnless extend
1013
1013
  } : {
1014
1014
  [TName in keyof TSchema as TName extends string ? Capitalize<TName> : never]: GraphQLObjectType;
1015
1015
  });
1016
- type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends Record<string, unknown> = TDatabase extends AnyDrizzleDB<infer ISchema> ? ISchema : never, TSchemaTables extends ExtractTables<TSchema> = ExtractTables<TSchema>, TSchemaRelations extends ExtractRelations<TSchema> = ExtractRelations<TSchema>, TInputs extends GeneratedInputs<TSchemaTables> = GeneratedInputs<TSchemaTables>, TOutputs extends GeneratedOutputs<TSchemaTables, TDatabase extends MySqlDatabase<any, any, any, any> ? true : false> = GeneratedOutputs<TSchemaTables, TDatabase extends MySqlDatabase<any, any, any, any> ? true : false>> = {
1016
+ type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends Record<string, unknown> = TDatabase extends AnyDrizzleDB<infer ISchema> ? ISchema : never, TSchemaTables extends ExtractTables<TSchema> = ExtractTables<TSchema>, TSchemaRelations extends ExtractRelations<TSchema> = ExtractRelations<TSchema>, TInputs extends GeneratedInputs<TSchemaTables> = GeneratedInputs<TSchemaTables>, TOutputs extends GeneratedOutputs<TSchemaTables, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false> = GeneratedOutputs<TSchemaTables, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false>> = {
1017
1017
  queries: QueriesCore<TSchemaTables, TSchemaRelations, TInputs, TOutputs>;
1018
- mutations: MutationsCore<TSchemaTables, TInputs, TOutputs, TDatabase extends MySqlDatabase<any, any, any, any> ? true : false>;
1018
+ mutations: MutationsCore<TSchemaTables, TInputs, TOutputs, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false>;
1019
1019
  inputs: TInputs;
1020
1020
  types: TOutputs;
1021
1021
  /**
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // src/index.ts
2
2
  import { is as is13 } from "drizzle-orm";
3
- import { MySqlDatabase as MySqlDatabase2 } from "drizzle-orm/mysql-core";
3
+ import { MySqlAsyncDatabase as MySqlAsyncDatabase2 } from "drizzle-orm/mysql-core";
4
4
  import { PgAsyncDatabase as PgAsyncDatabase2 } from "drizzle-orm/pg-core";
5
- import { BaseSQLiteDatabase as BaseSQLiteDatabase2 } from "drizzle-orm/sqlite-core";
5
+ import { SQLiteAsyncDatabase as SQLiteAsyncDatabase2 } from "drizzle-orm/sqlite-core";
6
6
  import {
7
7
  GraphQLObjectType as GraphQLObjectType5,
8
8
  GraphQLSchema
@@ -3118,6 +3118,7 @@ var BatchLoader = class {
3118
3118
  constructor(batchFn) {
3119
3119
  this.batchFn = batchFn;
3120
3120
  }
3121
+ batchFn;
3121
3122
  batch = [];
3122
3123
  scheduled = false;
3123
3124
  load(key) {
@@ -5615,7 +5616,7 @@ var createNestedWriteRuntime = (params) => {
5615
5616
  const scope = resolveScope(policies, context, filterCtx);
5616
5617
  for (const [relationName, op] of Object.entries(ops)) {
5617
5618
  const plan = tablePlans[relationName];
5618
- if (!plan || plan.fkSide !== "parent") {
5619
+ if (plan?.fkSide !== "parent") {
5619
5620
  continue;
5620
5621
  }
5621
5622
  assertSingleOperation(plan, op);
@@ -5657,7 +5658,7 @@ var createNestedWriteRuntime = (params) => {
5657
5658
  const scope = resolveScope(policies, context, filterCtx);
5658
5659
  for (const [relationName, op] of Object.entries(ops)) {
5659
5660
  const plan = tablePlans[relationName];
5660
- if (!plan || plan.fkSide !== "child") {
5661
+ if (plan?.fkSide !== "child") {
5661
5662
  continue;
5662
5663
  }
5663
5664
  if (plan.isOne) {
@@ -5747,7 +5748,7 @@ import { parseResolveInfo as parseResolveInfo2 } from "graphql-parse-resolve-inf
5747
5748
 
5748
5749
  // src/util/builders/errors.ts
5749
5750
  var missingQueryBuilderError = (tableName) => new Error(
5750
- `Drizzle-GraphQL Error: Table '${tableName}' was passed to the drizzle constructor's schema but is missing from its relations config, so drizzle-orm exposes no query builder for it. Include it in the relations you pass to buildRelations/defineRelations, or drop it from the generated schema with config.exclude.tables.`
5751
+ `Drizzle-GraphQL Error: Table '${tableName}' has no query builder on the drizzle instance, so there is nothing for its resolvers to read through. Include it in the relations you pass to buildRelations/defineRelations, or drop it from the generated schema with config.exclude.tables.`
5751
5752
  );
5752
5753
 
5753
5754
  // src/util/builders/select.ts
@@ -7758,19 +7759,19 @@ var generateSchemaData3 = (db, schema, relations, options) => sqliteSchemaData(d
7758
7759
 
7759
7760
  // src/util/selection.ts
7760
7761
  import { is as is12, Table as Table2 } from "drizzle-orm";
7761
- import { getTableConfig as getMySqlTableConfig, MySqlDatabase } from "drizzle-orm/mysql-core";
7762
+ import { getTableConfig as getMySqlTableConfig, MySqlAsyncDatabase } from "drizzle-orm/mysql-core";
7762
7763
  import { getTableConfig as getPgTableConfig, PgAsyncDatabase } from "drizzle-orm/pg-core";
7763
- import { BaseSQLiteDatabase, getTableConfig as getSQLiteTableConfig } from "drizzle-orm/sqlite-core";
7764
+ import { getTableConfig as getSQLiteTableConfig, SQLiteAsyncDatabase } from "drizzle-orm/sqlite-core";
7764
7765
  import { parseResolveInfo as parseResolveInfo5 } from "graphql-parse-resolve-info";
7765
7766
  var contextCache = /* @__PURE__ */ new WeakMap();
7766
7767
  var tableConfigFor = (db) => {
7767
- if (is12(db, MySqlDatabase)) {
7768
+ if (is12(db, MySqlAsyncDatabase)) {
7768
7769
  return getMySqlTableConfig;
7769
7770
  }
7770
7771
  if (is12(db, PgAsyncDatabase)) {
7771
7772
  return getPgTableConfig;
7772
7773
  }
7773
- if (is12(db, BaseSQLiteDatabase)) {
7774
+ if (is12(db, SQLiteAsyncDatabase)) {
7774
7775
  return getSQLiteTableConfig;
7775
7776
  }
7776
7777
  throw new Error("Drizzle-GraphQL Error: unsupported database instance \u2014 expected a PostgreSQL, MySQL or SQLite one.");
@@ -7781,7 +7782,7 @@ var contextFor = (db) => {
7781
7782
  return cached;
7782
7783
  }
7783
7784
  const relations = db._.relations ?? {};
7784
- const schema = db._.fullSchema ?? Object.fromEntries(
7785
+ const schema = Object.fromEntries(
7785
7786
  Object.entries(relations).filter(([, config]) => config?.table != null).map(([key, config]) => [key, config.table])
7786
7787
  );
7787
7788
  const tableEntries = Object.entries(schema).filter(([, value]) => is12(value, Table2));
@@ -7906,21 +7907,21 @@ var resolveSelection = async (info, options) => {
7906
7907
  // src/index.ts
7907
7908
  var buildSchema = (db, config) => {
7908
7909
  const relations = db._.relations;
7909
- const schema = db._.fullSchema ?? Object.fromEntries(
7910
+ const schema = Object.fromEntries(
7910
7911
  Object.entries(relations).filter(([, config2]) => config2?.table != null).map(([key, config2]) => [key, config2.table])
7911
7912
  );
7912
- if (!schema || !Object.keys(schema).length) {
7913
+ if (!Object.keys(schema).length) {
7913
7914
  throw new Error(
7914
7915
  "Drizzle-GraphQL Error: Schema not found in drizzle instance. Pass relations (from buildRelations/defineRelations) to the drizzle constructor so drizzle-graphql can detect your tables."
7915
7916
  );
7916
7917
  }
7917
7918
  const generatorOptions = resolveBuildConfig(config, schema);
7918
7919
  let generatorOutput;
7919
- if (is13(db, MySqlDatabase2)) {
7920
+ if (is13(db, MySqlAsyncDatabase2)) {
7920
7921
  generatorOutput = generateSchemaData(db, schema, relations, generatorOptions);
7921
7922
  } else if (is13(db, PgAsyncDatabase2)) {
7922
7923
  generatorOutput = generateSchemaData2(db, schema, relations, generatorOptions);
7923
- } else if (is13(db, BaseSQLiteDatabase2)) {
7924
+ } else if (is13(db, SQLiteAsyncDatabase2)) {
7924
7925
  generatorOutput = generateSchemaData3(db, schema, relations, generatorOptions);
7925
7926
  } else {
7926
7927
  throw new Error("Drizzle-GraphQL Error: Unknown database instance type");