apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
813 stars 272 forks source link

Router Fails to Recognize content-type Header in Federated Service Responses Without Payloads #5804

Open mostafao-spotify opened 3 months ago

mostafao-spotify commented 3 months ago

Describe the Bug

We are self-hosting the Router image on a Kubernetes cluster. Whenever a federated service returns a 4xx or 5xx status, the Router expects a payload in the response. If there is no payload, the Router does not recognize the content-type header in the response and returns the error: subgraph response does not contain 'content-type' header, even though the federated service response does include that header.

To Reproduce

Steps to reproduce the behavior:

  1. Create a federated service that defaults to returning a 500 status on any request, and include the "content-type", "application/json" header in the response.
  2. Submit a query through the Router to hit that federated service.
  3. Observe the error: HTTP fetch failed from 'some-federated-service': subgraph response does not contain 'content-type' header; expected content-type: application/json or content-type: application/graphql-response+json.

Expected Behavior

This error should not occur, as the content-type header is already present in the response.

Output

{
    "data": null,
    "errors": [
      {
        "message": "HTTP fetch failed from 'some-federated-service': 500: Internal Server Error",
        "extensions": {
          "code": "SUBREQUEST_HTTP_ERROR",
          "service": "some-federated-service",
          "reason": "500: Internal Server Error",
          "http": {
            "status": 500
          }
        }
      },
      {
        "message": "HTTP fetch failed from 'some-federated-service': subgraph response does not contain 'content-type' header; expected content-type: application/json or content-type: application/graphql-response+json",
        "extensions": {
          "code": "SUBREQUEST_HTTP_ERROR",
          "service": "some-federated-service",
          "reason": "subgraph response does not contain 'content-type' header; expected content-type: application/json or content-type: application/graphql-response+json",
          "http": {
            "status": 500
          }
        }
      }
    ]
  }

Router version:

grnikhil commented 2 months ago

I am also facing similar issue where Router v1.45.1 gives below error for a query but same query return expected result on v1.40.1. There is no change in the router config/ backend infra while testing on the above 2 versions. Is there are config change in v1.45.1 that is needed in subgraph to get the data from subgraph

errors": [ { "message": "HTTP fetch failed from 'subgraphA': 415: Unsupported Media Type", "extensions": { "code": "SUBREQUEST_HTTP_ERROR", "service": "subgraphA'", "reason": "415: Unsupported Media Type", "http": { "status": 415 } } }, { "message": "HTTP fetch failed from 'subgraphA'': subgraph didn't return JSON (expected content-type: application/json or content-type: application/graphql-response+json)", "extensions": { "code": "SUBREQUEST_HTTP_ERROR", "service": "subgraphA'", "reason": "subgraph didn't return JSON (expected content-type: application/json or content-type: application/graphql-response+json)", "http": { "status": 415 } } }

It starts breaking post >v1.40.1. The request doesn't appear to reach the subgraph aws api gateway endpoint as we are not seeing the request logs in the cloudwatch

@o0Ignition0o