1.0.1 • Published 6 years ago

gremlin-serverless v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

gremlin-serverless

A stateless Gremlin driver of Apache TinkerPop™ , optimized for serverless functions.

Installation

npm install gremlin-serverless --save

Introduction

gremlin-serverless is a simple wrapper of Websocket using rxjs observable.
Socket will close on error and success, this way serverless functions could execute a statless query.

Usage

Socket endpoint address should be provided with protocol, port and path embedded. Note the /gremlin, see Revised URL for websockets in 3.2.2

import { createClient } from "gremlin-serverless";

/**
 * Microsoft Azure exmaple
 * Gremlin Endpoint
 * https://exmaple.gremlin.cosmosdb.azure.com:443/
 */
const execute = createClient({
    address: "wss://exmaple.gremlin.cosmosdb.azure.com:443/gremlin",
    username: "user",
    password: "pwd"
});

const testmsg = {
    requestId: uuid.v1(),
    processor: "",
    op: "eval",
    args: {
        gremlin: "g.V()",
        bindings: {},
        accept: "application/json",
        language: "gremlin-groovy"
    }
};
const result$ = execute(testmsg)
const disposable = result$.subscribe(
    ... //rxjs subscription
)

Error handling

Server response with statuscode other than success will be treated as error, a 'response' property will contain the response.

{ Error: Execution failed
        at ...
      response:
       { requestId: '4085bf30',
         status:
          { code: 597,
            attributes: [Object],
            message: '\r\n\nActivityId : 6cad836f-3c\nExceptionType :GraphCompileException\nExceptionMessage :\r\n\tGremlin Query Compilation Error: Script compileerror: Missing \')\' @ line 1, column 4.\nSource : Graphs\n\tGremlinRequestId : 6cad836f-\n\tContext : graphcompute\n\tScope : graphparse-translate-outer\n\tGraphStatusCode : ScriptEvaluationError\n\tHResult : 0x80131500\r\n' },
         result: { data: null, meta: {} } } }