如何在GraphQl和Neo4js中处理响应

时间:2018-09-27 11:20:24

标签: react-native neo4j graphql response express-graphql

如果数据库中已经存在该电子邮件,我将无法获得回复。 我尝试了下面的示例代码。但是我得到的回应是空的(见图) in status there should Email exist message I am sending from query 这是我的api

{"query": "mutation authenticateUser($Phone: String!,$Email: String!, $type: String!, $otp: Int!) { authenticateUser(Phone : $Phone,Email: $Email,type : $type, otp : $otp) { status } }", "variables" : this.authenticateUserObj}

和后端代码:

router.post('/graphql', express_graphql(request => {
return {
    schema: schema,
    rootValue: root,
    graphiql: true
}    

}));

var root = {
authenticateUser : authenticateUser
};

var schema = buildSchema(`
type Mutation {
   authenticateUser(Phone:  String, Email: String,type: String,otp: Int,status: String): Authenticate
}
type Authenticate {
    Phone : String
    Email : String
    Type : String
    otp : Int
    status: String
}

`);

var authenticateUser = function({Phone, Email, type, otp}) {
db.cypher({
    query: "MATCH (n:userNodes) where n.Email='"+Email+"' RETURN count(*) as total",
}, function (err, results) {
    if(results[0]['total'] > 0)
    {
        return {status: "Email already exist"};
    }
});

}

1 个答案:

答案 0 :(得分:0)

您是否在结果[0]中获得了价值?是对象还是数组?