javascript - graphqljs - 如何获取文件名和错误行

标签 javascript node.js graphql graphql-js

我正在使用 graphqljs 和 express-graphql。每当我收到错误时,我都会得到一些模糊的信息,例如 "Expected type Int!, found\"1\" with an unhelped location property:

"locations": [
    {
        "line": 3,
        "column": 42
    }
],

如何获取文件名及其行?

以下错误:

"{
    "errors": [
        {
            "json": "{\"message\":\"Expected type Int!, found \\\"1\\\".\",\"locations\":[{\"line\":3,\"column\":42}]}",
            "message": "Expected type Int!, found \"1\".",
            "locations": [
                {
                    "line": 3,
                    "column": 42
                }
            ],
            "stack": [
                "GraphQLError: Expected type Int!, found \"1\".",
                "    at isValidScalar (/Applications/MAMP/htdocs/whylookforit-server/node_modules/graphql/validation/rules/ValuesOfCorrectType.js:164:27)",
                "    at Object.StringValue (/Applications/MAMP/htdocs/whylookforit-server/node_modules/graphql/validation/rules/ValuesOfCorrectType.js:128:14)",
                "    at Object.enter (/Applications/MAMP/htdocs/whylookforit-server/node_modules/graphql/language/visitor.js:333:29)",
                "    at Object.enter (/Applications/MAMP/htdocs/whylookforit-server/node_modules/graphql/language/visitor.js:384:25)",
                "    at visit (/Applications/MAMP/htdocs/whylookforit-server/node_modules/graphql/language/visitor.js:251:26)",
                "    at validate (/Applications/MAMP/htdocs/whylookforit-server/node_modules/graphql/validation/validate.js:63:22)",
                "    at /Applications/MAMP/htdocs/whylookforit-server/node_modules/express-graphql/dist/index.js:154:52",
                "    at processTicksAndRejections (internal/process/next_tick.js:81:5)"
            ]
        }
    ]
}"

最佳答案

所有的 graphql 代码都会被捆绑到一个大模式中,只有在完成之后,coge 才会运行。如果模式运行时出现错误,则代码不再引用最初定义的文件。

关于javascript - graphqljs - 如何获取文件名和错误行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54900814/

相关文章:

Javascript 对 Python 中的相同算法给出了不同的答案

javascript - 显示更多信息 (onmouseover)

javascript - 如何实现响应式设计,在缩放时保持按钮和其他东西相对于背景图像的位置?

javascript - 如何在 Apollo 中关闭 GraphQL 订阅的套接字连接

java - 如何正确使用Java中Apollo客户端的RxJava2库进行同步调用?

javascript - 在javascript中读取cookie,由asp.net c#code制作

angularjs - 为什么 npm 试图在错误的目录中查找 package.json?

javascript - MongoDB 中的 "Generic Collection"?

javascript - antoniogarrote/rdfstore-js 重用空白 Node

java - 如何使用 okHttpClient 执行 graphql 查询?