drizzle-graphql-plus 0.8.21 → 0.8.23
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 +35 -8
- package/index.cjs.map +1 -1
- package/index.js +35 -8
- 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(
|
|
@@ -2497,6 +2498,12 @@ ${orderByFields.join("\n")}
|
|
|
2497
2498
|
}`);
|
|
2498
2499
|
}
|
|
2499
2500
|
const allDefs = [];
|
|
2501
|
+
allDefs.push(`enum OPERATION {
|
|
2502
|
+
READ
|
|
2503
|
+
INSERTED
|
|
2504
|
+
UPDATED
|
|
2505
|
+
DELETED
|
|
2506
|
+
}`);
|
|
2500
2507
|
if (customScalars.size > 0) {
|
|
2501
2508
|
for (const scalarName of Array.from(customScalars).sort()) {
|
|
2502
2509
|
allDefs.push(`scalar ${scalarName}`);
|
|
@@ -2806,7 +2813,10 @@ var createQueryResolver = (queryBase, tableInfo, tables, relations) => {
|
|
|
2806
2813
|
allFields
|
|
2807
2814
|
)
|
|
2808
2815
|
});
|
|
2809
|
-
return result
|
|
2816
|
+
return result.map((row) => ({
|
|
2817
|
+
...row,
|
|
2818
|
+
_operation: "READ"
|
|
2819
|
+
}));
|
|
2810
2820
|
} catch (e) {
|
|
2811
2821
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2812
2822
|
throw new import_graphql8.GraphQLError(String(e.message));
|
|
@@ -2879,6 +2889,7 @@ var buildWhereClause2 = (tableInfo, where) => {
|
|
|
2879
2889
|
};
|
|
2880
2890
|
var generateMutations = (db, tables, relations) => {
|
|
2881
2891
|
const mutations = {};
|
|
2892
|
+
const deleteResultResolvers = {};
|
|
2882
2893
|
for (const [tableName, tableInfo] of Object.entries(tables)) {
|
|
2883
2894
|
const capitalizedName = capitalize(tableName);
|
|
2884
2895
|
const queryBase = db.query[tableName];
|
|
@@ -2915,7 +2926,7 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2915
2926
|
const insertedIds = insertedRows.map(
|
|
2916
2927
|
(row) => row[primaryKeyColumn.name]
|
|
2917
2928
|
);
|
|
2918
|
-
|
|
2929
|
+
const result = await queryResolver(
|
|
2919
2930
|
parent,
|
|
2920
2931
|
{
|
|
2921
2932
|
where: {
|
|
@@ -2925,6 +2936,10 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2925
2936
|
context,
|
|
2926
2937
|
info
|
|
2927
2938
|
);
|
|
2939
|
+
return result.map((row) => ({
|
|
2940
|
+
...row,
|
|
2941
|
+
_operation: "INSERTED"
|
|
2942
|
+
}));
|
|
2928
2943
|
} catch (e) {
|
|
2929
2944
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2930
2945
|
throw new import_graphql9.GraphQLError(String(e.message));
|
|
@@ -2948,7 +2963,7 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2948
2963
|
const updatedIds = updatedRows.map(
|
|
2949
2964
|
(row) => row[primaryKeyColumn.name]
|
|
2950
2965
|
);
|
|
2951
|
-
|
|
2966
|
+
const result = await queryResolver(
|
|
2952
2967
|
parent,
|
|
2953
2968
|
{
|
|
2954
2969
|
where: {
|
|
@@ -2958,6 +2973,10 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2958
2973
|
context,
|
|
2959
2974
|
info
|
|
2960
2975
|
);
|
|
2976
|
+
return result.map((row) => ({
|
|
2977
|
+
...row,
|
|
2978
|
+
_operation: "UPDATED"
|
|
2979
|
+
}));
|
|
2961
2980
|
} catch (e) {
|
|
2962
2981
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2963
2982
|
throw new import_graphql9.GraphQLError(String(e.message));
|
|
@@ -2973,8 +2992,11 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2973
2992
|
if (whereClause) {
|
|
2974
2993
|
deleteQuery = deleteQuery.where(whereClause);
|
|
2975
2994
|
}
|
|
2976
|
-
const
|
|
2977
|
-
return
|
|
2995
|
+
const deletedRows = await deleteQuery.returning();
|
|
2996
|
+
return deletedRows.map((row) => ({
|
|
2997
|
+
...row,
|
|
2998
|
+
_operation: "DELETED"
|
|
2999
|
+
}));
|
|
2978
3000
|
} catch (e) {
|
|
2979
3001
|
if (typeof e === "object" && e !== null && "message" in e) {
|
|
2980
3002
|
throw new import_graphql9.GraphQLError(String(e.message));
|
|
@@ -2983,7 +3005,7 @@ var generateMutations = (db, tables, relations) => {
|
|
|
2983
3005
|
}
|
|
2984
3006
|
};
|
|
2985
3007
|
}
|
|
2986
|
-
return mutations;
|
|
3008
|
+
return { mutations, deleteResultResolvers: {} };
|
|
2987
3009
|
};
|
|
2988
3010
|
|
|
2989
3011
|
// src/buildSchemaSDL/index.ts
|
|
@@ -3006,12 +3028,17 @@ var buildSchemaSDL = (db, config) => {
|
|
|
3006
3028
|
typeDefsArray.push(generateMutationTypeDefs(tables));
|
|
3007
3029
|
const typeDefs = typeDefsArray.join("\n\n");
|
|
3008
3030
|
const queries = generateQueries(db, tables, relations);
|
|
3009
|
-
const mutations = generateMutations(
|
|
3031
|
+
const { mutations, deleteResultResolvers } = generateMutations(
|
|
3032
|
+
db,
|
|
3033
|
+
tables,
|
|
3034
|
+
relations
|
|
3035
|
+
);
|
|
3010
3036
|
return {
|
|
3011
3037
|
typeDefs,
|
|
3012
3038
|
resolvers: {
|
|
3013
3039
|
Query: queries,
|
|
3014
|
-
Mutation: mutations
|
|
3040
|
+
Mutation: mutations,
|
|
3041
|
+
...deleteResultResolvers
|
|
3015
3042
|
}
|
|
3016
3043
|
};
|
|
3017
3044
|
};
|