Fixed update handler

This commit is contained in:
2023-05-02 07:31:53 +10:00
parent cdb0653e38
commit e6b51f5374
2 changed files with 96 additions and 22 deletions
+4 -2
View File
@@ -97,6 +97,7 @@ const createBook = async (query, typeGraph) => {
const updateBookFields = (query) => { const updateBookFields = (query) => {
const final = []; const final = [];
let fields = [];
query.forEach((q) => { query.forEach((q) => {
//the array of objects to update //the array of objects to update
@@ -133,14 +134,15 @@ const updateBookFields = (query) => {
; ;
final.push({ ...updates, ...where }); final.push({ ...updates, ...where });
fields = fields.concat(Object.keys(updates));
}); });
return { updates: final, updateOnDuplicate: Object.keys(updates) }; return { updates: final, updateOnDuplicate: fields };
}; };
const updateBook = async (query, typeGraph) => { const updateBook = async (query, typeGraph) => {
const { updates, ...opts } = updateBookFields(query); const { updates, ...opts } = updateBookFields(query);
console.log(opts)
try { try {
await Book.bulkCreate( await Book.bulkCreate(
updates, updates,
+91 -19
View File
@@ -1,20 +1,4 @@
POST http://sineql-demo.krgamestudios.com/sineql HTTP/1.1 POST http://localhost:4000/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 Content-Type: text/plain
Book { Book {
@@ -27,6 +11,94 @@ Book {
POST http://localhost:4000/sineql HTTP/1.1 POST http://localhost:4000/sineql HTTP/1.1
Content-Type: text/plain Content-Type: text/plain
Book { create Book [
title {
create title "The Philosophers Kidney Stone"
} }
{
create title "The Chamber Pot of Secrets"
}
{
create title "The Prisoner of Aunt Kazban"
}
{
create title "The Goblet of the Fire Cocktail"
}
{
create title "The Order for Kleenex"
}
{
create title "The Half-Priced Pharmacy"
}
{
create title "Yeah, I Got Nothing"
}
]
###
POST http://localhost:4000/sineql HTTP/1.1
Content-Type: text/plain
update Book [
{
match title "The Philosophers Kidney Stone"
update published "1969-04-21"
}
{
match title "The Chamber Pot of Secrets"
update published "1969-04-22"
}
{
match title "The Prisoner of Aunt Kazban"
update published "1969-04-23"
}
{
match title "The Goblet of the Fire Cocktail"
update published "1969-04-24"
}
{
match title "The Order for Kleenex"
update published "1969-04-25"
}
{
match title "The Half-Priced Pharmacy"
update published "1969-04-26"
}
{
match title "Yeah, I Got Nothing"
update published "1969-04-27"
}
]
###
POST http://localhost:4000/sineql HTTP/1.1
Content-Type: text/plain
delete Book [
{
match title "The Philosophers Kidney Stone"
}
{
match title "The Chamber Pot of Secrets"
}
{
match title "The Prisoner of Aunt Kazban"
}
{
match title "The Goblet of the Fire Cocktail"
}
{
match title "The Order for Kleenex"
}
{
match title "The Half-Priced Pharmacy"
}
{
match title "Yeah, I Got Nothing"
}
]
###