Skip to content

Overriding the fetch client in apollo client leads to request matching fail #197

@formatlos

Description

@formatlos

Describe the bug
Overriding the used fetch client in Apollo Client with ky (which is fetch compatible) leads to failures in the request matching algorithm. I'm using ky to have a central (single source of truth) for setting headers like Authorization on all request through a beforeRequest hook

const fetchClient = ky.create({
  hooks: {
    beforeRequest: [
      (request) => {
        request.headers.set('Authorization', `Bearer ${access_token}`);
      },
    ],
  },
});

const httpLink = new HttpLink({
    uri: '',
    fetch: fetchClient,
  });

Expected behavior
Graphql requests still get matched.

Additional context
Add any other context about the problem here.

I've inspected the difference between the fetch and the ky calls (chrome.webRequest.WebRequestBodyDetails):

ky

{
    "documentId": "50EF69BBAF89263539823056234B884C",
    "documentLifecycle": "active",
    "frameId": 0,
    "frameType": "outermost_frame",
    "initiator": "http://localhost:3000",
    "method": "POST",
    "parentFrameId": -1,
    "requestBody": {
      "error": "Unknown error."
    },
    "requestId": "143649",
    "tabId": 420505696,
    "timeStamp": 1772205719634.835,
    "type": "xmlhttprequest",
    "url": "..."
  }

fetch

{
    "documentId": "565CADCE046FB1B0AD9B3329B18A8216",
    "documentLifecycle": "active",
    "frameId": 0,
    "frameType": "outermost_frame",
    "initiator": "http://localhost:3000",
    "method": "POST",
    "parentFrameId": -1,
    "requestBody": {
      "raw": [
        {
          "bytes": {}
        }
      ]
    },
    "requestId": "138471",
    "tabId": 420505696,
    "timeStamp": 1772205538801.859,
    "type": "xmlhttprequest",
    "url": "..."
  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions