apollographql / router

A configurable, high-performance routing runtime for Apollo Federation 🚀
https://www.apollographql.com/docs/router/
Other
813 stars 271 forks source link

Build a subgraph routing url on Router supergraph reload #3589

Closed smyrick closed 1 year ago

smyrick commented 1 year ago

Is your feature request related to a problem? Please describe. My subgraph routing urls are published to GraphOS and delivered to the Router in the supergraph file. If I do not have static URLs or they need to be calculated with logic I need to run some code to figure them out in the Router, but this logic only requires the supergraph schema file and some environment variables and does not change after that

Describe the solution you'd like

Describe alternatives you've considered Using coprocessor or Rhai scripts I can apply some logic on every single request to change the subgraph URL, but the logic I have does not change per-request. It is static and could be calculated once from the supergraph info and environment variables

Additional context Rover today does validate routing URLs so that logic might have to change: https://github.com/apollographql/rover/issues/1689

abernix commented 1 year ago

Subgraph URL overrides can be accomplished using the override_subgraph_url YAML configuration, which allows overriding on a subgraph-name basis. Subgraphs which are not defined in this map will fall back to the URL in the supergraph. This should allow for most build-time overrides.

Additionally, the configuration file supports environment variable expansion if there's a need to leverage any environmental artifacts (e.g., K8s environment variables to capture a namespace search domain or something).

If more dynamic approaches are necessary, they should be possible via Rhai scripts at runtime within the subgraph_service (e.g., by setting the request.uri). While Rhai scripts will get run on every request, the overhead for doing a simple assignment of the URL to the uri property.

Finally, if Rover's URL validation is at all problematic (e.g., you want to leave out the URL or have it be obviously invalid in the supergraph), the linked-to issue above was resolved by another PR and published in a recent Rover release; it's now possible to skip validation on Routing URLs if the desire exists to leave them blank using the --allow-invalid-routing-url option.

We don't have plans to introduce any additional life-cycle hooks or customization in this realm right now, but welcome addition comments and use-cases on this issue, or in a new issue.

smyrick commented 1 year ago

https://github.com/apollographql/router/pull/3613