【问题标题】:How to handle response in GraphQl and Neo4js如何在 GraphQl 和 Neo4js 中处理响应
【发布时间】:2019-03-03 07:08:31
【问题描述】:

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

}

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 是的,以整数形式获取结果。
    • 我唯一的问题是为什么 (return {status: "Email already exists"};) 没有在 db.cypher 中发回响应?如果我在 db.cypher 之外返回响应,它就像我想要的那样工作。
    猜你喜欢
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多