javascriptgremlintinkerpoptinkerpop3gremlin-server

When specifying the mimeType for a Gremlin connecting, what is the significance of 'types=false'?


I am connecting to various implementations of Gremlin using the javascript library and websockets. I am attempting to make my code interoperable with various gremlin servers, all support roughly the same version of Gremlin.

A strange behaviour that I don't quite grasp is the use of 'types=false' being added to the mimeType for some server configurations, i.e:

driver = new gremlin.driver.Client(`ws://localhost:8182/gremlin`,
{
  traversalsource: 'g',
  rejectUnauthorized: false,
  ssl: false,
  mimeType: 'application/vnd.gremlin-v3.0+json;types=false'
}

I understand, the above mimetype to be the default for Tinkerpop.

In some systems I'm testing against, with types=false, gremlin queries result in the following error (which is not present when types=false is omitted):

ResponseError: Server error (no request information): Invalid OpProcessor requested [null] (499)
    at /dev/node_modules/gremlin/lib/driver/connection.js:260:13
    at Array.forEach (<anonymous>)
    at Connection._handleMessage (/dev/node_modules/gremlin/lib/driver/connection.js:254:43)
    at WebSocket.<anonymous> (/dev/node_modules/gremlin/lib/driver/connection.js:131:43)
    at WebSocket.emit (node:events:507:28)
    at Receiver.receiverOnMessage (/dev/node_modules/ws/lib/websocket.js:789:20)
    at Receiver.emit (node:events:507:28)
    at Receiver.dataMessage (/dev/node_modules/ws/lib/receiver.js:413:14)
    at Receiver.getData (/dev/node_modules/ws/lib/receiver.js:352:17)
    at Receiver.startLoop (/dev/node_modules/ws/lib/receiver.js:138:22) {
  statusCode: 499,
  statusMessage: 'Invalid OpProcessor requested [null]',
  statusAttributes: {}

I'd like to understand what types=false does. I understand requests are matched with various opcodes for de-serialization, and eval'ed. When I stepped into Gremlin javascript, I saw both (opcode and bindings) as being undefined but can't determine why.

In the documentation for GraphSON3, the section begins with:

Version 3.0

Version 3.0 of GraphSON was first introduced on TinkerPop 3.3.0 and is the default format when not specified as of this version. It is quite similar to GraphSON 2.0 and in most cases will appear compatible to the eye, however there are some critical differences:

GraphSON 3.0 does not have an option to be typeless. Types are always embedded.

GraphSON 2.0 relied on JSON data types for collections like Map and List. In GraphSON 3.0, there is explicit typed support for Map, List and Set as Gremlin relies on those types in quite specific ways that are not directly compatible with the JSON definitions of those collections. In the case of List and Set, it was important to distinguish between the two and for Map it was necessary to have the ability to return Map instances that did not have String keys (e.g. g.V().out().groupCount()).

Does this imply types=false is invalid in my context? (incidentally, the same error occurs if I switch the mimeType to 'application/vnd.gremlin-v3.0+json;types=false')


Solution

  • The additional of types=false will return GraphSON that does not embed the data type which means that you'll just get back GraphSON that relies on the standard JSON data types. For example, g.V().count() would return a long and if you did types=false you'd get:

    100
    

    but if you didn't you'd get:

    {
      "@type" : "g:Int64",
      "@value" : 100
    }
    

    The types tend to be important for when you do bytecode based traversals over websockets where the serialization/deserialization of requests/responses are all handled by the driver (you don't ever see raw JSON). You tend to only work with types=false when you are not using Gremlin drivers and are perhaps using another tool connecting over raw HTTP. It sounds like you're working with the drivers, so I'd not include types=false, moreover, when possible I'd prefer GraphBinary with: application/vnd.graphbinary-v1.0

    You can find the full GraphSON documentation here.