fix(string-interpolation): operation headers not interpolated when req.headers is a HeaderMap #5227
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.
Description
Considering how to set dynamic header values: https://the-guild.dev/graphql/mesh/docs/guides/headers
This PR allows the mesh config
operationHeaders
to be a function that returns the headers object. It takes theresolverData
as first argument so we can have access to thecontext.req.headers
. This fixes the issues where theheaders
object is a HeaderMap (you need to callheaders.get('key')
) which is not interpolated as expected:Fixes #5226
Type of change
Sandbox
🚀 See it in action by checking out the
fixed
branch of the issue reproduction repo. The changes of this PR has been published on npm under @pmrotule/graphql-mesh-string-interpolation@0.4.3-beta.2.How Has This Been Tested?
It has been tested in the issue reproduction repo and our real GraphQL Mesh integration (not tested on production yet). We still need to add test in this PR. Any guidance around tests would be appreciated since I haven't found any test regarding string interpolation.
Test Environment:
@graphql-mesh/string-interpolation
: 0.4.2 (latest)express
: 4.18.2 (latest)@apollo/server
: 4.5.0 (latest)Checklist:
CONTRIBUTING doc and the
style guidelines of this project
Further comments
I made the changes in the
string-interpolation
package even though it doesn't perform any string interpolation. It might be better to define it elsewhere, but I would love your feedback on that one.We also started to get warnings from the JSON Schema validation of the mesh config, but I'm not sure where to update this (is it based on the Typescript types?).