Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into connectors
Browse files Browse the repository at this point in the history
# Conflicts:
#	.circleci/config.yml
#	.github/workflows/publish.yml
#	.github/workflows/release.yml
#	Cargo.lock
#	apollo-federation-types/Cargo.toml
#	harmonizer/Cargo.toml
#	harmonizer/build.rs
#	harmonizer/package-lock.json
#	harmonizer/package.json
#	harmonizer/src/lib.rs
#	supergraph/Cargo.toml
  • Loading branch information
dylan-apollo committed Jul 23, 2024
2 parents 9aefa89 + 24135cb commit a947a11
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 47 deletions.
9 changes: 1 addition & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

# Our CircleCI dependencies
orbs:
rust: circleci/rust@1.6.0
rust: circleci/rust@1.6.1
secops: apollo/circleci-secops-orb@2.0.7

release: &release
Expand Down Expand Up @@ -182,13 +182,6 @@ commands:
- run:
name: Skip homebrew update
command: echo "HOMEBREW_NO_AUTO_UPDATE=1" >> $BASH_ENV
- run:
name: Install curl
# we need to override the system curl because of outdated CA certificates
# on the base macos image
command: |
brew install curl
echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> $BASH_ENV
- run:
name: Install CMake
command: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js 16
uses: actions/setup-node@v3
Expand All @@ -22,7 +22,6 @@ jobs:
- name: Create a tag to kick off release
run: |
ROUTERBRIDGE_RELEASE_VERSION=router-bridge@v`cargo metadata --format-version 1 |jq -r '.packages[] | select(.name=="router-bridge") | .version'`
cd ..
git config user.name "ApolloBot2"
git config user.email "support@apollographql.com"
git tag -a $ROUTERBRIDGE_RELEASE_VERSION -m $ROUTERBRIDGE_RELEASE_VERSION
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ jobs:
router-bridge_pr:
name: Create router-bridge release
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.inputs.version }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js 16
uses: actions/setup-node@v3
Expand All @@ -32,13 +34,13 @@ jobs:

- name: Run cargo edit and cargo build
run: |
echo "$VERSION"
echo $VERSION
NEW_VERSION=`cargo metadata --format-version 1 |jq -r '.packages[] | select(.name=="router-bridge") | .version' | python3 -c 'import sys; version=sys.stdin.readline().split("+")[0].split("."); version[2] = str(int(version[2]) + 1); print(".".join(version))'`+"v$VERSION"
echo "New version " $NEW_VERSION
cargo set-version $NEW_VERSION -p router-bridge
cargo build -p router-bridge
cd router-bridge
npm version "$VERSION"
npm version --allow-same-version "$VERSION"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/tests-mac-x86.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Mac_x86_tests

on:
push:
workflow_dispatch:

jobs:
build-supergraph:
name: Build Supergraph for macOS x86-64
# Arm64 runner for cross-compilation
runs-on: macos-14
steps:
- uses: actions/checkout@v4
name: "Checkout federation-rs repo"
- uses: actions-rs/toolchain@v1
name: "Install x86_64 toolchain for cross-compilation"
with:
toolchain: stable
target: x86_64-apple-darwin
- run: |
rustup target add x86_64-apple-darwin
# Build supergraph
- uses: actions-rs/cargo@v1
name: "Build supergraph binary"
with:
command: build
args: --target x86_64-apple-darwin
- uses: actions/upload-artifact@v4
name: "Store built binaries to use later on"
with:
path: |
target/x86_64-apple-darwin/debug/supergraph
if-no-files-found: error
retention-days: 5
comopse-supergraph:
needs: build-supergraph
name: Run supergraph compose on macOS x86-64
# strategy:
# matrix:
# composition-version: ${{ fromJSON(inputs.composition-versions) }}
# x86-64 runner
runs-on: macos-13
steps:
- uses: actions/checkout@v4
name: "Checkout rover repo"
- uses: actions/download-artifact@v4
name: "Download artifacts built in previous stages"
- uses: volta-cli/action@v4
name: "Install volta"
- name: Run supergraph compose on test graph
run: |
chmod +x ./artifact/supergraph
./artifact/supergraph compose supergraph/tests/compose_test.yaml
5 changes: 3 additions & 2 deletions apollo-federation-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Elastic-2.0"
name = "apollo-federation-types"
readme = "README.md"
repository = "https://github.com/apollographql/federation-rs/"
version = "0.12.0-dev.0"
version = "0.14.0-dev.0"

