3

New to Elixir/Phoenix and GraphQL. I have created a simple API that retrieves "drawings" from a PostgreSQL database. The table consists of an "id" (uuid) and "drawing_json" (text). In the table is one row with a json string of about 77Kb. My schema and queries are defined using Absinthe. I have 1 query called "all_drawings" which resolves and reaches out to the Repo and pulls in all drawings. When using postman to call this API, the following query works fine:

{
   allDrawings
   {
       id
   }
}

However, when I try to return the json field as well the postman request times out and I get a "socket hang up" error.

enter image description here

Looking at the Debug Console in Visual Studio Code, I can see the query gets the data from the db just fine and almost immediately. Something seems to be happening though in returning it to the client that I can't detect. No errors are thrown. Any ideas? Not sure what information will help but happy to provide more.

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
mac
  • 485
  • 1
  • 6
  • 29
  • How many rows are in your database? Are you enforcing a limit on the query, or does it return all available rows? – Everett Jun 28 '21 at 15:36
  • @Everett Just for testing purposes I only have one row in the table it is pulling from. It would pull all available rows, but there is only one. Like I said I can see in the Debug Console that it prints the result almost immediately when I hit send, with the expected results from the db. Something is happening though when trying to send that response downstream that I can't seem to get a descriptive error message for. I know in a .NET api you have set the maxrequestlength to handle larger responses. Maybe this is along those same lines? If so hwo do I handle this in Elixir/Phoenix/GraphQL? – mac Jun 28 '21 at 15:46
  • I'd have to dig around for the setting, but there must be something similar in Phoenix. There is also the possibility to stream the output, which could be better. Are you able to share the exact JSON body in use so we may try to reproduce the problem? – Everett Jun 28 '21 at 16:10
  • https://stackoverflow.com/q/56416447/6124657 - return as string to avoid type checking – xadm Jun 28 '21 at 16:36
  • I tried to reproduce this locally: I made a simple Phoenix app with some very large rows in the database and the API response still came back ok (the response size was over 26mb). Perhaps you could share your database schema and migration? And see if anything pops up if you set your log level to debug. – Everett Jun 28 '21 at 19:50

1 Answers1

0

A colleague helped me find the fix. Not sure why this is (maybe someone can elaborate), but the issue was with trying to run it in Visual Studio Code. Previously, I set up the run task in launch.json and would click the run button to start debugging my application. This would cause the aforementioned crash every time. When I went to the terminal and ran the "mix phx.server" command, everything worked fine. Not sure if the hang up is with Visual Studio Code or the ElixirLS extension when using the IDE to debug. But starting the application through the command line allowed me to use postman to hit the api and retrieve the data just fine. I'm very new to the Elixir/Phoenix world so I'm unable to draw a more intelligent conclusion as to why this happens.

mac
  • 485
  • 1
  • 6
  • 29