From cdb0653e3811a515a0568c6961f6cf4246cd552b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 2 May 2023 07:08:50 +1000 Subject: [PATCH] Fixed update --- server/type-handlers/book-handlers.js | 12 ++++++++---- tools/request.rest | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/server/type-handlers/book-handlers.js b/server/type-handlers/book-handlers.js index 1693203..dd20a61 100644 --- a/server/type-handlers/book-handlers.js +++ b/server/type-handlers/book-handlers.js @@ -96,11 +96,13 @@ const createBook = async (query, typeGraph) => { }; const updateBookFields = (query) => { - //the array of objects to update - const updates = {}; - const where = {}; + const final = []; query.forEach((q) => { + //the array of objects to update + const updates = {}; + const where = {}; + //just in case if (!q.update && !q.match) { throw 'Unexpected field (expected an update or match keyword)'; @@ -129,9 +131,11 @@ const updateBookFields = (query) => { } }) ; + + final.push({ ...updates, ...where }); }); - return { updates: [{ ...updates, ...where }], updateOnDuplicate: Object.keys(updates) }; + return { updates: final, updateOnDuplicate: Object.keys(updates) }; }; const updateBook = async (query, typeGraph) => { diff --git a/tools/request.rest b/tools/request.rest index f4f2a64..ffbfd0c 100644 --- a/tools/request.rest +++ b/tools/request.rest @@ -1,8 +1,25 @@ POST http://sineql-demo.krgamestudios.com/sineql HTTP/1.1 Content-Type: text/plain +update Book [ + { + match title "foo" + update published "2020-01-01" + } + { + match title "Bar" + update published "2021-01-01" + } +] + +### + +POST http://sineql-demo.krgamestudios.com/sineql HTTP/1.1 +Content-Type: text/plain + Book { title + published } ###