---
title: "How do I forward headers from gateway to subgraph?"
canonical: "https://support.apollographql.com/space/ETKB/646316066/How%20do%20I%20forward%20headers%20from%20gateway%20to%20subgraph%3F"
format: markdown
---
When defining your gateway object, you can forward request data from a gateway to a subgraph server by passing in a `build service` function. The gateway calls the `build service` function once for each subgraph.

The other necessary component is a `RemoteGraphQLDataSource` object. You can use the `willSendRequest` method to take the original request (`context`) and use that data to populate the request to your subgraphs(`request`).

*For the complete API reference, please see the **[BuildService docs](https://www.apollographql.com/docs/federation/api/apollo-gateway/#the-buildservice-function)**.*

See below for an example of forwarding a single user's id header:

```typescript
// gateway server index.ts
class AuthenticatedDataSource extends RemoteGraphQLDataSource {
  willSendRequest({ request, context }) {
    request.http.headers.set("x-user-id", context.userId);
  }
}

const gateway = new ApolloGateway({
  // ...other options...
  buildService({ name, url }) {
    return new AuthenticatedDataSource({ url });
  },
});

```