0

I am using ApolloGateway to build a federated server to federate subgraphs. I have implmeneted a data source class to set credentials on the gateway server. Below is the code:

class AuthenticatedDataSource extends RemoteGraphQLDataSource {
  willSendRequest({ request, context }) {
    const apiKey = ...
    request.http.headers.set('x-key-id', apiKey);
  }
}

The question I have is that I only want to set the API key when the gateway server tries to federate the graphql schema at launch time. For all sub-sequence requests, I'd like to forward the credentials from http headers to sub-graph. What I found so far has 2 issues:

  • I logged all request on the willSendRequest method, but the headers is always empty. It seems the data source class doesn't receive any value in the headers.

  • How can I differentiate the request if it is sent by the gateway server or from aclient?

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

0 Answers0