.mergeV() with Javascript not working

Hi, I have a nodeJS 18 lambda which is closely modeled after this documentation: https://docs.aws.amazon.com/neptune/latest/userguide/lambda-functions-examples.html#lambda-functions-examples-javascript here is my async query function:
async function query(context) {
const { userId } = context;
return g
.mergeV(new Map([[t.id, userId]]))
.option(
merge.onCreate,
new Map([
[t.label, 'myLabel']
])
)
.next();
}
async function query(context) {
const { userId } = context;
return g
.mergeV(new Map([[t.id, userId]]))
.option(
merge.onCreate,
new Map([
[t.label, 'myLabel']
])
)
.next();
}
This code produces the following vertex, without using the userId or label which I provided:
gremlin> g.V().elementMap()
==>[id:84c77791-6b38-6c39-c63a-4f0a84d3058e,label:vertex]
gremlin> g.V().elementMap()
==>[id:84c77791-6b38-6c39-c63a-4f0a84d3058e,label:vertex]
How can I troubleshoot this function? I'm using Neptune 1.2.1.0 with a nodeJs 18 lambda and here is an excerpt from my package.json and yarn.lock which shows the gremlin versions which yarn resolved for my project
"dependencies": {
"date-fns": "^2.30.0",
"gremlin": "3.6.2",
"gremlin-aws-sigv4": "^3.6.1"
}
"dependencies": {
"date-fns": "^2.30.0",
"gremlin": "3.6.2",
"gremlin-aws-sigv4": "^3.6.1"
}
"gremlin-aws-sigv4@npm:^3.6.1":
version: 3.6.1
resolution: "gremlin-aws-sigv4@npm:3.6.1"
dependencies:
aws4: ^1.11.0
debug: ^4.3.4
gremlin: ^3.6.1
checksum: 51e574db25ecf7c046e257b30d2b43ef18ef09e7564558bc2b40452ac0db2ce85eee556074bd4cbe5d02f554e9c995264377498cfc78ff3b4713e0dd7bcd480d
languageName: node
linkType: hard

"gremlin@npm:3.6.2":
version: 3.6.2
resolution: "gremlin@npm:3.6.2"
dependencies:
ws: ^8.11.0
checksum: c70c08ee108e9437afc81d6a945f66f5756c5dc09dd2772026d41bced952d5564c6f61e87066f3c807fb0f8c8af290ac399962c866f2b4695c0953d4e9113428
languageName: node
linkType: hard

"gremlin@npm:^3.6.1":
version: 3.7.1
resolution: "gremlin@npm:3.7.1"
dependencies:
ws: ^8.11.0
checksum: e1a9cbf0bbcade9e66b9b9b5c3e51c15314e55fec5dba2dd8d3f309cff18b0ae4bffbfbf9e7c239054454b6060bc6aecb787e10af168f114722660d0ad049753
languageName: node
linkType: hard
"gremlin-aws-sigv4@npm:^3.6.1":
version: 3.6.1
resolution: "gremlin-aws-sigv4@npm:3.6.1"
dependencies:
aws4: ^1.11.0
debug: ^4.3.4
gremlin: ^3.6.1
checksum: 51e574db25ecf7c046e257b30d2b43ef18ef09e7564558bc2b40452ac0db2ce85eee556074bd4cbe5d02f554e9c995264377498cfc78ff3b4713e0dd7bcd480d
languageName: node
linkType: hard

"gremlin@npm:3.6.2":
version: 3.6.2
resolution: "gremlin@npm:3.6.2"
dependencies:
ws: ^8.11.0
checksum: c70c08ee108e9437afc81d6a945f66f5756c5dc09dd2772026d41bced952d5564c6f61e87066f3c807fb0f8c8af290ac399962c866f2b4695c0953d4e9113428
languageName: node
linkType: hard

