jbmusso / grex

JavaScript graph database client for TinkerPop2 Rexster
MIT License
46 stars 12 forks source link

simple example getting error: Object #<Grex> has no method 'gremlin' #26

Closed leabdalla closed 10 years ago

leabdalla commented 10 years ago

I'm trying the example in readme file:

var Grex = require('grex');

var settings = {
  'database': 'graph',
  'host': '127.0.0.1',
  'port': 8182
};

// 1. connect() takes two optional parameters: a settings Object and a Node style callback
Grex.connect(settings, function(err, client) {
  if (err) {
    console.error(err);
  }

  // 2. Initialize a Gremlin object to work with
  var gremlin = client.gremlin();

  // Start appending some code
  gremlin.g.v(1); // gremlin.script === 'g.v(1)'

  // 3. Send script for execution, and return a response with the results (if any)
  gremlin.exec(function(err, response) {
    // ...
  })
});

So, when I run app, I get this:

TypeError: Object #<Grex> has no method 'gremlin'

Am I doing something wrong?

jbmusso commented 10 years ago

Woops, this is indeed annoying.

Are you running the app in Node.js or in the browser? Also, which version of gRex are you using?

leabdalla commented 10 years ago

I'm running version 0.4.0 in NodeJS on Mavericks.

Outputting the client object, it shows:

{ options: { database: 'graph', host: '127.0.0.1', port: 8182 },
  typeMap: {},
  resultFormatter: {} }
celrenheit commented 10 years ago

The example you're trying is an example meant for the latest gRex version i.e., 0.5.x. I hugely recommend that you get the latest version. Run:

npm install grex

To get the latest version.

Otherwise, try the old example: https://github.com/gulthor/grex/blob/0.3.1/examples/createVertex.js

I just tried it with gRex 0.4.0 and there is a small bug in src/grex.js file installed inside your nodemodules directory: Change merge to .merge like so.

Grex.prototype.begin = function (typeMap) {
        typeMap = typeMap ? _.merge(typeMap, this.typeMap) : this.typeMap;

        return new Transaction(this.options, typeMap);
    };

Note: You also have to install the batch kibble extension... (https://github.com/gulthor/grex/tree/nodeify#dependancies).

The easiest thing you can do to get you started is installing the latest version of gRex.

leabdalla commented 10 years ago

Running

npm install grex

The version 0.4.0 is downloaded. Check: https://www.npmjs.org/package/grex

How can I manually install the version 0.5.0?

jbmusso commented 10 years ago

This is weird. It could be npm related, I don't know. I'll investigate.

Could you please try the following?

npm install grex@0.5.x

Or if you wish to automatically update package.json:

npm install grex@0.5.x --save

Let met know how it goes.

leabdalla commented 10 years ago

Now it worked and that errors has gone. Thanks!

npm install output:

 [~/Desktop/test]$ npm install grex@0.5.x --save                                                                                                                                                                                                             [ruby-1.9.3-p448]
 npm WARN package.json test@0.0.0 No description
 npm WARN package.json test@0.0.0 No repository field.
 npm WARN package.json test@0.0.0 No README data
 npm http GET https://registry.npmjs.org/grex
 npm http 304 https://registry.npmjs.org/grex
 npm http GET https://registry.npmjs.org/inherits
 npm http GET https://registry.npmjs.org/q
 npm http GET https://registry.npmjs.org/lodash
 npm http 304 https://registry.npmjs.org/inherits
 npm http 304 https://registry.npmjs.org/q
 npm http 304 https://registry.npmjs.org/lodash
 grex@0.5.6 node_modules/grex
 ├── inherits@2.0.1
 ├── q@0.9.7
 └── lodash@2.4.1
 [~/Desktop/test]$
jbmusso commented 10 years ago

Good to hear :). Let me know if you have trouble using gRex. You can also find me on irc Freenode #tinkerpop or #mogwai as Gulthor. Feel free to drop by, I'll happily provide support.

jbmusso commented 10 years ago

This issue is most likely related with issue https://github.com/gulthor/grex/issues/27.

jbmusso commented 10 years ago

This was indeed related to #27. My local npm config was misconfigured, and that caused issues when publishing packages. It was fixed for v0.5.6 and the problem should not occur with next versions anymore.