Skip to content

Commit 6f100e0

Browse files
rakeshkkymarionschleifertirumaraiselvan
authored
improve debug information in actions errors response (close hasura#4031) (hasura#4432)
* config options for internal errors for non-admin role, close hasura#4031 More detailed action debug info is added in response 'internal' field * add docs * update CHANGELOG.md * set admin graphql errors option in ci tests, minor changes to docs * fix tests Don't use any auth for sync actions error tests. The request body changes based on auth type in session_variables (x-hasura-auth-mode) * Apply suggestions from code review Co-Authored-By: Marion Schleifer <marion@hasura.io> * use a new sum type to represent the inclusion of internal errors As suggested in review by @0x777 -> Move around few modules in to specific API folder -> Saperate types from Init.hs * fix tests Don't use any auth for sync actions error tests. The request body changes based on auth type in session_variables (x-hasura-auth-mode) * move 'HttpResponse' to 'Hasura.HTTP' module * update change log with breaking change warning * Update CHANGELOG.md Co-authored-by: Marion Schleifer <marion@hasura.io> Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
1 parent a8affc2 commit 6f100e0

38 files changed

Lines changed: 999 additions & 470 deletions

‎CHANGELOG.md‎

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,106 @@
22

33
## Next release
44

5+
### server: debugging mode for non-admin roles
6+
7+
For any errors the server sends extra information in `extensions` field under `internal` key. Till now this was only
8+
available for `admin` role requests. To enable this for other roles, start the server with `--dev-mode` flag or set `HASURA_GRAPHQL_DEV_MODE` env variable to `true`:
9+
10+
```bash
11+
$ graphql-engine --database-url <database-url> serve --dev-mode
12+
```
13+
14+
In case you want to disable `internal` field for `admin` role requests, set `--admin-internal-errors` option to `false` or or set `HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS` env variable to `false`
15+
16+
```bash
17+
$ graphql-engine --database-url <database-url> serve --admin-internal-errors false
18+
```
19+
20+
This feature come in handy during development when you may want to see detailed errors irrespective of roles.
21+
22+
**Improved internal errors for Actions**:
23+
24+
(This is a **breaking change** with previous 1.2.0-beta releases)
25+
26+
The `internal` field for action errors is improved with more debug information. It now includes `request`,
27+
`response` and `error` fields instead of just `webhook_response` field.
28+
29+
Before:
30+
```json
31+
{
32+
"errors": [
33+
{
34+
"extensions": {
35+
"internal": {
36+
"webhook_response": {
37+
"age": 25,
38+
"name": "Alice",
39+
"id": "some-id"
40+
}
41+
},
42+
"path": "$",
43+
"code": "unexpected"
44+
},
45+
"message": "unexpected fields in webhook response: age"
46+
}
47+
]
48+
}
49+
```
50+
After:
51+
```json
52+
{
53+
"errors": [
54+
{
55+
"extensions": {
56+
"internal": {
57+
"error": "unexpected response",
58+
"response": {
59+
"status": 200,
60+
"body": {
61+
"age": 25,
62+
"name": "Alice",
63+
"id": "some-id"
64+
},
65+
"headers": [
66+
{
67+
"value": "application/json",
68+
"name": "Content-Type"
69+
},
70+
{
71+
"value": "abcd",
72+
"name": "Set-Cookie"
73+
}
74+
]
75+
},
76+
"request": {
77+
"body": {
78+
"session_variables": {
79+
"x-hasura-role": "admin"
80+
},
81+
"input": {
82+
"arg": {
83+
"age": 25,
84+
"name": "Alice",
85+
"id": "some-id"
86+
}
87+
},
88+
"action": {
89+
"name": "mirror"
90+
}
91+
},
92+
"url": "http://127.0.0.1:5593/mirror-action",
93+
"headers": []
94+
}
95+
},
96+
"path": "$",
97+
"code": "unexpected"
98+
},
99+
"message": "unexpected fields in webhook response: age"
100+
}
101+
]
102+
}
103+
```
104+
5105
### cli: add support for .env file
6106

7107
ENV vars can now be read from .env file present at the project root directory. A global flag, `--envfile`, is added so you can explicitly provide the .env filename, which defaults to `.env` filename if no flag is provided.
@@ -23,7 +123,7 @@ Along with the check for filtering rows that can be updated, you can now set a p
23123

24124
(close #4142) (#4313)
25125

26-
### docs: map Postgres operators to corresponding Hasura operators
126+
### docs: map Postgres operators to corresponding Hasura operators
27127

28128
Map Postgres operators to corresponding Hasura operators at various places in docs and link to PG documentation for reference.
29129
For example, see [here](https://hasura.io/docs/1.0/graphql/manual/api-reference/schema-metadata-api/syntax-defs.html#operator).

‎docs/graphql/manual/actions/action-handlers.rst‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ The request payload is of the format:
3131
.. code-block:: json
3232
3333
{
34-
"action": "<action-name>",
34+
"action": {
35+
"name": "<action-name>"
36+
},
3537
"input": {
3638
"arg1": "<value>",
3739
"arg2": "<value>"
@@ -83,7 +85,7 @@ For example, consider the following mutation.
8385
8486
Let's say, the following mutation is executed:
8587

86-
.. code-block:: graphql
88+
.. code-block:: graphql
8789
8890
mutation {
8991
UserLogin (username: "jake", password: "secretpassword") {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.. meta::
2+
:description: Deriving Hasura actions
3+
:keywords: hasura, docs, actions, debug, debugging
4+
5+
.. _debugging_actions:
6+
7+
Debugging actions
8+
=================
9+
10+
.. contents:: Table of contents
11+
:backlinks: none
12+
:depth: 1
13+
:local:
14+
15+
While you're developing actions for your application, you may want to debug the webhook
16+
configured for the action. To do so, start the server in :ref:`debugging mode <errors-debugging>`.
17+
In the case of errors, the GraphQL response contains debugging information of webhook
18+
calls in the ``extensions.internal`` field.
19+
20+
For example, let's consider the following mutation:
21+
22+
.. code-block:: graphql
23+
24+
mutation {
25+
create_user(email: "foo@bar.com", name: "Foo"){
26+
id
27+
user {
28+
name
29+
email
30+
is_admin
31+
}
32+
}
33+
}
34+
35+
In case of errors, the response will look like the following if the debugging mode is enabled.
36+
37+
.. code-block:: json
38+
39+
{
40+
"errors": [
41+
{
42+
"extensions": {
43+
"internal": {
44+
"response": {
45+
"status": 200,
46+
"body": "some-string",
47+
"headers": [
48+
{
49+
"value": "application/json",
50+
"name": "Content-Type"
51+
}
52+
]
53+
},
54+
"request": {
55+
"body": {
56+
"session_variables": {
57+
"x-hasura-role": "admin"
58+
},
59+
"input": {
60+
"email": "foo@boo.com",
61+
"name": "Foo"
62+
},
63+
"action": {
64+
"name": "create_user"
65+
}
66+
},
67+
"url": "http://127.0.0.1:5593/invalid-response",
68+
"headers": [
69+
70+
]
71+
},
72+
"error": "expecting object or array of objects for action webhook response"
73+
},
74+
"path": "$",
75+
"code": "parse-failed"
76+
},
77+
"message": "expecting object or array of objects for action webhook response"
78+
}
79+
]
80+
}

‎docs/graphql/manual/actions/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,4 @@ Learn more
149149
Codegen <codegen>
150150
derive
151151
action-connect
152+
debugging

‎docs/graphql/manual/deployment/graphql-engine-flags/config-examples.rst‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,40 @@ the right content-type headers.
169169
a ``major.minor`` version is updated continuously across all patches. If
170170
you're using the assets on the server with a Docker image, it might not be the latest
171171
version of console.
172+
173+
.. _errors-debugging:
174+
175+
Debugging mode
176+
----------------
177+
178+
The Hasura GraphQL engine may provide additional information for each object in the ``extensions`` key of ``errors``.
179+
The ``internal`` key contains error information including the
180+
generated SQL statement and exception information from Postgres.
181+
This can be highly useful, especially in the case of debugging errors in :doc:`action <../../actions/debugging>` requests.
182+
183+
By default the ``extensions`` key is not sent in the ``errors`` response. To enable this,
184+
start the GraphQL engine server in debugging mode with the following configuration:
185+
186+
.. code-block:: bash
187+
188+
# Flag
189+
--dev-mode
190+
191+
# Or env var
192+
193+
HASURA_GRAPHQL_DEV_MODE=true
194+
195+
If you want the debugging mode enabled only for ``admin`` role requests, configure as follows instead of the above:
196+
197+
.. code-block:: bash
198+
199+
# Flag
200+
--admin-internal-errors
201+
202+
# Or env var
203+
204+
HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS=true
205+
206+
.. note::
207+
208+
It is highly recommended to enable debugging only for the ``admin`` role in production.

‎docs/graphql/manual/deployment/graphql-engine-flags/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The following are a few configuration use cases:
2828
- :ref:`cli-with-admin-secret`
2929
- :ref:`configure-cors`
3030
- :ref:`console-assets-on-server`
31+
- :ref:`errors-debugging`
3132

3233
.. toctree::
3334
:hidden:

‎docs/graphql/manual/deployment/graphql-engine-flags/reference.rst‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ For the ``serve`` sub-command these are the available flags and ENV variables:
134134

135135
* - N/A
136136
- ``HASURA_GRAPHQL_EVENTS_FETCH_INTERVAL``
137-
- Interval in milliseconds to sleep before trying to fetch events again after a fetch
137+
- Interval in milliseconds to sleep before trying to fetch events again after a fetch
138138
returned no events from postgres
139139

140140
* - ``-s, --stripes <NO_OF_STRIPES>``
@@ -144,8 +144,8 @@ For the ``serve`` sub-command these are the available flags and ENV variables:
144144

145145
* - ``-c, --connections <NO_OF_CONNS>``
146146
- ``HASURA_GRAPHQL_PG_CONNECTIONS``
147-
- Maximum number of Postgres connections that can be opened per stripe (default: 50).
148-
When the maximum is reached we will block until a new connection becomes available,
147+
- Maximum number of Postgres connections that can be opened per stripe (default: 50).
148+
When the maximum is reached we will block until a new connection becomes available,
149149
even if there is capacity in other stripes.
150150

151151
* - ``--timeout <SECONDS>``
@@ -201,6 +201,14 @@ For the ``serve`` sub-command these are the available flags and ENV variables:
201201
- Set the logging level. Default: ``info``. Options: ``debug``, ``info``,
202202
``warn``, ``error``.
203203

204+
* - ``--dev-mode``
205+
- ``HASURA_GRAPHQL_DEV_MODE``
206+
- Set dev mode for GraphQL requests; include the ``internal`` key in the errors extensions of the response (if required).
207+
208+
* - ``--admin-internal-errors``
209+
- ``HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS``
210+
- Include the ``internal`` key in the errors extensions of the response for GraphQL requests with the admin role (if required).
211+
204212
.. note::
205213

206214
When the equivalent flags for environment variables are used, the flags will take precedence.

‎server/graphql-engine.cabal‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ library
221221
, Hasura.Server.App
222222
, Hasura.Server.Auth
223223
, Hasura.Server.Init
224-
, Hasura.Server.Query
224+
, Hasura.Server.Init.Config
225+
, Hasura.Server.API.Query
225226
, Hasura.Server.Utils
226227
, Hasura.Server.Version
227228
, Hasura.Server.Logging
228-
, Hasura.Server.Context
229229
, Hasura.Server.Migrate
230230
, Hasura.Server.Compression
231-
, Hasura.Server.PGDump
231+
, Hasura.Server.API.PGDump
232232
-- Exposed for testing:
233233
, Hasura.Server.Telemetry.Counters
234234
, Data.Parser.JSONPath
@@ -255,7 +255,7 @@ library
255255
, Hasura.Server.CheckUpdates
256256
, Hasura.Server.Telemetry
257257
, Hasura.Server.SchemaUpdate
258-
, Hasura.Server.Config
258+
, Hasura.Server.API.Config
259259
, Hasura.Server.Migrate.Version
260260
, Hasura.Server.Auth.JWT.Internal
261261
, Hasura.Server.Auth.JWT.Logging

0 commit comments

Comments
 (0)