[features]
default = ["config", "build", "build_plugin"]
Expand All @@ -25,7 +25,7 @@ serde = { version = "1", features = ["derive"] }
camino = { version = "1", features = ["serde1"], optional = true }
log = { version = "0.4", optional = true }
semver = { version = "1", features = ["serde"] }
serde_with = { version = "1", optional = true }
serde_with = { version = "3", default-features = false, features = ["macros"], optional = true }
serde_yaml = { version = "0.8", optional = true }
thiserror = { version = "1", optional = true }
url = { version = "2", features = ["serde"], optional = true }
Expand All @@ -35,5 +35,6 @@ serde_json = { version = "1", optional = true }

[dev-dependencies]
assert_fs = "1"
rstest = "0.21.0"
serde_json = "1"
serde_yaml = "0.8"
2 changes: 1 addition & 1 deletion apollo-federation-types/src/config/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use url::Url;

/// Config for a single [subgraph](https://www.apollographql.com/docs/federation/subgraphs/)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct SubgraphConfig {
/// The routing URL for the subgraph.
/// This will appear in supergraph SDL and
Expand Down
94 changes: 92 additions & 2 deletions apollo-federation-types/src/config/supergraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{collections::BTreeMap, fs};

/// The configuration for a single supergraph
/// composed of multiple subgraphs.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct SupergraphConfig {
// Store config in a BTreeMap, as HashMap is non-deterministic.
subgraphs: BTreeMap<String, SubgraphConfig>,
Expand All @@ -18,6 +18,16 @@ pub struct SupergraphConfig {
}

