Proxy capabilities

When working in a federated architecture the need to propagate / orchestrate client data is common. We provide several ways to simplify the work with it.

Forward HTTP headers to subgraphs

Forwarding specific client headers to your subgraphs is a straightforward process. By default, no headers are forwarded for security reasons. To enable header forwarding, insert the following snippet into your config.yaml file and adjust it according to your needs.

# config.yaml

# See
# for the full list of configuration options.

  all: # Header rules for all subgraph requests.
      - op: "propagate"            # Forward a client header
        named: X-Test-Header       # Exact match (Use the canonicalized version)
      - op: "propagate"
        matching: (?i)^X-Custom-.* # Regex match (Case insensitive)
      - op: "propagate"
        named: "X-User-Id"
        default: "123"             # Set the value when the header was not set
      - op: "propagate"
        named: "X-Test-1"
        rename: "X-Test"           # Rewrites the header from X-Test-1 to X-Test
    specific-subgraph: # Will only affect this subgraph
        - op: "propagate"
          named: Subgraph-Secret
          default: "some-secret"

What does the snippet do?

With all we address all subgraph requests. Next, we can define several rules on the client's request. The operation propagate forwards all matching client request headers to the subgraphs.

The subgraphs section allows to propagate headers for specific subgraphs. The name must match with the subgraph name in the Studio.

Supported header rules

Currently, we support the following header rules:

  • propagate - Forwards all matching client request headers to the subgraphs. You can choose between one of the following matchers:

    • named - It exactly matches on the header name.

    • matching - Regex matches on the header name. You can use to test your regexes. Go to the website and select Golang on the left panel. Note: The Router never propagates hop-by-hop headers (such as Connection) when propagating by regex.

    • rename: Replaces the identified header based on its name or matching criteria and transfers the value to the newly specified header.

    • default: Fallback to this value when the named, matching or rename header could not be found.

Go canonicalize headers by default e.g. x-my-header to X-My-Header. Write your rule accordingly or use (?i)^X-Test-.* flags to make your regex case insensitive.

Default value

You can also define a value when the client header is not set by the client. Can only be used with the named matcher.

      - op: "propagate"
        named: "X-User-Id"
        default: "123"

Rule ordering

All rules are evaluated in the order they are defined.

Please inform us if you have more advanced use cases that cannot be accommodated with the current feature set. You can still use Custom Modules to implement any logic yourself. You can aggregate, remove, or add headers as you like.

Override Subgraph config

By default, we read the routing URL for each of your subgraphs from the router execution config. In most cases, no additional configuration is required.

However, if you do need to override a particular subgraph's routing URL (for example, to handle changing network topography), you can do so with the following config

New way

Using the new way, the entire subgraph config can be overridden.

      routing_url: http://router:3002/graphql
      subscription_url: http://router:3002/graphql/ws
      subscription_protocol: ws
      subscription_websocket_subprotocol: graphql-ws

The available options for subscription_protocol are ws, sse and sse_post.

The available options for subscription_websocket_subprotocol are graphql-ws, graphql-transport-ws and auto.

Old way (Will be deprecated soon)

Using the old way only the routing URL of the subgraph can be overridden.

    some-subgraph: http://router:3002/graphql

A more practical example is for routers inside a Kubernetes cluster so they can use the cluster-local DNS name while keeping the public DNS name config in the control plane.

Keep in mind, that this will also modify the URLs in your router config.

Last updated