graphql 中的 Console.log 解析器数据 [英] Console.log resolver data in graphql

查看:22
本文介绍了graphql 中的 Console.log 解析器数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 graphql 应用程序中控制台.log 解析器.graphiql 部分有效(我可以启动服务器并查看 graphql 仪表板,然后使用根查询在浏览器窗格中检索结果),但我无法在浏览器控制台中 console.log 相同的结果.以下是我的代码:

I'm trying to console.log the resolver in a graphql app. The graphiql part works (I can start the server and see the graphql dashboard and then use the root query to retrieve the results in the browser pane), but I'm unable to console.log the same results in my browser console. Following is my code:

const GetBooks = {
 type: new GraphQLList(BookTypes),
 args: {},
 resolve() {
    return new Promise((resolve, reject) => {
        let sql = singleLineString`
        select * from books
        `;
        sql = mysql.format(sql);
        pool.query(sql, (err, results) => {
            if (err) {
                reject(err);
            }

            resolve(results);
            console.log(resolve(results));
        });
    });
   }
 };

不起作用"的部分是代码的 console.log(resolve(results)) 部分.有人能指出为什么这不起作用吗?

The part that is 'not working' is the console.log(resolve(results)) part of the code. Can someone point out why this isn't working?

推荐答案

您使用的 console.log 不在客户端.

The console.log you are using is not on the client side.

它在服务器端记录结果,而不是在浏览器上.检查启动 GraphQL 服务器的命令行,日志应该在那里.

It logs the result on the server side, not on the browser. Check your command line that started the GraphQL server, the logs should be there.

这篇关于graphql 中的 Console.log 解析器数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