Apollo-server: Allow specifying headers in gateway serviceList (specifically Authorization header)

Created on 2 Jun 2019  ·  5Comments  ·  Source: apollographql/apollo-server

In ApolloGateway, the getServiceDefinitionsFromRemoteEndpoint function in loadServicesFromRemoteEndpoint.ts has hardcoded headers. So graphql endpoints that are protected and accept only calls with a valid Authorization header cannot be accessed by the gateway.
For example if you use AWS ApiGateway authorizers for filtering only authorised requests to your graphql endpoint, requests that don't have an Authorization header are blocked and don't even reach your endpoint.

I suggest that the ServiceEndpointDefinition object will also have a headers parameter that will allow passing such headers. Or that the code in getServiceDefinitionsFromRemoteEndpoint will also go through the buildService function to allow changing the headers.

👩‍🚀 federation

Most helpful comment

I believe this issue can be closed. There are now two different mechanisms that can be used to accomplish this.

  1. Specify introspection headers. See https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/#apollogateway
  2. Modify the headers before requests are sent to federated services by implementing the willSendRequest method of RemoteGraphQLDataSource. See here:
    https://www.apollographql.com/docs/apollo-server/federation/implementing/#customizing-incoming-requests

All 5 comments

Have the same issue as above. I agree with that implementation @brafdlog .

Facing the same issue. Is there any update to the suggestion made by @brafdlog?

@reinosutisno they've added an introspectioHeaders option to gateway

@codyspate great! Thanks for the update.

I believe this issue can be closed. There are now two different mechanisms that can be used to accomplish this.

  1. Specify introspection headers. See https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/#apollogateway
  2. Modify the headers before requests are sent to federated services by implementing the willSendRequest method of RemoteGraphQLDataSource. See here:
    https://www.apollographql.com/docs/apollo-server/federation/implementing/#customizing-incoming-requests
Was this page helpful?
0 / 5 - 0 ratings