Replies: 1 comment 1 reply
-
| Unfortunately, there is no configuration option in Hasura to disable JSON pretty-printing in responses. The JSON serialization (including whitespace) happens inside the Haskell engine and is not configurable. A few things to consider: The real overhead is smaller than you think If you are already using gzip compression (which Hasura enables by default), whitespace compresses extremely well. Repeated spaces and newlines are nearly free in gzip. The wire overhead is minimal. The CPU cost of serializing/parsing the extra whitespace is also typically under 5% of total request latency, even for multi-MB payloads. Bigger wins for large responses For multi-MB responses, these approaches will help much more than removing whitespace:
Reverse proxy minification If you really want to strip whitespace, you could put a lightweight proxy (nginx with a Lua script, or a small Node.js middleware) between Hasura and your clients that minifies the JSON. But honestly, the effort is rarely worth it compared to pagination. Feature request This has come up before. It would be worth opening a GitHub issue specifically requesting a HASURA_GRAPHQL_JSON_COMPACT environment variable or similar. The change in the engine would be straightforward (switching from encodePretty to encode in the Aeson serializer), but it needs to be prioritized by the team. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
we have some GQL queries that produce fairly large results of several MB.
I noticed that most of the actual response text is whitespace formatting of the JSON. While all of that is compressed with Gzip, it will still increase total processing time as the white space has to be processed at least 4 times (json generation, compression, decompression, json parsing).
I also noticed that the initial json result from Postgresql does not contain any whitespace. So Hasura must add that before forwarding to the client.
Is there a way to disable adding this whitespace, or even disable mutating the Postgresql response at all?
Beta Was this translation helpful? Give feedback.
All reactions