Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
gremlin-client
Advanced tools
A proof of concept WebSocket JavaScript client for TinkerPop3 Gremlin Server.
Tested with Node.js v0.10.29 and v0.11.13. Tested with Chrome 35, Firefox 28, Safari 7.
Gremlin Client is an AMD/CommonJS module that works in both Node.js and WebSocket enabled browsers.
npm install gremlin-client --save
In the browser, you can require the module with browserify or directly insert a <script>
tag, which will expose a global gremlin
variable:
<script type="text/javascript" src="gremlin.js"></script>
// Will open a WebSocket to ws://localhost:8182 by default
var client = gremlin.createClient();
same as:
var client = gremlin.createClient(8182, 'localhost');
If you want to use Gremlin-Server sessions, you can set the session
argument as true in the options
object:
var client = gremlin.createClient(8182, 'localhost', { session: true });
The client supports two modes: streaming results, or traditional callback mode.
Return a Node.js stream which emits a data
event with the raw data returned by Gremlin Server every time it receives a message. The stream simultaneously also emits a higher level result
event.
The stream emits an end
event when receiving the last, type: 0
message.
var query = client.stream('g.V()');
query.on('result', function(result) {
console.log(result);
});
// Alternatively:
// query.on('data', function(message) {
// console.log(message.result);
// });
query.on('end', function(msg) {
console.log("All results fetched", msg);
});
Will execute the provided callback when all results are actually returned from the server. Until it receives the final type: 0
message, the client will internally concatenate all partial results returned over different messages.
Providing your configured nashorn
script engine in your gremlin-server.yaml
file, you can send and execute Gremlin-JavaScript formatted queries:
scriptEngines: {
gremlin-groovy: {
imports: [java.lang.Math, org.apache.commons.math3.util.FastMath],
staticImports: [java.lang.Math.PI],
scripts: [scripts/generate-classic.groovy]},
nashorn: {
imports: [java.lang.Math, org.apache.commons.math3.util.FastMath],
staticImports: [java.lang.Math.PI]}}
Then, in your Node.js/Browser environment:
var client = gremlin.createClient({ language: 'nashorn' });
// Wrap a script definition in a JavaScript function
var script = function() {
// Retrieve all vertices ordered by name
g.V().order(function(a, b) {
return a.get().value('name').localeCompare(b.get().value('name')); // JavaScript replacement for <=> spaceship operator
});
};
// Send that script function body to Gremlin Server for execution in Nashorn engine
client.execute(script, function(err, response) {
// Handle response.results
});
The client gets a string representation of the function passed to client.stream()
or client.query()
by calling the .toString()
method.
The following example shows how to send a Gremlin-Javascript formatted script to Gremlin Server with bound parameters using the stream API:
var s = client.stream(function() { g.v(id); }, { id: 1 });
s.on('data', function(result) {
// handle result
});
This section assumes that you configured resultIterationBatchSize: 1
in your Gremlin Server .yaml config file and loaded the default TinkerPop graph with scripts: [scripts/generate-classic.groovy]
To run the command line example:
cd examples
node node-example
To run the browser example:
cd examples
node server
then open http://localhost:3000/examples/gremlin.html for a demonstration on how a list of 6 vertices is being populated as the vertices are being streamed down from Gremlin Server.
.execute()
with promiseFAQs
JavaScript client for TinkerPop3 Gremlin Server
The npm package gremlin-client receives a total of 6 weekly downloads. As such, gremlin-client popularity was classified as not popular.
We found that gremlin-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.