I'm following a tutorial on howtographql, 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.
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)
let links = [
{
id: "link-0",
url: "www.howtographql",
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];
},
}
I'm following a tutorial on howtographql., 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.
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)
let links = [
{
id: "link-0",
url: "www.howtographql.",
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];
},
}
Share
Improve this question
edited Apr 19, 2018 at 14:33
Vadim Kotov
8,2848 gold badges50 silver badges63 bronze badges
asked Apr 19, 2018 at 14:25
redOctober13redOctober13
4,0046 gold badges40 silver badges66 bronze badges
2 Answers
Reset to default 5The resolvers run on the server. The servers' code will not appear in DevTools' Sources panel. You have to use a NodeJS debugger from your IDE to debug your resolvers
You can use the Auto Attach from VS Code:
- Follow the official doc to setup: https://code.visualstudio./docs/nodejs/nodejs-debugging#_auto-attach
- If you select "onlyWithFlag", you will need to launch with
node --inspect index.js
, the fileindex.js
is where you start the server - Set a debug point in your resolver
- Open local GraphQL explorer and run some queries, you will see the debugger is attached