GraphQL Mesh: Issue reproduction for the operation headers not being interpolated when req.headers is a Map
- Install dependencies with
yarn install
- Start the services then the gateway with
yarn start
- Open the Apollo Sandbox at http://localhost:4000 and execute a query:
# Taken from https://rickandmortyapi.com/documentation/
query {
characters(page: 2, filter: { name: "rick" }) {
info {
count
}
results {
name
}
}
}
- Open the Apollo Sandbox at http://localhost:4000 and enter a query depending on headers:
query {
me {
id
name
email
}
}
- Click on the "Headers" tab to add the
access-token
header which is also passed in theoperationHeaders
mesh config:
Key | Value |
---|---|
access-token | 456 |
- Run the query in the Apollo Sandbox
โ ๏ธ data.me
isnull
in the response while it should return the user object because we passed the correctaccess-token
header
- Open the Node.js DevTools
- Visit
chrome://inspect
on Chrome - Click on the hyperlink "Open dedicated DevTools for Node"
- In Node.js DevTools, go to the "Connection" tab and add one for
localhost:8123
- Visit
- Add a
debugger
statement right beforereturn headers;
at the end of this file:node_modules/@graphql-mesh/string-interpolation/dist/cjs/resolver-data-factory.js
- Start the server with
node --inspect=8123 server
(change the start script of the gateway) - Run the query in the Apollo Sandbox
- You should see the
headers
being returned and used asoperationHeaders
: theaccess-token
should be empty
๐ Run it by checking out the fixed
branch
We can simply allow the operationHeaders
mesh config to be a function to use as a hook. This way, we trust Javascript to interprete the code instead of adding extra string interpolation based on regular expressions.
operationHeaders: ({ context }) => ({
'access-token': context.req.headers.get('access-token'),
}),