apollographql / apollographql/apollo-server

Guidance needed: HeaderMap doesn't allow setting multiple values for a header (needed for set-cookie)

Open
#7,372 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
14k
Forks
2k
Avg merge
2d 14h
Merged PRs (30d)
2

Description

Hi!

When creating a custom Apollo Server Plugin, in the `willSendResponse` method, we might want to copy the response headers from subgraphs back down the the user's request - particularly for `set-cookie`.

(This problem also exists in theory for [`x-forwarded-for`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For#examples) too fwiw)

`HeaderMap` is defined as a simple subclass of `Map`:
https://github.com/apollographql/apollo-server/blob/6ff88e87c52f4d6734c36fda96be07d4f8ad80cc/packages/server/src/utils/HeaderMap.ts#L1

So we can't do `response.http.headers.append('set-cookie', 'foo')` (this worked in prior versions of apollo, where I think we were using more of minifetch/node-fetch for this layer?)

It's also unclear how to serialize multiple set-cookie values into a single string - the `cookie` npm module (defacto standard, used by express) explicitly (correctly) doesn't support this https://github.com/jshttp/cookie/issues/129#issuecomment-957344975

I would suggest either:
1) provide guidance on how to concat and encode multiple set-cookie values into a single string (is this supported? I can't find where this is defined in spec)
2) Change HeaderMap: `Map` => `Map>`?

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start with packages/server/src/utils/HeaderMap.ts and the willSendResponse entry point described in the issue. Determine how Apollo Server should represent and serialize multiple set-cookie values, then confirm whether guidance or a HeaderMap API change is the intended outcome. Done means the chosen behavior is specified and supports the cited multi-value header use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.