apollographql / apollographql/embeddable-explorer
Add or modify headers async before query, mutation or subscription is being sent
- Dominant language
- TypeScript
- Stars
- 3
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
I would like to add a Bearer token to the requests automatically.
An optional function which can modify the headers would solve this issue.
Sample:
```js
new window.EmbeddedSandbox({
target: '#sandbox',
initialEndpoint: window.location.href,
initialState: {
sharedHeaders: {
'X-SpecialHeader': 'WILL_BE_REPLACED_AUTOMATICALLY'
}
},
modifyHeaders: async (url, headers) => {
// Add Authorization header if not provided
if (!headers.Authorization) {
const accessToken = await window.getAccessToken();
headers.Authorization = 'Bearer ' + accessToken;
}
// Modify special header if shared header is not unchecked
if (headers['X-SpecialHeader'] === 'WILL_BE_REPLACED_AUTOMATICALLY') {
const special = await window.getTheValue();
headers['X-SpecialHeader'] = special;
}
return headers;
}
});
```
I already provided a PR for this. #307
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing PR #307, which the issue identifies as the existing implementation. Check how EmbeddedSandbox exposes sharedHeaders and modifyHeaders, and verify that the async header modification runs before query, mutation, and subscription requests are sent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100