thingdom / node-neo4j

[RETIRED] Neo4j graph database driver (REST API client) for Node.js
Apache License 2.0
925 stars 135 forks source link

GraphDatabase instance does not have access to functions #200

Open ayhid opened 8 years ago

ayhid commented 8 years ago

I am testing the module within a meteor app, but I can't get further from instanciating the GraphDatabase Class.

const neo4j = require('neo4j');
const GraphDB =  new neo4j.GraphDatabase('http://neo4j:neo4j@localhost:7474');

//getting this object
{ 
  url: 'http://neo4j:neo4j@localhost:7474',
  auth: { username: 'neo4j', password: 'neo4j' },
  headers: { 'User-Agent': 'node-neo4j/2.0.0-RC2' },
  proxy: undefined,
  agent: undefined 
}

As you can see I can't call any methods on this object as it does contain none.

Am I missing something?

aseemk commented 8 years ago

I'm not sure. =) What do you mean by "getting this object"? How are you printing that? Have you tried actually calling the methods in the documentation?

As is typical for JS classes, all methods are actually defined on the class's prototype. So perhaps you're just not seeing prototype methods depending on how you're printing that object.

Try following the documentation. Let me know if anything doesn't work. Hope that helps for now.

ayhid commented 8 years ago

@aseemk I actually tried to call the query() method first but I got an exception TypeError: undefined is not a function, than I used a simple console.log() to print out my GraphDB object and see whether or not it contains some methods.

royipressburger commented 8 years ago

Maybe you are mistaken GraphDB.query () with GraphDB.cypher () because query is really no a function on the db object

ayhid commented 8 years ago

@royipressburger you are right I was calling GraphDB.query() instead of GraphDB.cypher()

Now I am having another error here is what I am calling:

GraphDB.cypher({
  query: 'MATCH (n) RETURN n',
  params: {},
  },
 callback
);

And I am getting this error:

TypeError: Object [object Object] has no method 'http' at GraphDatabase.module.exports.GraphDatabase.cypher (/node_modules/neo4j/lib-new/GraphDatabase.js:208:19)
royipressburger commented 8 years ago

@ayhid for me its abit hard to understand like that, Can you add the complete stacktrace and more code please?

ayhid commented 8 years ago

@royipressburger thank you for your patience

here is what I am actually doing

const neo4j = require('neo4j');
const GraphDB = new neo4j.GraphDatabase('http://neo4j:neo4j@localhost:7474');
function callback(err, results) {
    console.log('callback');
    if (err) throw err;
    var result = results[0];
    if (!result) {
        console.log('No user found.');
    } else {
        var user = result;
        console.log(user);
    }
};

Meteor.methods({
    'graph.get': ()=> {
        GraphDB.cypher({
                query: 'MATCH (n) RETURN n',
                params: {},
            },

            callback
        );
    }
})

and here is the error with the full stack trace

TypeError: Object [object Object] has no method 'http'
    at GraphDatabase.module.exports.GraphDatabase.cypher (/node_modules/neo4j/lib-new/GraphDatabase.js:208:19)
    at [object Object].artistGet (imports/api/server/artists/methods.js:22:17)
    at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1704:12)
    at packages/ddp-server/livedata_server.js:1617:18
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
    at Server.apply (packages/ddp-server/livedata_server.js:1616:45)
    at Server.call (packages/ddp-server/livedata_server.js:1559:17)
    at [object Object]:1:-54
    at Script.(anonymous function) [as runInThisContext] (vm.js:41:22)
    at .meteor/local/build/programs/server/shell-server.js:366:27
royipressburger commented 8 years ago

@ayhid Hi again.

So i just copied your code and ran it, everything looks Ok there.. The thing is I did not wrap it with Meteor.methods, so i guess the problem is there somewhere.. I don't know Meteor so I'm sorry I cant help :\

UPDATE: when looking at GraphDatabase.js source code I see nothing related to the http method.. So maybe try to delete the node modules and rerun npm install? i doute it will work though

ayhid commented 8 years ago

@royipressburger sorry for the delay, I have the 2.0.0-RC2 version and the GraphDatabase.js calls a http method

ekkis commented 8 years ago

I'm having the same issue with the same version. I posted here before coming across this issue: https://github.com/thingdom/node-neo4j/issues/204 - though I should say that the .cypher() method does seem to work