drizzle-graphql-plus 0.8.33 → 0.8.34
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/index.cjs +85 -19
- package/index.cjs.map +1 -1
- package/index.d.cts +104 -74
- package/index.d.ts +104 -74
- package/index.js +80 -18
- package/index.js.map +1 -1
- package/package.json +2 -1
package/index.cjs
CHANGED
|
@@ -36,9 +36,13 @@ __export(src_exports, {
|
|
|
36
36
|
cleanupDataLoaderContext: () => cleanupDataLoaderContext,
|
|
37
37
|
createDataLoaderContext: () => createDataLoaderContext,
|
|
38
38
|
createExportMiddleware: () => createExportMiddleware,
|
|
39
|
+
exportDirectiveTypeDefs: () => exportDirectiveTypeDefs,
|
|
39
40
|
makeScalarAcceptExports: () => makeScalarAcceptExports,
|
|
40
41
|
setCustomGraphQL: () => setCustomGraphQL,
|
|
41
|
-
setCustomGraphQLTypes: () => setCustomGraphQLTypes
|
|
42
|
+
setCustomGraphQLTypes: () => setCustomGraphQLTypes,
|
|
43
|
+
useDataLoaderCleanup: () => useDataLoaderCleanup,
|
|
44
|
+
useDataLoaderCleanupOnly: () => useDataLoaderCleanupOnly,
|
|
45
|
+
useDataLoaderContext: () => useDataLoaderContext
|
|
42
46
|
});
|
|
43
47
|
module.exports = __toCommonJS(src_exports);
|
|
44
48
|
|
|
@@ -3611,6 +3615,7 @@ ${orderByFields.join("\n")}
|
|
|
3611
3615
|
}`);
|
|
3612
3616
|
}
|
|
3613
3617
|
const allDefs = [];
|
|
3618
|
+
customScalars2.add("JSON");
|
|
3614
3619
|
if (customScalars2.size > 0) {
|
|
3615
3620
|
for (const scalarName of Array.from(customScalars2).sort()) {
|
|
3616
3621
|
allDefs.push(`scalar ${scalarName}`);
|
|
@@ -4073,6 +4078,18 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4073
4078
|
if (!tableRelations) {
|
|
4074
4079
|
return mainResults;
|
|
4075
4080
|
}
|
|
4081
|
+
for (const mainResult of mainResults) {
|
|
4082
|
+
for (const [relName, { relation }] of Object.entries(tableRelations)) {
|
|
4083
|
+
const relationField = fields[relName];
|
|
4084
|
+
if (!relationField)
|
|
4085
|
+
continue;
|
|
4086
|
+
if ((0, import_drizzle_orm18.is)(relation, import_drizzle_orm18.One)) {
|
|
4087
|
+
mainResult[relName] = null;
|
|
4088
|
+
} else {
|
|
4089
|
+
mainResult[relName] = [];
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4076
4093
|
const primaryKeyColumn = Object.values(tableInfo.columns).find((col) => col.primary);
|
|
4077
4094
|
if (!primaryKeyColumn) {
|
|
4078
4095
|
throw new Error(`No primary key found for table ${tableInfo.name}`);
|
|
@@ -4448,20 +4465,11 @@ var generateMutations2 = (db, tables, relations) => {
|
|
|
4448
4465
|
return { mutations, deleteResultResolvers };
|
|
4449
4466
|
};
|
|
4450
4467
|
|
|
4451
|
-
// src/
|
|
4452
|
-
|
|
4453
|
-
return {
|
|
4454
|
-
relationLoaders: /* @__PURE__ */ new Map()
|
|
4455
|
-
};
|
|
4456
|
-
}
|
|
4457
|
-
function cleanupDataLoaderContext(context) {
|
|
4458
|
-
for (const loader of Array.from(context.relationLoaders.values())) {
|
|
4459
|
-
loader.clearAll();
|
|
4460
|
-
}
|
|
4461
|
-
context.relationLoaders.clear();
|
|
4462
|
-
}
|
|
4468
|
+
// src/export-tool/directive-definitions.ts
|
|
4469
|
+
var exportDirectiveTypeDefs = `directive @export(as: String!) on FIELD`;
|
|
4463
4470
|
|
|
4464
4471
|
// src/build-schema-sdl-with-dl/index.ts
|
|
4472
|
+
var import_schema3 = require("@graphql-tools/schema");
|
|
4465
4473
|
var buildSchemaSDL2 = (db) => {
|
|
4466
4474
|
const schema = db._.fullSchema;
|
|
4467
4475
|
if (!schema) {
|
|
@@ -4486,16 +4494,70 @@ var buildSchemaSDL2 = (db) => {
|
|
|
4486
4494
|
tables,
|
|
4487
4495
|
relations
|
|
4488
4496
|
);
|
|
4497
|
+
const resolvers = {
|
|
4498
|
+
Query: queries,
|
|
4499
|
+
Mutation: mutations,
|
|
4500
|
+
...deleteResultResolvers
|
|
4501
|
+
};
|
|
4489
4502
|
return {
|
|
4490
4503
|
typeDefs,
|
|
4491
|
-
resolvers
|
|
4492
|
-
Query: queries,
|
|
4493
|
-
Mutation: mutations,
|
|
4494
|
-
...deleteResultResolvers
|
|
4495
|
-
}
|
|
4504
|
+
resolvers
|
|
4496
4505
|
};
|
|
4497
4506
|
};
|
|
4498
4507
|
|
|
4508
|
+
// src/build-schema-sdl-with-dl/generator/utils/context.ts
|
|
4509
|
+
function createDataLoaderContext() {
|
|
4510
|
+
return {
|
|
4511
|
+
relationLoaders: /* @__PURE__ */ new Map()
|
|
4512
|
+
};
|
|
4513
|
+
}
|
|
4514
|
+
function cleanupDataLoaderContext(context) {
|
|
4515
|
+
for (const loader of Array.from(context.relationLoaders.values())) {
|
|
4516
|
+
loader.clearAll();
|
|
4517
|
+
}
|
|
4518
|
+
context.relationLoaders.clear();
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
// src/build-schema-sdl-with-dl/generator/utils/envelop-plugin.ts
|
|
4522
|
+
var useDataLoaderCleanup = (options) => ({
|
|
4523
|
+
onContextBuilding: ({ context, extendContext }) => {
|
|
4524
|
+
const dataLoaderContext = createDataLoaderContext();
|
|
4525
|
+
const contextExtension = dataLoaderContext;
|
|
4526
|
+
if (options?.db) {
|
|
4527
|
+
contextExtension.db = options.db;
|
|
4528
|
+
}
|
|
4529
|
+
extendContext(contextExtension);
|
|
4530
|
+
},
|
|
4531
|
+
onExecute: ({ args }) => ({
|
|
4532
|
+
onExecuteDone: () => {
|
|
4533
|
+
const context = args.contextValue;
|
|
4534
|
+
if (context && context.relationLoaders) {
|
|
4535
|
+
cleanupDataLoaderContext(context);
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
})
|
|
4539
|
+
});
|
|
4540
|
+
var useDataLoaderContext = (options) => ({
|
|
4541
|
+
onContextBuilding: ({ context, extendContext }) => {
|
|
4542
|
+
const dataLoaderContext = createDataLoaderContext();
|
|
4543
|
+
const contextExtension = dataLoaderContext;
|
|
4544
|
+
if (options?.db) {
|
|
4545
|
+
contextExtension.db = options.db;
|
|
4546
|
+
}
|
|
4547
|
+
extendContext(contextExtension);
|
|
4548
|
+
}
|
|
4549
|
+
});
|
|
4550
|
+
var useDataLoaderCleanupOnly = () => ({
|
|
4551
|
+
onExecute: ({ args }) => ({
|
|
4552
|
+
onExecuteDone: () => {
|
|
4553
|
+
const context = args.contextValue;
|
|
4554
|
+
if (context && context.relationLoaders) {
|
|
4555
|
+
cleanupDataLoaderContext(context);
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
})
|
|
4559
|
+
});
|
|
4560
|
+
|
|
4499
4561
|
// src/export-tool/ExportStore.ts
|
|
4500
4562
|
var ExportStore = class {
|
|
4501
4563
|
store = /* @__PURE__ */ new Map();
|
|
@@ -4685,8 +4747,12 @@ function setCustomGraphQLTypes(table, columnTypes) {
|
|
|
4685
4747
|
cleanupDataLoaderContext,
|
|
4686
4748
|
createDataLoaderContext,
|
|
4687
4749
|
createExportMiddleware,
|
|
4750
|
+
exportDirectiveTypeDefs,
|
|
4688
4751
|
makeScalarAcceptExports,
|
|
4689
4752
|
setCustomGraphQL,
|
|
4690
|
-
setCustomGraphQLTypes
|
|
4753
|
+
setCustomGraphQLTypes,
|
|
4754
|
+
useDataLoaderCleanup,
|
|
4755
|
+
useDataLoaderCleanupOnly,
|
|
4756
|
+
useDataLoaderContext
|
|
4691
4757
|
});
|
|
4692
4758
|
//# sourceMappingURL=index.cjs.map
|