"gremlin@npm:^3.6.1":
version: 3.7.1
resolution: "gremlin@npm:3.7.1"
dependencies:
ws: ^8.11.0
checksum: e1a9cbf0bbcade9e66b9b9b5c3e51c15314e55fec5dba2dd8d3f309cff18b0ae4bffbfbf9e7c239054454b6060bc6aecb787e10af168f114722660d0ad049753
languageName: node
linkType: hard
AWS Lambda function examples for Amazon Neptune - Amazon Neptune
The following example AWS Lambda functions, written in Java, JavaScript and Python, illustrate upserting a single vertex with a randomly generated ID using the fold().coalesce().unfold() idiom.
Solution:
The solution was to allow neptune to use the default mimetype; removing the mimetype header solved the issue
Jump to solution
12 Replies
danielcraig23
danielcraig23OP8mo ago
logging the response shows me this:
{
"level": "info",
"message": "Result",
"result": {
"done": false,
"value": {
"id": "1ec77792-3c3d-1ffc-5671-f38db9edd81e",
"label": "vertex"
}
}
}
{
"level": "info",
"message": "Result",
"result": {
"done": false,
"value": {
"id": "1ec77792-3c3d-1ffc-5671-f38db9edd81e",
"label": "vertex"
}
}
}
Valentyn Kahamlyk
what is the type of userId?
danielcraig23
danielcraig23OP8mo ago
userId is a string
kelvinl2816
kelvinl28168mo ago
Is it possible the vertex already existed?
danielcraig23
danielcraig23OP8mo ago
no unfortunately, I'm testing this new lambda with a empty neptune db, created for this purpose Now I've changed/simplified the query function to this:
async function query() {
return g.mergeV(new Map([[t.label,"person"],["name","marko"],["age",29]])).next();
}
async function query() {
return g.mergeV(new Map([[t.label,"person"],["name","marko"],["age",29]])).next();
}
But the result is similar,
{
"value": {
"id": "d4c7797b-ed67-474a-cdc9-5102e6ed6896",
"label": "vertex"
},
"done": false
}
{
"value": {
"id": "d4c7797b-ed67-474a-cdc9-5102e6ed6896",
"label": "vertex"
},
"done": false
}
and the vertex created is this:
gremlin> g.V().elementMap()
==>[id:d4c7797b-ed67-474a-cdc9-5102e6ed6896,label:vertex]
gremlin> g.V().elementMap()
==>[id:d4c7797b-ed67-474a-cdc9-5102e6ed6896,label:vertex]
it seems like mergeV on javascript is not eager to comply with my expectations :/ @salman_walmart This is the question I was telling you about I can't seem to get mergeV to work
danielcraig23
danielcraig23OP8mo ago
It creates a vertex without considering the map that I provide, it seems like I'm using the wrong syntax but it's the same syntax that is generated by the gremlator tool https://www.gremlator.com/
Gremlator
Gremlin Language Variant Translator for Apache Tinkerpop
danielcraig23
danielcraig23OP8mo ago
Now when I instrument the function a bit more, I'm seeing that there is something wrong with the map that I'm creating:
async function query() {
const vertexMatcher = new Map([
[label, 'person'],
['name', 'marko'],
['age', 31],
]);
logger.info('vertexMatcher', { vertexMatcher });
return g.mergeV(vertexMatcher).next();
}
async function query() {
const vertexMatcher = new Map([
[label, 'person'],
['name', 'marko'],
['age', 31],
]);
logger.info('vertexMatcher', { vertexMatcher });
return g.mergeV(vertexMatcher).next();
}
the logs show
{"level":"info","message":"Initializing connection to neptunedbcluster-xxxxxxxx.cluster-csd4wx9xfzaj.us-east-1.neptune.amazonaws.com, port ZZZZ"}
{"level":"info","message":"vertexMatcher","vertexMatcher":{}}
{"level":"info","message":"Result","result":{"done":false,"value":{"id":"9ac77b77-8872-5bc3-9388-659dbe6791d5","label":"vertex"}}}
{"level":"info","message":"Initializing connection to neptunedbcluster-xxxxxxxx.cluster-csd4wx9xfzaj.us-east-1.neptune.amazonaws.com, port ZZZZ"}
{"level":"info","message":"vertexMatcher","vertexMatcher":{}}
{"level":"info","message":"Result","result":{"done":false,"value":{"id":"9ac77b77-8872-5bc3-9388-659dbe6791d5","label":"vertex"}}}
As deployed in Lambda the code appears like this:
async function query() {
const vertexMatcher = /* @__PURE__ */ new Map([[label, "person"], ["name", "marko"], ["age", 31]]);
import_logging3.logger.info("vertexMatcher", { vertexMatcher });
return g.mergeV(vertexMatcher).next();
}
async function query() {
const vertexMatcher = /* @__PURE__ */ new Map([[label, "person"], ["name", "marko"], ["age", 31]]);
import_logging3.logger.info("vertexMatcher", { vertexMatcher });
return g.mergeV(vertexMatcher).next();
}
I'm not sure what /* @__PURE__ */ means Now I've updated my function to
async function query() {
const vertexMatcher = new Map([
['label', 'person'],
['name', 'marko'],
['age', 31],
]);
logger.info('vertexMatcher', { vertexMatcher });
console.log(vertexMatcher);
console.log(vertexMatcher.get('label'));
return g.mergeV(vertexMatcher).next();
}
async function query() {
const vertexMatcher = new Map([
['label', 'person'],
['name', 'marko'],
['age', 31],
]);
logger.info('vertexMatcher', { vertexMatcher });
console.log(vertexMatcher);
console.log(vertexMatcher.get('label'));
return g.mergeV(vertexMatcher).next();
}
and the logs show
{"level":"info","message":"Initializing connection to neptunedbcluster-XXXXX.cluster-csd4wx9xfzaj.us-east-1.neptune.amazonaws.com, port ZZZZ"}
2024-04-19T15:44:33.052Z 60819b7d-5dfc-40db-a3aa-4f1ebdc7cc9b INFO Map(3) { 'label' => 'person', 'name' => 'marko', 'age' => 31 }
{"level":"info","message":"vertexMatcher","vertexMatcher":{}}
2024-04-19T15:44:33.054Z 60819b7d-5dfc-40db-a3aa-4f1ebdc7cc9b INFO person
{"level":"info","message":"Result","result":{"done":false,"value":{"id":"9ac77b77-8872-5bc3-9388-659dbe6791d5","label":"vertex"}}}
{"level":"info","message":"Initializing connection to neptunedbcluster-XXXXX.cluster-csd4wx9xfzaj.us-east-1.neptune.amazonaws.com, port ZZZZ"}
2024-04-19T15:44:33.052Z 60819b7d-5dfc-40db-a3aa-4f1ebdc7cc9b INFO Map(3) { 'label' => 'person', 'name' => 'marko', 'age' => 31 }
{"level":"info","message":"vertexMatcher","vertexMatcher":{}}
2024-04-19T15:44:33.054Z 60819b7d-5dfc-40db-a3aa-4f1ebdc7cc9b INFO person
{"level":"info","message":"Result","result":{"done":false,"value":{"id":"9ac77b77-8872-5bc3-9388-659dbe6791d5","label":"vertex"}}}
So it seems that the map was populated after all, and my logging was just representing it as {}. so the problem remains
triggan
triggan8mo ago
I just tried this using gremlin-javascript 3.6.2: Same query: g.mergeV(new Map([[t.label,"person"],["name","marko"],["age",29]])).next() And got this result:
{
value: Vertex {
id: 'e6c77ba9-4257-027b-5c00-83c380772ae4',
label: 'person',
properties: undefined
},
done: false
}
{
value: Vertex {
id: 'e6c77ba9-4257-027b-5c00-83c380772ae4',
label: 'person',
properties: undefined
},
done: false
}
Running element map on that id returns:
{
value: Map(4) {
EnumValue { typeName: 'T', elementName: 'id' } => 'e6c77ba9-4257-027b-5c00-83c380772ae4',
EnumValue { typeName: 'T', elementName: 'label' } => 'person',
'name' => 'marko',
'age' => 29
},
done: false
}
{
value: Map(4) {
EnumValue { typeName: 'T', elementName: 'id' } => 'e6c77ba9-4257-027b-5c00-83c380772ae4',
EnumValue { typeName: 'T', elementName: 'label' } => 'person',
'name' => 'marko',
'age' => 29
},
done: false
}
danielcraig23
danielcraig23OP8mo ago
ooh nice that's what I want to see I provided some more details in an amazon case which I just created, can I send you that case #?
triggan
triggan8mo ago
yes, please
danielcraig23
danielcraig23OP8mo ago
Thank you!
Solution
danielcraig23
danielcraig237mo ago
The solution was to allow neptune to use the default mimetype; removing the mimetype header solved the issue
Want results from more Discord servers?
Add your server