Allow headers type in DefaultContext to be Record or HttpHeaders#2392
Open
vz-tl wants to merge 1 commit intothe-guild-org:masterfrom
Open
Allow headers type in DefaultContext to be Record or HttpHeaders#2392vz-tl wants to merge 1 commit intothe-guild-org:masterfrom
vz-tl wants to merge 1 commit intothe-guild-org:masterfrom
Conversation
vz-tl
commented
Nov 28, 2025
| const { headers: contextHeaders } = operation.getContext(); | ||
| return contextHeaders ? mergeHeaders(headers, contextHeaders) : headers; | ||
| return contextHeaders | ||
| ? mergeHeaders(headers, convertToHttpHeaders(contextHeaders)) |
Contributor
Author
There was a problem hiding this comment.
@PowerKiKi , here was already a check/conversion to HttpHeaders missing, which led to a stacktrace in case of using object-type headers. Adding convertToHttpHeaders(contextHeaders) will fix that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2386
Hi @PowerKiKi , in contrast to my initial assumption (see above issue), the fix for restoring the previous flexibility of using
Record<string,string>as headers type in operation context required some additional changes.The reason is, that headers can be applied in 2 different locations, which are
HttpLinkoptions and operation context.In versions before v12,
HttpLinkoptions always required typeHttpHeaders(hence this should still remain), but headers in the operation context could also be defined asRecord<string,string>(which btw. is in accordance to@apollo/clientas well as AngularHttpClientspecs).So, in order to restore the pre-v12 flexibility of using a header object, it now was required to add some more checks to ensure the headers finally to be in the expected
HttpHeadersformat. And here I noticed, that before v12, assigning Record-type headers to the operation context just worked by coincidence, as finally the object-type headers became converted toHttpHeadersbycreateHeadersWithClientAwareness()method. This worked flawlessly for the basicHttpLink, but withHttpBatchLinkit apparently could lead to errors when using objects.However, as previously it was allowed to use object-headers and as even apollo-angular already does some internal conversion from object to HttpHeaders, I think it's still important to allow both header types in operation context by taking care for proper conversion, which also will fix the error when using object-headers with HttpBatchLink.
Please have a look at the changes and let me know your thoughts.