From bb21bff83e8f8db45ba046eb0df7ffcd178366f2 Mon Sep 17 00:00:00 2001 From: Sam J Combs Date: Wed, 18 Dec 2024 11:39:53 -0500 Subject: [PATCH] fix: ensures seed cache updates upon seed patch --- backend/src/routes/seeds.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/src/routes/seeds.ts b/backend/src/routes/seeds.ts index 9c6558e..965ea5e 100644 --- a/backend/src/routes/seeds.ts +++ b/backend/src/routes/seeds.ts @@ -247,9 +247,30 @@ router.patch('/seeds', async (req: Request, res: Response) => { const {id, ...updateData} = req.body; const seed = await DI.seeds.findOne({id}); if (!seed) return res.status(404).json({message: 'Seed not found'}); + DI.seeds.assign(seed, updateData); await DI.em.persistAndFlush(seed); + + const mockServer = await getOrStartNewMockServer( + seed.graphId, + seed.variantName + ); + + mockServer?.seedManager.updateSeed( + seed.seedGroup.id.toString(), + seed.operationMatchArguments, + { + operationName: seed.operationName, + seedResponse: seed.seedResponse, + operationMatchArguments: seed.operationMatchArguments, + } + ); + + if (!mockServer) { + console.error('Could not start mock server'); + return res.status(422).json({message: 'Could not start mock server'}); + } + res.json({message: 'Seed updated successfully'}); }); - export default router;