Please fwd this to a better category if necessary. I'm running nodejs and from an ejs page, I'm trying to send an input value into a Cypher query that will result in a vis.js display of a graph. Note : All javascript actions are taking place on the ejs page, there is no server contact in this case.
I can render the Neo4j graph no problem when running the query without any attempts of adding the input value.
This Works Clicking this button...
<input type="submit" onclick="displayGraph()" value='Display Graph' class="button">
...runs this function which includes the Cypher query (no input in this query) and renders the Neo4j graph as expected.
function displayGraph() {
// Create the authorization header for the ajax request.
AUTHORIZATION = "Basic " + btoa("abc"+":"+"123");
// Post Cypher query to return node and relations and return results as graph.
restPost({
"statements": [
{
"statement": `MATCH (bry:Brewery)-[r:BREWS]->(b:Beer {name: 'Pliny the Elder'})-[r2:IS_A]->(bt:BeerType)
Optional Match (b)-[r3:BREWED_WITH]->(h:Hop)
Return bry,r,b,r2,bt,r3,h`,
"resultDataContents": ["graph"]
}
]
}).done(function (data) {
// Parse results and convert it to vis.js compatible data.
var graphData = parseGraphResultData(data);
var nodes = convertNodes(graphData.nodes);
var edges = convertEdges(graphData.edges);
var visData = {
nodes: nodes,
edges: edges
};
displayVisJsData(visData);
});
}
This Doesn't Work If I use an input field to capture the name of a beer...
<label>
Beer Name:<input name="inputbeer" id="inputbeer" type="text">
</label>
...and then click the same button...
<input type="submit" onclick="displayGraph()" value='Display Graph' class="button">
...I run the similar function, but have tried a number of variations on passing the input value into the Cypher query like this (everything is the same as the function seen above, just amending the Cypher query)...
MATCH (bry:Brewery)-[r:BREWS]->(b:Beer {name: '$inputbeer'})-[r2:IS_A]->(bt:BeerType)
Optional Match (b)-[r3:BREWED_WITH]->(h:Hop)
Return bry,r,b,r2,bt,r3,h
...this and other variations don't work. I've tried {name: {inputbeer}}... {name: {$inputbeer}}... {name: $inputbeer}... so many possibilities. I'm guessing it's a simple format issue, but I'm at a loss.
Thank you for any help!