Skip to content

Commit bfc7041

Browse files
feat(hooks): Makes all hooks chain value return.
1 parent 4542e8d commit bfc7041

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

lib/mutationResolvers/create.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ function generateMutationCreate(modelName, inputType, outputType, model, graphql
148148
args: args,
149149
context: context,
150150
info: info
151-
})];
151+
})
152+
// The return value of the before hook is used as the attributes for the next hook
153+
];
152154
case 11:
153155
attributes = _f.sent();
156+
// The return value of the before hook is used as the attributes for the next hook
157+
args[modelName] = attributes;
154158
if (!attributes) {
155159
throw new Error('The before hook must always return the create method first parameter.');
156160
}

lib/mutationResolvers/delete.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ function generateMutationDelete(modelName, graphqlModelDeclaration, models, glob
147147
args: args,
148148
context: context,
149149
info: info
150-
})];
150+
})
151+
// The return value of the before hook is used as the where for the next hook
152+
];
151153
case 11:
152154
result = _e.sent();
155+
// The return value of the before hook is used as the where for the next hook
153156
if (result) {
154157
where = result;
155158
}
@@ -212,7 +215,7 @@ function generateMutationDelete(modelName, graphqlModelDeclaration, models, glob
212215
info: info
213216
})];
214217
case 21:
215-
_e.sent();
218+
entity = _e.sent();
216219
if (afterHandle) {
217220
afterHandle();
218221
}

lib/mutationResolvers/update.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ function generateMutationUpdate(modelName, inputType, outputType, graphqlModelDe
148148
args: args,
149149
context: context,
150150
info: info
151-
})];
151+
})
152+
// The return value of the before hook is used as the attributes for the next hook
153+
];
152154
case 11:
153155
data = _f.sent();
156+
// The return value of the before hook is used as the attributes for the next hook
157+
args[modelName] = data;
154158
if (beforeHandle) {
155159
beforeHandle();
156160
}

src/mutationResolvers/create.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export default function generateMutationCreate<M extends Model<any>>(
9090
info,
9191
})
9292

93+
// The return value of the before hook is used as the attributes for the next hook
94+
args[modelName] = attributes
95+
9396
if (!attributes) {
9497
throw new Error(
9598
'The before hook must always return the create method first parameter.'

src/mutationResolvers/delete.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,19 @@ export default function generateMutationDelete<
8181
context,
8282
info,
8383
})
84+
85+
// The return value of the before hook is used as the where for the next hook
8486
if (result) {
8587
where = result
8688
}
89+
8790
if (beforeHandle) {
8891
beforeHandle()
8992
}
9093
}
9194
}
9295

93-
const entity = await models[modelName].findOne({
96+
let entity = await models[modelName].findOne({
9497
where,
9598
} as FindOptions<M>)
9699

@@ -122,7 +125,7 @@ export default function generateMutationDelete<
122125

123126
for (const after of afterList) {
124127
const afterHandle = globalPreCallback('deleteAfter')
125-
await after({
128+
entity = await after({
126129
deletedEntity: entity,
127130
source,
128131
args,

src/mutationResolvers/update.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export default function generateMutationUpdate<M extends Model<any>>(
8585
context,
8686
info,
8787
})
88+
89+
// The return value of the before hook is used as the attributes for the next hook
90+
args[modelName] = data
91+
8892
if (beforeHandle) {
8993
beforeHandle()
9094
}

0 commit comments

Comments
 (0)