From 592ab86c45e9e4cbbee560ac06862fbc07794b8c Mon Sep 17 00:00:00 2001 From: andreachild Date: Thu, 7 Nov 2024 15:15:52 -0800 Subject: [PATCH] Fix http gremlin queries resulting in bad request (#37) Changed http lambda code to submit axios POST gremlin query request with body as object instead of string to solve 400 bad request errors and then changed open cypher axios POST request as well for consistency. --- templates/Lambda4AppSyncHTTP/index.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/templates/Lambda4AppSyncHTTP/index.mjs b/templates/Lambda4AppSyncHTTP/index.mjs index 65fe8d9..8b5ef39 100644 --- a/templates/Lambda4AppSyncHTTP/index.mjs +++ b/templates/Lambda4AppSyncHTTP/index.mjs @@ -61,10 +61,15 @@ export const handler = async (event) => { timeout: 20000 }; - if (resolver.language == 'opencypher') { - result = await axios.post(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}/opencypher`, `query=${encodeURIComponent(resolver.query)}¶meters=${encodeURIComponent(JSON.stringify(resolver.parameters))}`, myConfig); + if (resolver.language === 'opencypher') { + result = await axios.post(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}/opencypher`, { + query: resolver.query, + parameters: JSON.stringify(resolver.parameters) + }, myConfig); } else { - result = await axios.post(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}`, `gremlin=${encodeURIComponent(resolver.query)}`, myConfig); + result = await axios.post(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}/gremlin`, { + gremlin: resolver.query + }, myConfig); } if (LOGGING_ENABLED) console.log("Result: ", JSON.stringify(result.data, null, 2)); } catch (err) {