[英]How do I debug a GraphQL resolver in JavaScript?
I'm following a tutorial on howtographql.com , which creates a very basic GraphQL server with in-memory data and resolvers written in JavaScript. I keep having issues where I'd like to be able to just put a breakpoint in the resolver, but when I'm running the GraphQL playground GUI, I can't see anything in the DevTools' Sources panel, and putting a debugger
line in the code doesn't stop it either.我正在关注howtographql.com上的教程,它创建了一个非常基本的 GraphQL 服务器,其中包含内存数据和用 JavaScript 编写的解析器。我一直遇到问题,我希望能够在解析器中放置一个断点,但是当我运行 GraphQL 游乐场 GUI 时,我在 DevTools 的源面板中看不到任何东西,并且在代码中放置debugger
行也不会阻止它。
How do I debug my resolver?如何调试我的解析器?
Schema图式
type Mutation {
updateLink(id: ID!, url: String, description: String): Link
}
Resolver (I'm using immutable.js's Map; perhaps not correctly)解析器(我使用的是 immutable.js 的 Map;可能不正确)
let links = [
{
id: "link-0",
url: "www.howtographql.com",
description: "Fullstack tutorial for GraphQL",
},
]
const resolvers = {
Mutation: {
updateLink(root, args) {
const linkIndex = links.findIndex(link => link.id === args.id);
const state = links.map(link => {
debugger;
if (link.id === args.id) {
const map = Map(link);
return map
.set("url", args.url || link.url)
.set("description", args.description || link.description);
}
return link;
});
links = state;
return state[linkIndex];
},
}
The resolvers run on the server. 解析器在服务器上运行。 The servers' code will not appear in DevTools' Sources panel. 服务器的代码不会出现在DevTools的“源”面板中。 You have to use a NodeJS debugger from your IDE to debug your resolvers 您必须使用IDE中的NodeJS调试器来调试解析器
You can use the Auto Attach from VS Code:您可以使用 VS Code 的自动附加功能:
node --inspect index.js
, the file index.js
is where you start the server如果你 select “onlyWithFlag”,你需要用node --inspect index.js
启动,文件index.js
是你启动服务器的地方
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.