0

如果电子邮件已存在于数据库中,我将无法获得回复。我尝试了下面的示例代码。但我得到的回应是空的(见图) 在状态应该有电子邮件存在我从查询发送的消息 这是我的 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"};
    }
});

}

4

1 回答 1

0

你在 results[0] 中获得价值吗?它是对象还是数组?

于 2018-09-27T17:49:19.233 回答