Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compose): follow-up to #2101 #2105

Merged
merged 1 commit into from
Sep 9, 2024
Merged

fix(compose): follow-up to #2101 #2105

merged 1 commit into from
Sep 9, 2024

Conversation

glasser
Copy link
Member

@glasser glasser commented Sep 6, 2024

The improvements in #2101 did not quite work in all cases, due to some "enhancements" that the resolve_supergraph_yaml (which reads the --config file) applies which are overzealous in the case where the YAML file is an "override" to a graph ref.

First, resolve_supergraph_yaml sets a default federation_version (based on whether or not any subgraph SDLs contain the @link directive) if one is not provided. The YAML file's federation version correctly takes precedence over a remote federation_version, which means it's not appropriate for us to calculate this default if the file lacks a federation_version but we have one from another source. This PR adds a parameter to resolve_supergraph_yaml which suppresses this defaulting in the case where you have also specified --graph-ref and read a federation version from GraphOS (or if you've specified it explicitly on the command line: previously this case "worked" in that the CLI option took precedence, but it would print a warning first telling you to specify the version).

Secondly, we want to no longer treat a lack of a routing_url for a subgraph in the YAML file as an error, so that the improvement in #2101 which lets you merge local SubgraphConfigs with routing_url: None with remote SubgraphConfigs that have routing URLs works. But resolve_supergraph_yaml required every subgraph definition to have a routing URL (and in fact used the SubgraphDefinition struct as an intermediate data type, which requires the routing URL to exist). We refactor to no longer use that as an intermediate data type so that it's OK for the routing URL to still be None (like it is in the SupergraphConfig type that the function returns).

(You may wonder if it's safe that the SupergraphConfig returned from resolve_supergraph_yaml can now have None in its routing URLs when that was not possible before. But it already was the case that a graph read from GraphOS lacked routing URLs; this requirement was only enforced here for local configuration. The lack of a routing URL gets caught later and turned into an error when Compose::exec calls supergraph_config.get_subgraph_definitions().)

let mut resolved_supergraph_config: SupergraphConfig = subgraph_definitions.into();

let mut fed_two_subgraph_names = Vec::new();
for subgraph_definition in resolved_supergraph_config.get_subgraph_definitions()? {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to get_subgraph_definitions() returns error if anything in the config lacks a routing URL. I could have just changed this to iterate over the SubgraphConfigs but I would have to do an assertion that every schema source was of type Sdl. So I thought it would be simpler to just do the parsing on the SDL before we put it in the SupergraphConfig instead of afterwards. (Technically this does mean that some error cases we do some extra work before returning the error that we didn't do before.)

Copy link
Contributor

@jonathanrainer jonathanrainer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This looks fine to me, subject to the kind of UAT you've been doing anyway so all seems grand

The improvements in #2101 did not quite work in all cases, due to some
"enhancements" that the `resolve_supergraph_yaml` (which reads the
`--config` file) applies which are overzealous in the case where the
YAML file is an "override" to a graph ref.

First, `resolve_supergraph_yaml` sets a default `federation_version`
(based on whether or not any subgraph SDLs contain the `@link`
directive) if one is not provided. The YAML file's federation version
correctly takes precedence over a remote `federation_version`, which
means it's not appropriate for us to calculate this default if the file
lacks a `federation_version` but we have one from another source. This
PR adds a parameter to `resolve_supergraph_yaml` which suppresses this
defaulting in the case where you have also specified `--graph-ref` and
read a federation version from GraphOS (or if you've specified it
explicitly on the command line: previously this case "worked" in that
the CLI option took precedence, but it would print a warning first
telling you to specify the version).

Secondly, we want to no longer treat a lack of a `routing_url` for a
subgraph in the YAML file as an error, so that the improvement in #2101
which lets you merge local SubgraphConfigs with `routing_url: None` with
remote SubgraphConfigs that have routing URLs works. But
`resolve_supergraph_yaml` required every subgraph definition to have a
routing URL (and in fact used the `SubgraphDefinition` struct as an
intermediate data type, which requires the routing URL to exist). We
refactor to no longer use that as an intermediate data type so that it's
OK for the routing URL to still be None (like it is in the
`SupergraphConfig` type that the function returns).

(You may wonder if it's safe that the `SupergraphConfig` returned from
`resolve_supergraph_yaml` can now have None in its routing URLs when
that was not possible before. But it already was the case that a graph
read from GraphOS lacked routing URLs; this requirement was only
enforced here for local configuration. The lack of a routing URL gets
caught later and turned into an error when `Compose::exec` calls
`supergraph_config.get_subgraph_definitions()`.)
@glasser
Copy link
Member Author

glasser commented Sep 9, 2024

@glasser glasser merged commit cea92cb into main Sep 9, 2024
90 checks passed
@glasser glasser deleted the glasser/fix-2101 branch September 9, 2024 16:49
@jonathanrainer jonathanrainer added the fix 🩹 fixes a bug label Sep 10, 2024
@jonathanrainer jonathanrainer mentioned this pull request Sep 10, 2024
jonathanrainer added a commit that referenced this pull request Sep 10, 2024
## 🐛 Fixes

- **Avoid misleading warning when `--output` is not specified - @glasser
#2100**

In the release of v0.26.1 logic was added to disable the output flag if
the Federation version was less than 2.9, however this was being printed
even when the `--output` flag was not supplied. This has been corrected.

- **Improve `--graph-ref` option - @glasser #2101**

In the release of v0.26.0 the `--graph-ref` option was added to
`supergraph compose` as well as `rover dev`. However, the behaviour when
`--graph-ref` was used in conjunction with `--config` did not work as
documented. This is now fixed. Furthermore, both `rover dev` and
`supergraph compose`, when using only the `--graph-ref` option, respect
the graph ref's Federation version.

- **Further improve `--graph-ref` option - @glasser #2105**

Improves on the above by fixing some corner cases that prevented #2101
from working as intended

## 🛠 Maintenance

- **Update `eslint` to v9.10.0 - @jonathanrainer #2106**
- **Update `concurrently` to v9.0.0 - @jonathanrainer #2108**
- **Update `manylinux` CI Docker Image to v2024.09.09 - @jonathanrainer
#2110**
- **Update Rust to v1.81.0 - @jonathanrainer #2107**
- **Pass GitHub Tag to GitHub Actions Workflow - @glasser #2109**
- **Add `tower` for use with HTTP/GraphQL clients - @dotdat #2067**

## 📚 Documentation

- **Fix Glossary links - @Meschreiber @pnodet #2114**
aaronArinder pushed a commit that referenced this pull request Sep 10, 2024
- **Avoid misleading warning when `--output` is not specified - @glasser

In the release of v0.26.1 logic was added to disable the output flag if
the Federation version was less than 2.9, however this was being printed
even when the `--output` flag was not supplied. This has been corrected.

- **Improve `--graph-ref` option - @glasser #2101**

In the release of v0.26.0 the `--graph-ref` option was added to
`supergraph compose` as well as `rover dev`. However, the behaviour when
`--graph-ref` was used in conjunction with `--config` did not work as
documented. This is now fixed. Furthermore, both `rover dev` and
`supergraph compose`, when using only the `--graph-ref` option, respect
the graph ref's Federation version.

- **Further improve `--graph-ref` option - @glasser #2105**

Improves on the above by fixing some corner cases that prevented #2101
from working as intended

- **Update `eslint` to v9.10.0 - @jonathanrainer #2106**
- **Update `concurrently` to v9.0.0 - @jonathanrainer #2108**
- **Update `manylinux` CI Docker Image to v2024.09.09 - @jonathanrainer
- **Update Rust to v1.81.0 - @jonathanrainer #2107**
- **Pass GitHub Tag to GitHub Actions Workflow - @glasser #2109**
- **Add `tower` for use with HTTP/GraphQL clients - @dotdat #2067**

- **Fix Glossary links - @Meschreiber @pnodet #2114**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 🩹 fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants