Fixed update

This commit is contained in:
2023-05-02 07:08:50 +10:00
parent 40ce5badbd
commit cdb0653e38
2 changed files with 25 additions and 4 deletions
+8 -4
View File
@@ -96,11 +96,13 @@ const createBook = async (query, typeGraph) => {
}; };
const updateBookFields = (query) => { const updateBookFields = (query) => {
//the array of objects to update const final = [];
const updates = {};
const where = {};
query.forEach((q) => { query.forEach((q) => {
//the array of objects to update
const updates = {};
const where = {};
//just in case //just in case
if (!q.update && !q.match) { if (!q.update && !q.match) {
throw 'Unexpected field (expected an update or match keyword)'; 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) => { const updateBook = async (query, typeGraph) => {
+17
View File
@@ -1,8 +1,25 @@
POST http://sineql-demo.krgamestudios.com/sineql HTTP/1.1 POST http://sineql-demo.krgamestudios.com/sineql HTTP/1.1
Content-Type: text/plain 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 { Book {
title title
published
} }
### ###