mirror of
https://github.com/Ratstail91/sineql-demo.git
synced 2026-05-05 23:30:11 +10:00
Fixed update
This commit is contained in:
@@ -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) => {
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|||||||
Reference in New Issue
Block a user