Is settings the baseUrl via config in @source supported?

I want to set the baseUrl in the @source directive via an environment config setting because we promote our schema from lower environments to upper environments, and the URL for the API changes in each environment. However, we also require schema proposals for all changes, so the baseUrl must be configurable outside the schema. I was thinking I could do the following with the {$config.myApiBaseUrl} inside the @source directive:

extend schema
  @link(
    url: "https://specs.apollo.dev/federation/v2.10"
    import: ["@key", "@policy"]
  )
  @link(
    url: "https://specs.apollo.dev/connect/v0.1"
    import: ["@connect", "@source"]
  )
  @source(
    name: "myApi"
    http: {
      baseURL: "{$config.myApiBaseUrl}"
    }
  )

type Account @key(fields: "id") {
  id: ID!
  firstName: String
    @connect(
      source: "/myApi"
      http: { GET: "/accounts/{$this.id}" }
      selection: """
      firstName
      """
    )
}

However, I get the following error during composition:

The value "{$config.myApiBaseUrl}" for @source(baseURL:) is not a valid URL: relative URL without a base.(INVALID_URL)

Is there something I am missing?

1 Like

You can achieve this with a dedicated setting in router config!

connectors:
  sources:
    your-subgraph-name.myApi:
      override_url: "https://value-for-this-environment"

You will still need a placeholder or default value in the @source, though.

1 Like

Thank you. This is what I needed.

That being said, it is a bit weird that we commit a URL directly into the schema file when the true value really comes from the config in the router.

It would be nice to make that config variable available in the directive so that it is clear to other engineers looking at the schema where that value comes from

Agreed, and we definitely want to make base URLs be more dynamic using the same expressions as @connect! We just have to work through a few details, since there are some extra security implications when domains can be dynamically modified.