Skip to content

Commit 4542e8d

Browse files
Merge branch 'develop' into DP-3835-gsg-simplifier-et-etandre-la-facon-dappeller-les-hooks-de-resolvers-et-ou-mutation-array
2 parents c51a4e7 + 1ddf1b4 commit 4542e8d

File tree

17 files changed

+555
-160
lines changed

17 files changed

+555
-160
lines changed

CHANGELOG.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,94 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [9.4.1](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.4.0...v9.4.1) (2025-03-26)
6+
7+
8+
### Bug Fixes
9+
10+
* **count:** Fix where and includes not initialized in the count hook like the list one. ([df10069](https://github.com/teamstarter/graphql-sequelize-generator/commit/df10069))
11+
12+
13+
14+
## [9.4.0](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.3.0...v9.4.0) (2025-03-26)
15+
16+
17+
### Features
18+
19+
* **hooks:** Harmonize hooks parametersnaming ([0fb5e05](https://github.com/teamstarter/graphql-sequelize-generator/commit/0fb5e05))
20+
21+
22+
23+
## [9.3.0](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.2.0...v9.3.0) (2025-03-26)
24+
25+
26+
### Features
27+
28+
* **hooks:** Make possible to type the context of the hooks. ([33f1859](https://github.com/teamstarter/graphql-sequelize-generator/commit/33f1859))
29+
30+
31+
32+
## [9.2.0](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.1.0...v9.2.0) (2025-03-25)
33+
34+
35+
### Features
36+
37+
* **hooks:** Initialize the includes and limit the way they work by default to make it easier to use in hooks. ([4996577](https://github.com/teamstarter/graphql-sequelize-generator/commit/4996577))
38+
39+
40+
41+
## [9.1.0](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.0.3...v9.1.0) (2025-03-25)
42+
43+
44+
### Features
45+
46+
* **list:** Improve the list resolver by initializing the where and typing it properly to avoid suggesting it could be a function while it's not possible through Graphql. ([9c6aaa2](https://github.com/teamstarter/graphql-sequelize-generator/commit/9c6aaa2))
47+
48+
49+
50+
### [9.0.3](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.0.2...v9.0.3) (2025-03-24)
51+
52+
53+
### Bug Fixes
54+
55+
* **subscription:** Fix regression. ([00ca8b6](https://github.com/teamstarter/graphql-sequelize-generator/commit/00ca8b6))
56+
57+
58+
59+
### [9.0.2](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.0.1...v9.0.2) (2025-03-24)
60+
61+
62+
### Bug Fixes
63+
64+
* **customHooks:** Fix create/update/delete complete overwrite. ([f6600f1](https://github.com/teamstarter/graphql-sequelize-generator/commit/f6600f1))
65+
66+
67+
68+
### [9.0.1](https://github.com/teamstarter/graphql-sequelize-generator/compare/v9.0.0...v9.0.1) (2025-03-24)
69+
70+
71+
### Bug Fixes
72+
73+
* **types:** Fix regression on declaration. ([d3b3545](https://github.com/teamstarter/graphql-sequelize-generator/commit/d3b3545))
74+
75+
76+
77+
## [9.0.0](https://github.com/teamstarter/graphql-sequelize-generator/compare/v8.7.4...v9.0.0) (2025-03-24)
78+
79+
80+
### Features
81+
82+
* **hooks:** Change global hook signature ([b15061b](https://github.com/teamstarter/graphql-sequelize-generator/commit/b15061b))
83+
* **hooks:** Change the signature of all the hooks to take an object instead of an array. ([bae8017](https://github.com/teamstarter/graphql-sequelize-generator/commit/bae8017))
84+
85+
86+
### BREAKING CHANGES
87+
88+
* **hooks:** Change the signature of all the hooks to take an object instead of an array.
89+
* **hooks:** change global hook signature
90+
91+
92+
593
### [8.7.4](https://github.com/teamstarter/graphql-sequelize-generator/compare/v8.7.3...v8.7.4) (2024-06-04)
694

795

lib/mutationResolvers/create.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function generateMutationCreate(modelName, inputType, outputType, model, graphql
8787
? graphqlModelDeclaration.create.extraArg
8888
: {})),
8989
resolve: function (source, args, context, info) { return __awaiter(_this, void 0, void 0, function () {
90-
var attributes, beforeList, beforeList_1, beforeList_1_1, before, handle, e_1_1, beforeList, beforeList_2, beforeList_2_1, before, beforeHandle, e_2_1, preventDuplicateAttributes_1, filters, entityDuplicate, newEntity, error_1, afterList, updatedEntity, hookData, afterList_1, afterList_1_1, after, afterHandle, e_3_1;
90+
var attributes, beforeList, beforeList_1, beforeList_1_1, before, handle, e_1_1, beforeList, beforeList_2, beforeList_2_1, before, beforeHandle, e_2_1, preventDuplicateAttributes_1, filters, entityDuplicate, newEntity, error_1, afterList, createdEntity, hookData, afterList_1, afterList_1_1, after, afterHandle, e_3_1;
9191
var e_1, _a, e_2, _b, e_3, _c, _d, _e;
9292
return __generator(this, function (_f) {
9393
switch (_f.label) {
@@ -221,8 +221,8 @@ function generateMutationCreate(modelName, inputType, outputType, model, graphql
221221
afterList = Array.isArray(graphqlModelDeclaration.create.after)
222222
? graphqlModelDeclaration.create.after
223223
: [graphqlModelDeclaration.create.after];
224-
updatedEntity = newEntity;
225-
hookData = { data: updatedEntity.get({ plain: true }) };
224+
createdEntity = newEntity;
225+
hookData = { data: createdEntity.get({ plain: true }) };
226226
_f.label = 24;
227227
case 24:
228228
_f.trys.push([24, 29, 30, 31]);
@@ -233,15 +233,15 @@ function generateMutationCreate(modelName, inputType, outputType, model, graphql
233233
after = afterList_1_1.value;
234234
afterHandle = globalPreCallback('createAfter');
235235
return [4 /*yield*/, after({
236-
newEntity: updatedEntity,
236+
createdEntity: createdEntity,
237237
source: source,
238238
args: args,
239239
context: context,
240240
info: info,
241241
setWebhookData: (0, setWebhookData_1["default"])(hookData)
242242
})];
243243
case 26:
244-
updatedEntity = _f.sent();
244+
createdEntity = _f.sent();
245245
if (afterHandle) {
246246
afterHandle();
247247
}
@@ -263,13 +263,13 @@ function generateMutationCreate(modelName, inputType, outputType, model, graphql
263263
case 31:
264264
if (pubSubInstance) {
265265
pubSubInstance.publish("".concat(modelName, "Created"), (_d = {},
266-
_d["".concat(modelName, "Created")] = updatedEntity.get(),
266+
_d["".concat(modelName, "Created")] = createdEntity.get(),
267267
_d));
268268
}
269269
return [4 /*yield*/, (0, callModelWebhook_1["default"])(modelName, graphqlModelDeclaration.webhooks, 'create', context, hookData.data, callWebhook)];
270270
case 32:
271271
_f.sent();
272-
return [2 /*return*/, updatedEntity];
272+
return [2 /*return*/, createdEntity];
273273
case 33:
274274
if (pubSubInstance) {
275275
pubSubInstance.publish("".concat(modelName, "Created"), (_e = {},

lib/mutationResolvers/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function generateMutationUpdate(modelName, inputType, outputType, graphqlModelDe
206206
afterHandle = globalPreCallback('updateAfter');
207207
return [4 /*yield*/, after({
208208
updatedEntity: updatedEntity,
209-
entitySnapshot: snapshotBeforeUpdate,
209+
previousPropertiesSnapshot: snapshotBeforeUpdate,
210210
source: source,
211211
args: args,
212212
context: context,

lib/queryResolvers/count.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ function countResolver(model, schemaDeclaration, globalPreCallback) {
105105
return [7 /*endfinally*/];
106106
case 8:
107107
findOptions = graphql_sequelize_1.argsToFindOptions["default"](args, Object.keys(model.getAttributes()));
108+
if (!findOptions.where) {
109+
findOptions.where = {};
110+
}
111+
if (typeof findOptions.include === 'undefined') {
112+
findOptions.include = [];
113+
}
108114
if (!countBefore) return [3 /*break*/, 16];
109115
beforeList = Array.isArray(countBefore)
110116
? countBefore

lib/queryResolvers/createListResolver.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6363
exports.__esModule = true;
6464
var graphql_sequelize_1 = require("graphql-sequelize");
6565
var sequelize_1 = require("sequelize");
66-
var removeUnusedAttributes_1 = __importDefault(require("../removeUnusedAttributes"));
66+
var removeUnusedAttributes_1 = __importDefault(require("./../removeUnusedAttributes"));
6767
function allowOrderOnAssociations(findOptions, model) {
6868
if (typeof findOptions.order === 'undefined') {
6969
return findOptions;
@@ -161,15 +161,15 @@ function allowOrderOnAssociations(findOptions, model) {
161161
return findOptions;
162162
}
163163
var argsAdvancedProcessing = function (findOptions, args, context, info, model, models) {
164-
findOptions = allowOrderOnAssociations(findOptions, model);
164+
var findOptionsWithFlatWhere = allowOrderOnAssociations(findOptions, model);
165165
// When an association uses a scope, we have to add it to the where condition by default.
166166
if (info.parentType &&
167167
models[info.parentType.name] &&
168168
models[info.parentType.name].associations[info.fieldName].scope) {
169-
findOptions.where = __assign(__assign({}, (findOptions.where ? findOptions.where : {})), models[info.parentType.name].associations[info.fieldName]
169+
findOptionsWithFlatWhere.where = __assign(__assign({}, (findOptions.where ? findOptions.where : {})), models[info.parentType.name].associations[info.fieldName]
170170
.scope);
171171
}
172-
return findOptions;
172+
return findOptionsWithFlatWhere;
173173
};
174174
function trimAndOptimizeFindOptions(_a) {
175175
var findOptions = _a.findOptions, graphqlTypeDeclaration = _a.graphqlTypeDeclaration, info = _a.info, models = _a.models, args = _a.args;
@@ -298,6 +298,12 @@ function createListResolver(graphqlTypeDeclaration, models, globalPreCallback, r
298298
return __generator(this, function (_c) {
299299
switch (_c.label) {
300300
case 0:
301+
if (!findOptions.where) {
302+
findOptions.where = {};
303+
}
304+
if (typeof findOptions.include === 'undefined') {
305+
findOptions.include = [];
306+
}
301307
processedFindOptions = argsAdvancedProcessing(findOptions, args, context, info, graphqlTypeDeclaration.model, models);
302308
if (graphqlTypeDeclaration.list &&
303309
graphqlTypeDeclaration.list.enforceMaxLimit) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@teamstarter/graphql-sequelize-generator",
3-
"version": "8.7.4",
3+
"version": "9.4.1",
44
"description": "A set of tools to easily generate a Graphql API from sequelize models.",
55
"keywords": [
66
"graphql",

src/mutationResolvers/create.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ export default function generateMutationCreate<M extends Model<any>>(
157157
? graphqlModelDeclaration.create.after
158158
: [graphqlModelDeclaration.create.after as CreateAfterHook<M>]
159159

160-
let updatedEntity = newEntity
161-
const hookData = { data: updatedEntity.get({ plain: true }) }
160+
let createdEntity = newEntity
161+
const hookData = { data: createdEntity.get({ plain: true }) }
162162
for (const after of afterList) {
163163
const afterHandle = globalPreCallback('createAfter')
164-
updatedEntity = await after({
165-
newEntity: updatedEntity,
164+
createdEntity = await after({
165+
createdEntity,
166166
source,
167167
args,
168168
context,
@@ -176,7 +176,7 @@ export default function generateMutationCreate<M extends Model<any>>(
176176

177177
if (pubSubInstance) {
178178
pubSubInstance.publish(`${modelName}Created`, {
179-
[`${modelName}Created`]: updatedEntity.get(),
179+
[`${modelName}Created`]: createdEntity.get(),
180180
})
181181
}
182182

@@ -189,7 +189,7 @@ export default function generateMutationCreate<M extends Model<any>>(
189189
callWebhook
190190
)
191191

192-
return updatedEntity
192+
return createdEntity
193193
}
194194

195195
if (pubSubInstance) {

src/mutationResolvers/delete.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import callModelWebhook from './callModelWebhook'
2020
* @param {*} models
2121
* @param {PubSub} pubSubInstance
2222
*/
23-
export default function generateMutationDelete<M extends Model<any>>(
23+
export default function generateMutationDelete<
24+
M extends Model<any>,
25+
TContext = any
26+
>(
2427
modelName: string,
2528
graphqlModelDeclaration: ModelDeclarationType<M>,
2629
models: SequelizeModels,

src/mutationResolvers/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default function generateMutationUpdate<M extends Model<any>>(
124124
const afterHandle = globalPreCallback('updateAfter')
125125
updatedEntity = await after({
126126
updatedEntity,
127-
entitySnapshot: snapshotBeforeUpdate,
127+
previousPropertiesSnapshot: snapshotBeforeUpdate,
128128
source,
129129
args,
130130
context,

src/queryResolvers/count.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
QueryBeforeHook,
99
} from '../types/types'
1010

11-
export default function countResolver<M extends Model<any>>(
11+
export default function countResolver<M extends Model<any>, TContext = any>(
1212
model: ModelStatic<M>,
1313
schemaDeclaration: ModelDeclarationType<M>,
1414
globalPreCallback: GlobalPreCallback
@@ -33,7 +33,7 @@ export default function countResolver<M extends Model<any>>(
3333
? schemaDeclaration.count.before
3434
: listBefore
3535

36-
return async (source: any, args: any, context: any, info: any) => {
36+
return async (source: any, args: any, context: TContext, info: any) => {
3737
if (schemaDeclaration.before) {
3838
const beforeList: GlobalBeforeHook[] = Array.isArray(
3939
schemaDeclaration.before
@@ -55,6 +55,14 @@ export default function countResolver<M extends Model<any>>(
5555
Object.keys(model.getAttributes())
5656
)
5757

58+
if (!findOptions.where) {
59+
findOptions.where = {}
60+
}
61+
62+
if (typeof findOptions.include === 'undefined') {
63+
findOptions.include = []
64+
}
65+
5866
if (countBefore) {
5967
const beforeList: QueryBeforeHook<M>[] = Array.isArray(countBefore)
6068
? countBefore

0 commit comments

Comments
 (0)