router icon indicating copy to clipboard operation
router copied to clipboard

Propagate errors from subgraph without hiding

Open ghost opened this issue 1 year ago • 5 comments

Apologies if this is not a bug. Our team has invested the better part of a week trying to get this working, and we have been unsuccessful.

Describe the bug We are unable to get the Router to propagate error message from our subgraphs.

In all the following scenarios, we have router config

include_subgraph_errors:
  all: true

We have a service (Service P) which is a subgraph in our supergraph. If we send a query with a bad input directly to the Service P, it returns a helpful response error:

{
    "errors": [
        {
            "message": "UUID cannot parse the given literal of type `StringValueNode`.",
            "path": [
                "input",
                "acceptorId"
            ],
            "extensions": {
                "field": "Foo.acceptorId",
                "fieldType": "UUID"
            }
        }
    ]
}

However if we send the same query to the subgraph via the Router, we get less helpful responses, depending on what Content-Type and Status we return from Service P.

  • If Service P returns status 200 and content type application/graphql-response+json; charset=utf-8 or a content-type of application/json, then the response we get from the router is:
{
    "data": null
}

^ The secondary concern here, is that it doesn't indicate that an error happened at all.

  • If Service P returns status 400 and content type application/graphql-response+json; charset=utf-8, then the response we get from the router is:
{
    "data": null,
    "errors": [
        {
            "message": "HTTP fetch failed from 'paymentprocessing': 400: Bad Request",
            "extensions": {
                "code": "SUBREQUEST_HTTP_ERROR",
                "service": "paymentprocessing",
                "reason": "400: Bad Request",
                "http": {
                    "status": 400
                }
            }
        }
    ]
}

In this case, it at least indicates that an error happened, but doesn't have any information as to why, which is a bad experience for our customers who are beginning their integration.

To Reproduce Steps to reproduce the behavior:

  1. Any schema on a subgraph behind the router.
  2. Return one or more errors from subgraph on request.

Expected behavior I was expecting the errors returned by the subgraph to be included in the response from the router.

Desktop (please complete the following information):

  • We run Router in a docker container on a Arm64 Linux container.

Additional context

  • tested on multiple version of Router, including the latest 1.48.1
  • include_subgraph_errors is set for all subgraphs
  • We tried different combinations of status codes and content types for the subgraph response.

Workarounds? We are also interested in work arounds if anyone can provide direction for that. We already have a couple small Rhai scripts running in production, and are able to add another if required.

Thank you in advanced.

ghost avatar Jun 10 '24 19:06 ghost