查询不起作用[Node.js / GraphQL]

时间:2016-10-27 13:47:42

标签: javascript node.js database graphql

我试图对我的数据库做一些请求: request graphql

使用代码:

.use('/graphql', graphqlHTTP(( req ) => {
let sess = req.session;
sess.ctx = {};

return {
    schema    : PublicSchema,
    pretty    : true,
    graphiql  : true,
    rootValue : {
      schema : 'public'
    },
    context   : sess.ctx
  };
})
)

正如你所看到的那样有效。 但是当我尝试使用NodeJS时,请求不起作用,这里是代码:

.get('/zob', function(req, res){
    let sess = req.session;
    sess.ctx = {};
    var { graphql } = require('graphql');
    var query = 'mutation{getToken(email:"###", password:"##"){token}}';
    graphql(PublicSchema, query, sess.ctx).then((response) => {
        console.log("hey");
        console.log(response);
    });
})

(我在我的代码中输入了真实的电子邮件和密码) 控制台响应: "{ data: { getToken: { token: null } }"有错误:

"TypeError: Cannot read property 'token' of undefined." 

GetToken函数返回Null。

所以,我在GraphiQL和nodeJS上做了同样的事情但是使用NodeJS查询不起作用。为什么???

你能帮帮我吗? 谢谢!

0 个答案:

没有答案