Add docs for header propagation (#5602)

This commit is contained in:
Arda TANRIKULU 2024-09-11 10:58:15 -07:00 committed by GitHub
parent 6e87471f07
commit 6f410010ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 0 deletions

View file

@ -2,6 +2,7 @@ export default {
index: 'Overview',
performance: 'Performance/Cache',
security: 'Security',
'header-propagation': 'Header Propagation',
testing: 'Testing & Debugging',
'custom-plugins': 'Custom Plugins',
};

View file

@ -0,0 +1,43 @@
# Header Propagation
Hive Gateway can forward headers from the incoming request to the outgoing request, also you can
forward the headers from the upstream responses to the client.
## From the client to the subgraphs
You can configure headers to be propagated from the incoming request to the outgoing request. You
can do either per subgraph or globally.
```ts filename="gateway.config.ts"
import { defineConfig } from '@graphql-hive/gateway'
export const gatewayConfig = defineConfig({
propagateHeaders: {
fromClientToSubgraphs({ request, subgraphName }) {
if (subgraphName === 'subgraph1') {
return {
'x-custom-header': request.headers.get('x-custom-header')
}
}
}
}
})
```
## From the subgraphs to the client
You can configure headers to be propagated from the upstream responses to the client.
```ts filename="gateway.config.ts"
import { defineConfig } from '@graphql-hive/gateway'
export const gatewayConfig = defineConfig({
propagateHeaders: {
fromSubgraphsToClient({ response }) {
return {
'x-custom-header': response.headers.get('x-custom-header')
}
}
}
})
```