impl SupergraphConfig {
/// Creates a new SupergraphConfig
pub fn new(
subgraphs: BTreeMap<String, SubgraphConfig>,
federation_version: Option<FederationVersion>,
) -> SupergraphConfig {
SupergraphConfig {
subgraphs,
federation_version,
}
}
/// Create a new SupergraphConfig from a YAML string in memory.
pub fn new_from_yaml(yaml: &str) -> ConfigResult<SupergraphConfig> {
let parsed_config: SupergraphConfig =
Expand Down Expand Up @@ -99,6 +109,13 @@ impl SupergraphConfig {
pub fn get_federation_version(&self) -> Option<FederationVersion> {
self.federation_version.clone()
}

/// Merges the subgraphs of another [`SupergraphConfig`] into this one
pub fn merge_subgraphs(&mut self, other: &SupergraphConfig) {
for (key, value) in other.subgraphs.iter() {
self.subgraphs.insert(key.to_string(), value.clone());
}
}
}

impl From<Vec<SubgraphDefinition>> for SupergraphConfig {
Expand Down Expand Up @@ -135,13 +152,14 @@ impl IntoIterator for SupergraphConfig {

#[cfg(test)]
mod tests {
use crate::config::FederationVersion;
use crate::config::{FederationVersion, SchemaSource, SubgraphConfig};

use super::SupergraphConfig;

use assert_fs::TempDir;
use camino::Utf8PathBuf;
use semver::Version;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::fs;

Expand Down Expand Up @@ -599,4 +617,76 @@ subgraphs:

assert!(SupergraphConfig::new_from_yaml(raw_good_yaml).is_err())
}

#[test]
fn test_merge_subgraphs() {
let raw_base_config = r#"---
federation_version: 2
subgraphs:
films:
routing_url: https://films.example.com
schema:
file: ./good-films.graphql
people:
routing_url: https://people.example.com
schema:
file: ./good-people.graphql
"#;
let raw_override_config = r#"---
federation_version: 1
subgraphs:
films:
routing_url: https://films.example.com/graphql
schema:
file: ./good-films.graphql
books:
routing_url: https://books.example.com
schema:
file: ./good-books.graphql
"#;
let mut base_config = SupergraphConfig::new_from_yaml(raw_base_config)
.expect("Failed to parse supergraph config");

let override_config = SupergraphConfig::new_from_yaml(raw_override_config)
.expect("Failed to parse supergraph config");

base_config.merge_subgraphs(&override_config);

assert_eq!(
base_config.get_federation_version(),
Some(FederationVersion::LatestFedTwo)
);

let expected_subgraphs = BTreeMap::from([
(
"films".to_string(),
SubgraphConfig {
routing_url: Some("https://films.example.com/graphql".to_string()),
schema: SchemaSource::File {
file: "./good-films.graphql".into(),
},
},
),
(
"books".to_string(),
SubgraphConfig {
routing_url: Some("https://books.example.com".to_string()),
schema: SchemaSource::File {
file: "./good-books.graphql".into(),
},
},
),
(
"people".to_string(),
SubgraphConfig {
routing_url: Some("https://people.example.com".to_string()),
schema: SchemaSource::File {
file: "./good-people.graphql".into(),
},
},
),
]);

assert_eq!(base_config.subgraphs, expected_subgraphs);
}
}
39 changes: 39 additions & 0 deletions apollo-federation-types/src/config/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ impl FederationVersion {
}
supports_arm
}

pub fn supports_arm_macos(&self) -> bool {
let mut supports_arm = false;
// No published fed1 version supports aarch64 on macOS
if self.is_fed_two() {
if self.is_latest() {
supports_arm = true;
} else if let Some(exact) = self.get_exact() {
// v2.7.3 is the earliest version published with aarch64 support for macOS
supports_arm = exact.ge(&Version::parse("2.7.3").unwrap())
}
}
supports_arm
}
}

impl PluginVersion for FederationVersion {
Expand Down Expand Up @@ -227,6 +241,7 @@ impl<'de> Deserialize<'de> for FederationVersion {

#[cfg(test)]
mod test_federation_version {
use rstest::rstest;
use serde_yaml::Value;

use crate::config::FederationVersion;
Expand Down Expand Up @@ -281,4 +296,28 @@ mod test_federation_version {
serde_yaml::from_str("v0.37.8").unwrap()
);
}

#[rstest]
#[case::fed1_latest(FederationVersion::LatestFedOne, true)]
#[case::fed1_supported(FederationVersion::ExactFedOne("0.37.2".parse().unwrap()), true)]
#[case::fed1_supported_boundary(FederationVersion::ExactFedOne("0.37.1".parse().unwrap()), true)]
#[case::fed1_unsupported(FederationVersion::ExactFedOne("0.25.0".parse().unwrap()), false)]
#[case::fed2_latest(FederationVersion::LatestFedTwo, true)]
#[case::fed2_supported(FederationVersion::ExactFedTwo("2.4.5".parse().unwrap()), true)]
#[case::fed2_supported_boundary(FederationVersion::ExactFedTwo("2.1.0".parse().unwrap()), true)]
#[case::fed2_unsupported(FederationVersion::ExactFedTwo("2.0.1".parse().unwrap()), false)]
fn test_supports_arm_linux(#[case] version: FederationVersion, #[case] expected: bool) {
assert_eq!(version.supports_arm_linux(), expected)
}

#[rstest]
#[case::fed1_latest(FederationVersion::LatestFedOne, false)]
#[case::fed1_unsupported(FederationVersion::ExactFedOne("0.37.2".parse().unwrap()), false)]
#[case::fed2_latest(FederationVersion::LatestFedTwo, true)]
#[case::fed2_supported(FederationVersion::ExactFedTwo("2.8.1".parse().unwrap()), true)]
#[case::fed2_supported_boundary(FederationVersion::ExactFedTwo("2.7.3".parse().unwrap()), true)]
#[case::fed2_unsupported(FederationVersion::ExactFedTwo("2.6.5".parse().unwrap()), false)]
fn test_supports_arm_macos(#[case] version: FederationVersion, #[case] expected: bool) {
assert_eq!(version.supports_arm_macos(), expected)
}
}
4 changes: 1 addition & 3 deletions router-bridge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "router-bridge"
version = "0.5.24+v2.8.0-alpha.1"
version = "0.5.29+v2.8.3"
authors = ["Apollo <packages@apollographql.com>"]
edition = "2018"
description = "JavaScript bridge for the Apollo Router"
Expand All @@ -25,7 +25,6 @@ anyhow = "1.0.79"
async-channel = "1.9.0"
deno_console = "0.115.0"
deno_core = "0.200.0"
deno_crypto = "0.129.0"
deno_url = "0.115.0"
deno_web = "0.146.0"
deno_webidl = "0.115.0"
Expand All @@ -48,7 +47,6 @@ criterion = { version = "0.4", features = ["async_tokio", "async_futures"] }
[build-dependencies]
deno_console = "0.115.0"
deno_core = "0.200.0"
deno_crypto = "0.129.0"
deno_url = "0.115.0"
deno_web = "0.146.0"
deno_webidl = "0.115.0"
Expand Down
1 change: 0 additions & 1 deletion router-bridge/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ fn create_snapshot(out_dir: &Path) {
deno_console::deno_console::init_ops(),
deno_url::deno_url::init_ops(),
deno_web::deno_web::init_ops::<Permissions>(Default::default(), Default::default()),
deno_crypto::deno_crypto::init_ops(None),
],
..Default::default()
};
Expand Down
Loading

0 comments on commit a947a11

Please sign in to comment.