diff --git a/packages/web/docs/src/pages/docs/gateway/other-features/_meta.ts b/packages/web/docs/src/pages/docs/gateway/other-features/_meta.ts index b5bc9bb1b..6c6dccc64 100644 --- a/packages/web/docs/src/pages/docs/gateway/other-features/_meta.ts +++ b/packages/web/docs/src/pages/docs/gateway/other-features/_meta.ts @@ -2,6 +2,7 @@ export default { index: 'Overview', performance: 'Performance/Cache', security: 'Security', + 'header-propagation': 'Header Propagation', testing: 'Testing & Debugging', 'custom-plugins': 'Custom Plugins', }; diff --git a/packages/web/docs/src/pages/docs/gateway/other-features/header-propagation.mdx b/packages/web/docs/src/pages/docs/gateway/other-features/header-propagation.mdx new file mode 100644 index 000000000..78dfa2921 --- /dev/null +++ b/packages/web/docs/src/pages/docs/gateway/other-features/header-propagation.mdx @@ -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') + } + } + } +}) +```