Support serialising iterable request headers
Closed this issue · 0 comments
The serializeRequest
method currently expects request.headers
to always be an object. There are several contexts where the headers can be an iterable which it could be good to support. I chatted about this with @apaleslimghost.
What problem does this feature solve?
In Apollo Server's requestDidStart
and also the Headers
object used by the fetch
API, the HTTP headers are not an object, they're an iterable. Currently this means you need to do the following if you want to serialise headers for these types of request:
// Assuming `request` is a `Request` instance as provided by the fetch API
serializeRequest({
...request,
headers: Object.fromEntries(Array.from(request.headers))
});
Ideal solution
It might be good to support iterables in the serialiser itself. We'd have to update the types and then change the code to check whether the value we're given is iterable. We should be able to test for this with Symbol.iterator
.
Alternatives
We don't do this, and keep iterable header serialisation in user code at the moment. We currently only have one use-case for this in the Customer Products API rationalisation team so maybe we revisit if we find that more people need it (or adoption of Apollo increases).