Gremlin console vs REST API

I'm trying to get a path and the properties of the vertices and the edges for that path by running a gremlin script via REST API in Neptune. The query is simple with some filters on the edges, but the result is different from what gremlin console gives me. For example, the following query returns the path with the type of entities (vertex or edge) but only the label and the ID properties.
g.V('efc912d3-6cec-49e2-9717-85625bab5243').inE().outV().path()
g.V('efc912d3-6cec-49e2-9717-85625bab5243').inE().outV().path()
Similarly, by adding a by(valueMap()) modulator I get all the properties of all edges and vertices in the path, but not the types ("@type": "g:Edge" and "@type": "g:Vertex") The call to Neptune is done as described here https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-rest.html I guess the question is: is there a way to get the type of entity and all properties with one single query?
Using the HTTPS REST endpoint to connect to a Neptune DB instance -...
Steps for connecting to Neptune using the HTTPS REST Endpoint.
Solution:
Generally speaking, the GLVs and the Gremlin Console (if sending queries as bytecode and connecting via websockets) will serialize the results back into types that are common to the runtime that you're using for your application.
Queries sent over HTTP will return the response using GraphSON (GraphSONv3, be default with Neptune) which includes all of the extra type information....
Jump to solution
8 Replies
Solution
triggan
triggan8mo ago
Generally speaking, the GLVs and the Gremlin Console (if sending queries as bytecode and connecting via websockets) will serialize the results back into types that are common to the runtime that you're using for your application.
Queries sent over HTTP will return the response using GraphSON (GraphSONv3, be default with Neptune) which includes all of the extra type information.
Dragos Ciupureanu
I see, thanks for the clarification. Regarding Neptune and GraphSON though, is there a standard way of getting the same response back in graphson format? I see in the docs that TinkerGraph has a different serializer than the rest. For more context here, I'm trying to build a simple UI that shows a very basic subraph to our users. I am using gdotv myself, but that's local and not a good solution for users - and I'm looking for something generic that given any arbitrary query I can construct and vizualize a graph. Is this a matter of me parsing the query before sending it to Neptune and change it to return a path and then ask for the same traversal but with a valueMap in the by modulator?
spmallette
spmallette8mo ago
Note that properties will (can) be returned on elements after 3.7.0: https://tinkerpop.apache.org/docs/current/upgrade/#_properties_on_elements Neptune does not yet support that version but should relatively soon.
triggan
triggan8mo ago
@Dragos Ciupureanu - which client are you using to interact with Neptune?
Dragos Ciupureanu
I'm doing a simple POST request to Neptune's REST API from Javascript right now
triggan
triggan8mo ago
Another approach... we now have support for issuing queries via the AWS CLI and SDKs. Still requires network access to your cluster endpoints. Example here:
const { NeptunedataClient, ExecuteGremlinQueryCommand } = require( "@aws-sdk/client-neptunedata" );

( main = async () => {
const config = {
endpoint: "https://neptunedbcluster-abcdefghij.cluster-abcdefghij.us-west-2.neptune.amazonaws.com:8182",
region: "us-west-2",
};
const client = new NeptunedataClient(config);
const input = {
gremlinQuery: "g.V(['1','2']).as('a').mergeE([(T.label): 'likes',(from): '3',(to): Merge.inV]).option(Merge.inV, select('a')).elementMap()",
serializer: "application/vnd.gremlin-v1.0+json;types=false",
}
const command = new ExecuteGremlinQueryCommand(input);

try {
const results = await client.send(command);
console.log(JSON.stringify(results.result.data));
} catch (err) {
console.error(err);
}
})
main();
const { NeptunedataClient, ExecuteGremlinQueryCommand } = require( "@aws-sdk/client-neptunedata" );

( main = async () => {
const config = {
endpoint: "https://neptunedbcluster-abcdefghij.cluster-abcdefghij.us-west-2.neptune.amazonaws.com:8182",
region: "us-west-2",
};
const client = new NeptunedataClient(config);
const input = {
gremlinQuery: "g.V(['1','2']).as('a').mergeE([(T.label): 'likes',(from): '3',(to): Merge.inV]).option(Merge.inV, select('a')).elementMap()",
serializer: "application/vnd.gremlin-v1.0+json;types=false",
}
const command = new ExecuteGremlinQueryCommand(input);

try {
const results = await client.send(command);
console.log(JSON.stringify(results.result.data));
} catch (err) {
console.error(err);
}
})
main();
Using the serializer above, it returns data in the more concise format without types:
[
{
"id": "c4c5cb1e-ba3a-5be9-4717-536eef3b4de9",
"label": "likes",
"IN": {
"id": "1",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
},
{
"id": "1ec5cb1e-ba3a-3636-b15e-e5d1e999da7c",
"label": "likes",
"IN": {
"id": "2",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
}
]
[
{
"id": "c4c5cb1e-ba3a-5be9-4717-536eef3b4de9",
"label": "likes",
"IN": {
"id": "1",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
},
{
"id": "1ec5cb1e-ba3a-3636-b15e-e5d1e999da7c",
"label": "likes",
"IN": {
"id": "2",
"label": "vertex"
},
"OUT": {
"id": "3",
"label": "vertex"
}
}
]
Dragos Ciupureanu
This is great, thanks for the suggestion.