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: refactor: clean up apollo_federation::compile_service #2905

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/core/blueprint/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@
Self { map, schema: blueprint.schema.to_owned() }
}
}

Check warning on line 183 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/index.rs
#[cfg(test)]
mod test {
use super::Index;
use crate::core::blueprint::Blueprint;
use crate::core::config::ConfigModule;
use crate::include_config;

Check warning on line 189 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/index.rs
use insta::assert_snapshot;
use crate::federation::compile_service;

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-x64-gnu

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-x64-musl

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-ia32-gnu

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-arm64-musl

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on darwin-x64

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-arm64-gnu

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on darwin-arm64

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on win32-x64-msvc

unresolved import `crate::federation`

Check failure on line 191 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on win32-ia32-msvc

unresolved import `crate::federation`

fn setup() -> Index {
let config = include_config!("./fixture/all-constructs.graphql").unwrap();
Expand Down Expand Up @@ -261,4 +263,18 @@
assert!(index.is_type_implements("Post", "Post"));
assert!(!index.is_type_implements("Node", "User"));
}

#[test]
fn test_compile_service_snapshot() {
let config = include_config!("./fixture/all-constructs.graphql").unwrap();
let cfg_module = ConfigModule::from(config);

let result = compile_service(&cfg_module);

if let Valid::Success(IR::Service(output)) = result {

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-x64-gnu

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-x64-gnu

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-x64-musl

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-x64-musl

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-ia32-gnu

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-ia32-gnu

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-arm64-musl

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-arm64-musl

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on darwin-x64

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on darwin-x64

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-arm64-gnu

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on linux-arm64-gnu

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on darwin-arm64

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on darwin-arm64

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on win32-x64-msvc

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on win32-x64-msvc

failed to resolve: use of undeclared type `IR`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on win32-ia32-msvc

failed to resolve: use of undeclared type `Valid`

Check failure on line 274 in src/core/blueprint/index.rs

View workflow job for this annotation

GitHub Actions / Run Tests on win32-ia32-msvc

failed to resolve: use of undeclared type `IR`
assert_snapshot!(output);
} else {
panic!("Expected Valid::Success");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,27 @@
},
)
.map_to(IR::Entity(resolver_by_type))
}

Check warning on line 80 in src/core/blueprint/operators/federation.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/operators/federation.rs

pub fn compile_service(config: &ConfigModule) -> Valid<IR, String> {
let mut sdl =
crate::core::document::print(filter_conflicting_directives(config.config().into()));

writeln!(sdl).ok();
// Add tailcall specific definitions to the sdl output
writeln!(
sdl,
"{}",
crate::core::document::print(filter_conflicting_directives(Config::graphql_schema()))
)
.ok();
writeln!(sdl).ok();
// Mark subgraph as Apollo federation v2 compatible according to [docs](https://www.apollographql.com/docs/apollo-server/using-federation/apollo-subgraph-setup/#2-opt-in-to-federation-2)
// (borrowed from async_graphql)
writeln!(sdl, "extend schema @link(").ok();
writeln!(sdl, "\turl: \"https://specs.apollo.dev/federation/v2.3\",").ok();
writeln!(sdl, "\timport: [\"@key\", \"@tag\", \"@shareable\", \"@inaccessible\", \"@override\", \"@external\", \"@provides\", \"@requires\", \"@composeDirective\", \"@interfaceObject\"]").ok();
writeln!(sdl, ")").ok();

Valid::succeed(IR::Service(sdl))
let mut service_doc = crate::core::document::print(filter_conflicting_directives(
config.config().into(),
));

let additional_schema = crate::core::document::print(filter_conflicting_directives(
Config::graphql_schema(),
));

let federation_v2_extension = r#"
extend schema @link(
url: "https://specs.apollo.dev/federation/v2.3",
import: ["@key", "@tag", "@shareable", "@inaccessible", "@override", "@external", "@provides", "@requires", "@composeDirective", "@interfaceObject"]
)

Check warning on line 95 in src/core/blueprint/operators/federation.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/operators/federation.rs
"#;

writeln!(service_doc, "{}\n{}", additional_schema, federation_v2_extension).ok();

Valid::succeed(IR::Service(service_doc))
}

fn filter_conflicting_directives(sd: ServiceDocument) -> ServiceDocument {
Expand Down
4 changes: 2 additions & 2 deletions src/core/blueprint/operators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
mod apollo_federation;
mod federation;

Check warning on line 1 in src/core/blueprint/operators/mod.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/operators/mod.rs
mod call;
mod enum_alias;
mod expr;
mod graphql;

Check warning on line 5 in src/core/blueprint/operators/mod.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/operators/mod.rs
mod grpc;
mod http;
mod js;
mod modify;

Check warning on line 9 in src/core/blueprint/operators/mod.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/operators/mod.rs
mod protected;

pub use apollo_federation::*;
pub use federation::*;
pub use call::*;
pub use enum_alias::*;
pub use expr::*;
pub use graphql::*;

Check warning on line 16 in src/core/blueprint/operators/mod.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/blueprint/operators/mod.rs
pub use grpc::*;
pub use http::*;
pub use js::*;
Expand Down
Loading