drizzle-graphql-plus 0.8.22 → 0.8.24
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 +49 -9
- package/index.cjs.map +1 -1
- package/index.js +49 -9
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -2414,6 +2414,7 @@ var generateTypeDefs = (tables, relations) => {
|
|
|
2414
2414
|
}
|
|
2415
2415
|
fields.push(` ${columnName}: ${typeStr}`);
|
|
2416
2416
|
}
|
|
2417
|
+
fields.push(` _operation: OPERATION!`);
|
|
2417
2418
|
const tableRelations = relations[tableName];
|
|
2418
2419
|
if (tableRelations) {
|
|
2419
2420
|
for (const [relationName, relationInfo] of Object.entries(
|
|
@@ -2423,8 +2424,21 @@ var generateTypeDefs = (tables, relations) => {
|
|
|
2423
2424
|
const targetTableName = relationInfo.targetTableName;
|
|
2424
2425
|
const targetTypeName = capitalize(targetTableName);
|
|
2425
2426
|
if (isOne) {
|
|
2427
|
+
const relation = relationInfo.relation;
|
|
2428
|
+
const config = relation.config;
|
|
2429
|
+
let isNonNullable = false;
|
|
2430
|
+
if (config?.fields && config.fields.length > 0) {
|
|
2431
|
+
isNonNullable = config.fields.every((field) => {
|
|
2432
|
+
const fieldColumnName = field.name;
|
|
2433
|
+
const column = Object.values(tableInfo.columns).find(
|
|
2434
|
+
(col) => col.name === fieldColumnName
|
|
2435
|
+
);
|
|
2436
|
+
return column && column.notNull;
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
const nullableModifier = isNonNullable ? "!" : "";
|
|
2426
2440
|
fields.push(
|
|
2427
|
-
` ${relationName}(where: ${targetTypeName}Filters): ${targetTypeName}`
|
|
2441
|
+
` ${relationName}(where: ${targetTypeName}Filters): ${targetTypeName}${nullableModifier}`
|
|
2428
2442
|
);
|
|
2429
2443
|
} else {
|
|
2430
2444
|
fields.push(
|
|
@@ -2497,6 +2511,12 @@ ${orderByFields.join("\n")}
|
|
|
2497
2511
|
}`);
|
|
2498
2512
|
}
|
|
2499
2513
|
const allDefs = [];
|
|
2514
|
+
allDefs.push(`enum OPERATION {
|
|
2515
|
+
READ
|
|
2516
|
+
INSERTED
|
|
2517
|
+
UPDATED
|
|
2518
|
+
DELETED
|
|
2519
|
+
}`);
|
|
2500
2520
|
if (customScalars.size > 0) {
|
|
2501
2521
|
for (const scalarName of Array.from(customScalars).sort()) {
|
|
2502
2522
|
allDefs.push(`scalar ${scalarName}`);
|
|
@@ -2806,7 +2826,10 @@ var createQueryResolver = (queryBase, tableInfo, tables, relations) => {
|
|
|
2806
2826
|
allFields
|
|
2807
2827
|
)
|
|
2808
2828
|
});
|
|
2809
|
-
return result
|
|
2829
|
+
return result.map((row) => ({
|
|
2830
|
+
...row,
|
|
2831
|
+
_operation: "READ"
|
|
2832
|
+
}));
|
|
2810
2833
|
} catch (e) {
|
|
2811
2834
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2812
2835
|
throw new import_graphql8.GraphQLError(String(e.message));
|
|
@@ -2879,6 +2902,7 @@ var buildWhereClause2 = (tableInfo, where) => {
|
|
|
2879
2902
|
};
|
|
2880
2903
|
var generateMutations = (db, tables, relations) => {
|
|
2881
2904
|
const mutations = {};
|
|
2905
|
+
const deleteResultResolvers = {};
|
|
2882
2906
|
for (const [tableName, tableInfo] of Object.entries(tables)) {
|
|
2883
2907
|
const capitalizedName = capitalize(tableName);
|
|
2884
2908
|
const queryBase = db.query[tableName];
|
|
@@ -2915,7 +2939,7 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2915
2939
|
const insertedIds = insertedRows.map(
|
|
2916
2940
|
(row) => row[primaryKeyColumn.name]
|
|
2917
2941
|
);
|
|
2918
|
-
|
|
2942
|
+
const result = await queryResolver(
|
|
2919
2943
|
parent,
|
|
2920
2944
|
{
|
|
2921
2945
|
where: {
|
|
@@ -2925,6 +2949,10 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2925
2949
|
context,
|
|
2926
2950
|
info
|
|
2927
2951
|
);
|
|
2952
|
+
return result.map((row) => ({
|
|
2953
|
+
...row,
|
|
2954
|
+
_operation: "INSERTED"
|
|
2955
|
+
}));
|
|
2928
2956
|
} catch (e) {
|
|
2929
2957
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2930
2958
|
throw new import_graphql9.GraphQLError(String(e.message));
|
|
@@ -2948,7 +2976,7 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2948
2976
|
const updatedIds = updatedRows.map(
|
|
2949
2977
|
(row) => row[primaryKeyColumn.name]
|
|
2950
2978
|
);
|
|
2951
|
-
|
|
2979
|
+
const result = await queryResolver(
|
|
2952
2980
|
parent,
|
|
2953
2981
|
{
|
|
2954
2982
|
where: {
|
|
@@ -2958,6 +2986,10 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2958
2986
|
context,
|
|
2959
2987
|
info
|
|
2960
2988
|
);
|
|
2989
|
+
return result.map((row) => ({
|
|
2990
|
+
...row,
|
|
2991
|
+
_operation: "UPDATED"
|
|
2992
|
+
}));
|
|
2961
2993
|
} catch (e) {
|
|
2962
2994
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2963
2995
|
throw new import_graphql9.GraphQLError(String(e.message));
|
|
@@ -2973,8 +3005,11 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2973
3005
|
if (whereClause) {
|
|
2974
3006
|
deleteQuery = deleteQuery.where(whereClause);
|
|
2975
3007
|
}
|
|
2976
|
-
const
|
|
2977
|
-
return
|
|
3008
|
+
const deletedRows = await deleteQuery.returning();
|
|
3009
|
+
return deletedRows.map((row) => ({
|
|
3010
|
+
...row,
|
|
3011
|
+
_operation: "DELETED"
|
|
3012
|
+
}));
|
|
2978
3013
|
} catch (e) {
|
|
2979
3014
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2980
3015
|
throw new import_graphql9.GraphQLError(String(e.message));
|
|
@@ -2983,7 +3018,7 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2983
3018
|
}
|
|
2984
3019
|
};
|
|
2985
3020
|
}
|
|
2986
|
-
return mutations;
|
|
3021
|
+
return { mutations, deleteResultResolvers: {} };
|
|
2987
3022
|
};
|
|
2988
3023
|
|
|
2989
3024
|
// src/buildSchemaSDL/index.ts
|
|
@@ -3006,12 +3041,17 @@ var buildSchemaSDL = (db, config) => {
|
|
|
3006
3041
|
typeDefsArray.push(generateMutationTypeDefs(tables));
|
|
3007
3042
|
const typeDefs = typeDefsArray.join("\n\n");
|
|
3008
3043
|
const queries = generateQueries(db, tables, relations);
|
|
3009
|
-
const mutations = generateMutations(
|
|
3044
|
+
const { mutations, deleteResultResolvers } = generateMutations(
|
|
3045
|
+
db,
|
|
3046
|
+
tables,
|
|
3047
|
+
relations
|
|
3048
|
+
);
|
|
3010
3049
|
return {
|
|
3011
3050
|
typeDefs,
|
|
3012
3051
|
resolvers: {
|
|
3013
3052
|
Query: queries,
|
|
3014
|
-
Mutation: mutations
|
|
3053
|
+
Mutation: mutations,
|
|
3054
|
+
...deleteResultResolvers
|
|
3015
3055
|
}
|
|
3016
3056
|
};
|
|
3017
3057
|
};
|