-
Notifications
You must be signed in to change notification settings - Fork 259
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
refactor(2904): clean up apollo federation #2906
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,14 +180,19 @@ | |
Self { map, schema: blueprint.schema.to_owned() } | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::Index; | ||
use crate::core::blueprint::Blueprint; | ||
use crate::core::config::ConfigModule; | ||
use crate::core::valid::Valid; | ||
use crate::core::ir::model::IR; | ||
use crate::core::blueprint::operators::federation::compile_service; | ||
use insta::assert_snapshot; | ||
use crate::include_config; | ||
|
||
|
||
fn setup() -> Index { | ||
let config = include_config!("./fixture/all-constructs.graphql").unwrap(); | ||
let cfg_module = ConfigModule::from(config); | ||
|
@@ -261,4 +266,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 Ok(IR::Service(output)) = result { | ||
assert_snapshot!(output); | ||
} else { | ||
panic!("Expected Valid::Success"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop if condition use unwrap. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,27 +79,40 @@ | |
.map_to(IR::Entity(resolver_by_type)) | ||
} | ||
|
||
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)) | ||
pub fn compile_service(config: &ConfigModule) -> Result<Valid<IR>, String> { | ||
let mut service_doc = ServiceDocument::from(config.config().into()); | ||
|
||
let federation_directive = DirectiveDefinition { | ||
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 85 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
name: "link".to_string(), | ||
arguments: vec![ | ||
Argument { | ||
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 88 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
name: "url".to_string(), | ||
value: Value::String("https://specs.apollo.dev/federation/v2.3".to_string()), | ||
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 90 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
}, | ||
Argument { | ||
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 92 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
name: "import".to_string(), | ||
value: Value::List(vec![ | ||
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 94 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
Value::String("@key".to_string()), | ||
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 95 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
Value::String("@tag".to_string()), | ||
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 96 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
Value::String("@shareable".to_string()), | ||
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 97 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
Value::String("@inaccessible".to_string()), | ||
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 98 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
Value::String("@override".to_string()), | ||
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Test AWS Lambda Build
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Check Examples
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (Cloudflare)
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests (WASM)
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Formatter and Lint Check
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-gnu
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-x64-musl
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-gnu
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-arm64-musl
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on linux-ia32-gnu
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-x64
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on darwin-arm64
Check failure on line 99 in src/core/blueprint/operators/federation.rs GitHub Actions / Run Tests on win32-ia32-msvc
|
||
Value::String("@external".to_string()), | ||
Value::String("@provides".to_string()), | ||
Value::String("@requires".to_string()), | ||
Value::String("@composeDirective".to_string()), | ||
Value::String("@interfaceObject".to_string()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to take a vec of strings and map over them to create a value::string |
||
]), | ||
}, | ||
], | ||
}; | ||
|
||
service_doc.add_directive(federation_directive); | ||
|
||
let mut complete_sdl = String::new(); | ||
writeln!(complete_sdl, "{}", crate::core::document::print(service_doc))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't think we need writeln. Just call print directly. |
||
|
||
Ok(Valid::succeed(IR::Service(complete_sdl))) | ||
} | ||
|
||
fn filter_conflicting_directives(sd: ServiceDocument) -> ServiceDocument { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,19 +1,19 @@ | ||||||
mod apollo_federation; | ||||||
pub mod federation; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
mod call; | ||||||
mod enum_alias; | ||||||
mod expr; | ||||||
mod graphql; | ||||||
mod grpc; | ||||||
mod http; | ||||||
mod js; | ||||||
mod modify; | ||||||
mod protected; | ||||||
|
||||||
pub use apollo_federation::*; | ||||||
pub use federation::*; | ||||||
pub use call::*; | ||||||
pub use enum_alias::*; | ||||||
pub use expr::*; | ||||||
pub use graphql::*; | ||||||
pub use grpc::*; | ||||||
pub use http::*; | ||||||
pub use js::*; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snapshot file is missing in the project.