Debugging/logging of resolvers and functions

prisma

#1

Hi,

is there a way to debug functions/resolvers? So far I did not find a documentation to how to do that and this is getting more and more complicated as my application grows (not more than 200 LOC) I can´t imagine doing this with more complicated resolvers and without debugging.

If debugging is no option, is there at least some log functionality? I know how to retreive the log from Docker, so is there a option to write into this log aswell?


#2

Are you using prisma or the framework?

With graphcool-framework, you can do gc logs -f nameOfFunction.

If you’re using graphql-yoga with prisma then you can do console.log and see the logs in the terminal or wherever they are outputted


#3

I thought Prisma was the framework. But I am using Prisma and already tried console.log but the output does not show up. I was under the impression that you see the log where yarn dev was run.

But I would much rather debug the code, not only logging it. Debugging is way more important to me and would be a dealbreaker for sure for a lot of guys in my company.

Is there really no debugging possible?


#4

I guess, you mean by “debugging,” using a Debugger in an IDE/Editor, right? That is possible. In fact, the application is an “ordinary” Node.js app – there is no magic involved. You might find this guide handy, if you’re using VS Code: Node.js Debugging in VS Code

Regarding: console.log – That is also possible. :slight_smile:

Maybe, you could post some code from your mutations, so that we can take a look and see why you don’t see any output.


#5

@andre maybe I’m just old school. I only ever do console.log :sunglasses::face_with_raised_eyebrow:


#6

No, you are not :slight_smile: I also do it all the time :slight_smile: My mantra is: “If I need a full-fledged debugger, my code might be too complicated.” :stuck_out_tongue: – But joke aside, console.log is in 98% of all cases sufficient.


#7

Ok, my bad with the logging. It worked, but i never found it in the querry/response output :wink: thanks for letting me know that it has to be there ^^

I am pretty new to the whole javascript/node world and this is actually my first node application as I am used to develop backend with Java/C#. So I am not really familiar with the debugging mechanisms in this world. It took me some time until I understood, that you have to debug a React/React-Native App in the browser, not the IDE, for example :wink:

I am just lacking a lot of background information on these topics. Is there no tutorial on how to do this properly? I am using Webstorm by the way. I will read up on the link you posted, but I think this is allready a little bit to advanced for me, as I merely understand the concept of a package.json… But ill try :wink:


#8

Ok, i am kind of able to debug now. I figured, that i had to compile the typescript and start with the dist/index.js, now i can set breakpoints on starting the server. But unfortunatelly, the playground does not get started this way. I figured that I somehow had to start it before/parallel but I did not come up with a solution yet. In Webstorm you can run a npm script before a debug session or you can pass parameters to node. Running the npm script before does just start the server without debugging (wich makes sense). So I tried to use the node parameters like “node_modules/npm-run-all --parallel graphql playground” for example. But all that does is to start debugging and ending the process right afterwards. I am also not sure what node expects as parameter, so i might be doing something wrong. On localhost:4000 there is nothing running, but on the http://localhost:4466/backend/dev I get a message, that my token is invalid. So i changed the URL in the field to localhost:4000 and could query my backend. But then, the breakpoint where not hit again, so I am thinking that I am on some other process again. I am just not able to wrap my head around all this.

Did nobody ever debug a prisma application so far? Maybe I am oldschool, too, but I was expecting that in the JS world debugging in an IDE is something that you would do :confused:

Is there an option to run the playground independent from the server? That might actually help


#9

Ok, i just had my first debugging experience, and it was nice =D

So for everybody that is a noob like me, here are my steps:

  • Add this to your package.json: “build”:
    "npm run build-ts",
    "build-ts": "tsc"

  • type in your console (in the project)
    npm run-script build

  • In Webstorm click on “Edit Configurations” on the run/Debug Dropdown

  • Hit the plus and select a Node.js Application

  • Enter “dist/index.js” on the “JavaScript file” field.

  • Hit Apply, set some Debug Points and click the Debug Button, server should run now

  • Go to the url defined on the bottom of index.ts (for me it is: http://localhost:4466/backend/dev)

  • In the Field where you enter the server URL enter the http://localhost:4000 (or wherever the console says, the server is running)

  • qery stuff and the debug point should be hit.

Restarting webstorm, my machine and docker in a unpredictable way also helped at the end, as there where somehow some older instances running, that where not in debugmode. Also the codemaps do not seem to be perfect and deleting the dist folder seemes to help sometimes. But for the start, this is enough for me right now.