我是新来的堆叠溢出,我真的认为你可以帮助我。
几天前,我开始在NEO4J和graphQL工作。在下面的代码中,我的neo4j请求可以正常工作。关于graphQL,我想我犯了一个错误,因为graphQL请求后的结果是null。
筛选结果
关于笔记,我用:
有人有主意吗?
`
//exampleToNeo4j.js
var neo4j = require("node-neo4j");
var db = new neo4j("http://user:pass@localhost:7474");
class Examples {
findAll = function(){
const cypher = "MATCH (a:Article) RETURN a";
var resultat = db.cypherQuery(cypher.function(err, result){
if(err) throw err;
var resultInt = [];
for (var i=0; i<result.data.lenght; i++){
resultInt[i]=result.data[i]._id:
}
return resultInt
}
return resultat;
}
}
Export default Examples;
//example.js
import {
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLList,
GraphQLNonNull} from 'graphql';
import Examples from '../../lib/exampleToNeo4j';
const examples = new Examples();
const exampleType = new GraphQLObjectType({
name: 'exampleType',
description: 'Example description',
fields: () => ({
id: {
description: "Example ID",
type: GraphQLInt
}
})
})
;
const getAllExample = {
description: 'Have all nodes',
type: new GraphQLList(exampleType),
resolve: (root)=>{
return examples.findAll();
}
};
export const getAllExamples = getAllExample;`
发布于 2017-04-05 22:01:18
所以我希望这个代码能帮上忙。一些纠正和注意点:
连接指向错误的默认端口,必须使用“螺栓”连接到另一个"http",这两个端口可以连接,例如: Db =新neo4j ('http: // neo4j: neo4j @ localhost: 7474');或Var驱动程序= neo4j.driver (“螺栓: // localhost: 7687")
也要小心回调,如果不需要,则需要放置一个"setTimeout“才能起作用;方法"Db.cypherQuery (cypher,getReturn)”中的另一件事不返回,因此它将getReturn作为回调;并且不要忘记JS是异步;
希望能帮上忙。我在这里用过它,结果就是我的名字。
//example.js
var GraphQL = require('graphql')
var Examples = require('./exampleToNeo4j.js')
var express = require('express')
var app = express()
const exampleType = new GraphQL.GraphQLObjectType({
name: 'exampleType',
description: 'Example description',
fields: () => ({
id: {
description: "Example ID",
type: GraphQLInt
}
})
})
const getAllExample = {
description: 'Have all nodes',
type: new GraphQL.GraphQLList(exampleType),
resolve: (root)=>{
return Examples.findAll(root)
}
};
app.get('/', function(req, res) {
getAllExample.resolve(function (data){
console.log(data)
res.send(data)
})
})
app.listen(3000)
console.log('porta 3000')
//exampleToNeo4j.js
var neo4j = require("node-neo4j");
var db = new neo4j("http://localhost:7474");
var Examples = {
findAll: function(call){
const cypher = "MATCH (a:Article) RETURN n LIMIT 2"
db.cypherQuery(cypher, getReturn)
function getReturn(err, result){
if(err) throw err;
var resultInt = [];
for (var i=0; i<result.data.length; i++){
resultInt[i]=result.data[i]._id
}
//console.log(result)
call(resultInt)
}
}
}
module.exports = Examples;https://stackoverflow.com/questions/36697234
复制相似问题