From 1c75719a4885326638be4752a2e6043529ce8027 Mon Sep 17 00:00:00 2001 From: Andrea Child Date: Wed, 6 Nov 2024 20:49:06 -0800 Subject: [PATCH 1/2] Changed http lambda to use GET request for gremlin queries as they were not working correctly with POST. --- templates/Lambda4AppSyncHTTP/index.mjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/Lambda4AppSyncHTTP/index.mjs b/templates/Lambda4AppSyncHTTP/index.mjs index 65fe8d9..29fd38f 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') { + 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); } else { - result = await axios.post(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}`, `gremlin=${encodeURIComponent(resolver.query)}`, myConfig); + result = await axios.get(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}/gremlin`, { + ...myConfig, + params: { + gremlin: resolver.query + } + }); } if (LOGGING_ENABLED) console.log("Result: ", JSON.stringify(result.data, null, 2)); } catch (err) { From 55eb392936e6f3384b405676e8b0ecf6bb15228c Mon Sep 17 00:00:00 2001 From: Andrea Child Date: Thu, 7 Nov 2024 12:13:17 -0800 Subject: [PATCH 2/2] Change back to post and change axios call to use an object to send the request body. --- templates/Lambda4AppSyncHTTP/index.mjs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/Lambda4AppSyncHTTP/index.mjs b/templates/Lambda4AppSyncHTTP/index.mjs index 29fd38f..8b5ef39 100644 --- a/templates/Lambda4AppSyncHTTP/index.mjs +++ b/templates/Lambda4AppSyncHTTP/index.mjs @@ -62,14 +62,14 @@ export const handler = async (event) => { }; 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); + 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.get(`https://${process.env.NEPTUNE_HOST}:${process.env.NEPTUNE_PORT}/gremlin`, { - ...myConfig, - params: { - gremlin: resolver.query - } - }); + 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) {