Apollo-server: Gateway should offer configuration point for introspection query

Created on 20 Jun 2019  ·  8Comments  ·  Source: apollographql/apollo-server

Gateways currently offer a configuration point for buildService -> willSendRequest, which allows setting headers on normal federated requests to their services, but they offer no configuration hook for sending the initial query GetServiceDefinition { _service { sdl } } request.

https://spectrum.chat/apollo/apollo-federation/sending-authorization-header-on-gateway-introspection-query~e8c3c16a-07b7-464a-97f5-13f577591bb9

👩‍🚀 federation

Most helpful comment

This would be quite helpful, but I also see it as useful for us to possibly configure the actual method used to communicate with the service. One might want to use lambda.invoke as opposed to fetch, and all we would need is to provide a function that implements a similar API.

I have patched the Apollo Gateway in my own codebase to facilitate my desire for leveraging lambda.invoke (why add an API Gateway layer if I don't need it? 😄 ) with some of the services, ensuring to construct the context object to be properly accepted by the apollo-server-lambda handler.

All 8 comments

Made a quick demo implementation, we can discuss API in this thread.

I just ran into this issue today (my service requires a particular header), FWIW it would be nice to be able to manipulate headers on a per-service basis rather than just globally. Perhaps as a headers prop that can be included alongside name and url?

This would be quite helpful, but I also see it as useful for us to possibly configure the actual method used to communicate with the service. One might want to use lambda.invoke as opposed to fetch, and all we would need is to provide a function that implements a similar API.

I have patched the Apollo Gateway in my own codebase to facilitate my desire for leveraging lambda.invoke (why add an API Gateway layer if I don't need it? 😄 ) with some of the services, ensuring to construct the context object to be properly accepted by the apollo-server-lambda handler.

Hey @JacksonKearl thanks for making those changes. Is there any documentation for this yet? Also, is my understanding correct that you would be sending the same headers for all introspection queries?

In our use case we would want to send different headers to each service, or in some cases, the same headers but different values. Is there a way of doing that?

Hey @jaknor, no docs yet. And still open to changes on the interface, what would you like to be able to do? For instance, would introspectionHeaders: HeadersInit | (url: string) => HeadersInit work?

To confirm, would the headers then only be applied for the specified url? That should work for this particular use case.

Thinking a little more about it we have also looked at using IAM authentication for our AWS API gateway. this however requires that you sign the request which in turn requires access to the request uri, body, headers etc. In schema stitching we were able to achieve this using a custom fetch method on the HttpLink object. This also had the added benefit that the same HttpLink was used for both introspection and regular requests so we only had to specify our custom logic once.

Without having looked too much into the code it appears that the willSendRequest method on a RemoteGraphQLDataSource would be a good place for the logic, however, this does not appear to be used for introspection. Is there a reason for this? At the moment I can't think of a reason why I would want my introspection request to be treated differently from other requests but I am probably missing some context.

If we don't want to use the RemoteGraphQLDataSource for the introspection I think it would be good to have a method similar to willSendRequest available for introspection but it would have to be per service.

I am also thinking that the managed federation announced yesterday might solve this as we would not be introspecting to get the schema, we would be querying engine, however I am not convinced I would want to use this approach during development but rather just introspect to keep things simple. I need to look into how it all works a bit more before making my mind up on that one though.

I also have need to enhance the request beyond just modifying headers. In my case I need to add request parameters to the URL for some federated services.

I also think that RemoteGraphQLDataSource seems like a nice way to accomplish request enhancement. I assumed this was already the case and was surprised that introspection queries were special in this regard.

I just submitted a PR that uses RemoteGraphQLDataSource when issuing introspection queries.

Closed by #3120

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dbrrt picture dbrrt  ·  3Comments

stevezau picture stevezau  ·  3Comments

Magneticmagnum picture Magneticmagnum  ·  3Comments

mathroc picture mathroc  ·  3Comments

veeramarni picture veeramarni  ·  3Comments