Skip to content

Commit

Permalink
pass default DeferStreamInterface to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robrichard committed Dec 16, 2021
1 parent e42d144 commit 7b5414c
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 85 deletions.
14 changes: 7 additions & 7 deletions compiler/crates/relay-codegen/tests/client_edges/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::get_test_schema_with_extensions;
use relay_transforms::{client_edges, relay_resolvers, sort_selections};
use relay_transforms::{client_edges, relay_resolvers, sort_selections, DeferStreamInterface};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -26,14 +26,14 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
.and_then(|program| relay_resolvers(&program, true))
.unwrap(),
);
let defer_stream_interface = DeferStreamInterface::default();

let mut result = next_program
.fragments()
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste))
.chain(
next_program
.operations()
.map(|def| print_operation(&schema, def, JsModuleFormat::Haste)),
)
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste, &defer_stream_interface))
.chain(next_program.operations().map(|def| {
print_operation(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
}))
.collect::<Vec<_>>();
result.sort_unstable();
Ok(result.join("\n\n"))
Expand Down
13 changes: 6 additions & 7 deletions compiler/crates/relay-codegen/tests/client_extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::get_test_schema_with_extensions;
use relay_transforms::{client_extensions, sort_selections};
use relay_transforms::{client_extensions, sort_selections, DeferStreamInterface};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let parts: Vec<_> = fixture.content.split("%extensions%").collect();
let defer_stream_interface = DeferStreamInterface::default();
if let [base, extensions] = parts.as_slice() {
let ast = parse_executable(base, SourceLocationKey::standalone(fixture.file_name)).unwrap();
let schema = get_test_schema_with_extensions(extensions);
Expand All @@ -24,12 +25,10 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let next_program = sort_selections(&client_extensions(&program));
let mut result = next_program
.fragments()
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste))
.chain(
next_program
.operations()
.map(|def| print_operation(&schema, def, JsModuleFormat::Haste)),
)
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste, &defer_stream_interface))
.chain(next_program.operations().map(|def| {
print_operation(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
}))
.collect::<Vec<_>>();
result.sort_unstable();
Ok(result.join("\n\n"))
Expand Down
19 changes: 15 additions & 4 deletions compiler/crates/relay-codegen/tests/connections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_codegen::{build_request_params, JsModuleFormat, Printer};
use relay_test_schema::get_test_schema;
use relay_transforms::{transform_connections, validate_connections, ConnectionInterface};
use relay_transforms::{
transform_connections, validate_connections, ConnectionInterface, DeferStreamInterface,
};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -32,7 +34,10 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
validate_connections(&program, &connection_interface)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;

let next_program = transform_connections(&program, &connection_interface);
let defer_stream_interface = DeferStreamInterface::default();

let next_program =
transform_connections(&program, &connection_interface, &defer_stream_interface);

let mut printed = next_program
.operations()
Expand All @@ -46,11 +51,17 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
type_condition: def.type_,
};
let request_parameters = build_request_params(def);
printer.print_request(&schema, def, &operation_fragment, request_parameters)
printer.print_request(
&schema,
def,
&operation_fragment,
request_parameters,
&defer_stream_interface,
)
})
.collect::<Vec<_>>();
for def in next_program.fragments() {
printed.push(printer.print_fragment(&schema, def));
printed.push(printer.print_fragment(&schema, def, &defer_stream_interface));
}
printed.sort();
Ok(printed.join("\n\n"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use graphql_ir::build;
use graphql_syntax::parse_executable;
use relay_codegen::{JsModuleFormat, Printer};
use relay_test_schema::TEST_SCHEMA;
use relay_transforms::DeferStreamInterface;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let mut printer = Printer::with_dedupe(JsModuleFormat::Haste);
Expand All @@ -19,18 +20,19 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
SourceLocationKey::standalone(fixture.file_name),
)
.unwrap();
let defer_stream_interface = DeferStreamInterface::default();
build(&TEST_SCHEMA, &ast.definitions)
.map(|definitions| {
definitions
.iter()
.map(|def| match def {
graphql_ir::ExecutableDefinition::Operation(operation) => format!(
"Operation:\n{}\n",
printer.print_operation(&TEST_SCHEMA, operation)
printer.print_operation(&TEST_SCHEMA, operation, &defer_stream_interface)
),
graphql_ir::ExecutableDefinition::Fragment(fragment) => format!(
"Fragment:\n{}\n",
printer.print_fragment(&TEST_SCHEMA, fragment)
printer.print_fragment(&TEST_SCHEMA, fragment, &defer_stream_interface)
),
})
.collect::<Vec<_>>()
Expand Down
16 changes: 8 additions & 8 deletions compiler/crates/relay-codegen/tests/defer_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::get_test_schema;
use relay_transforms::{sort_selections, transform_defer_stream};
use relay_transforms::{sort_selections, transform_defer_stream, DeferStreamInterface};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -23,15 +23,15 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let schema = get_test_schema();
let ir = build(&schema, &ast.definitions).unwrap();
let program = Program::from_definitions(Arc::clone(&schema), ir);
let next_program = sort_selections(&transform_defer_stream(&program).unwrap());
let defer_stream_interface = DeferStreamInterface::default();
let next_program =
sort_selections(&transform_defer_stream(&program, &defer_stream_interface).unwrap());
let mut result = next_program
.fragments()
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste))
.chain(
next_program
.operations()
.map(|def| print_operation(&schema, def, JsModuleFormat::Haste)),
)
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste, &defer_stream_interface))
.chain(next_program.operations().map(|def| {
print_operation(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
}))
.collect::<Vec<_>>();
result.sort_unstable();
Ok(result.join("\n\n"))
Expand Down
20 changes: 14 additions & 6 deletions compiler/crates/relay-codegen/tests/json_codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ use graphql_ir::{build, ExecutableDefinition};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::TEST_SCHEMA;
use relay_transforms::DeferStreamInterface;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let ast = parse_executable(
fixture.content,
SourceLocationKey::standalone(fixture.file_name),
)
.unwrap();
let defer_stream_interface = DeferStreamInterface::default();
build(&TEST_SCHEMA, &ast.definitions)
.map(|definitions| {
definitions
.iter()
.map(|def| match def {
ExecutableDefinition::Operation(operation) => {
print_operation(&TEST_SCHEMA, operation, JsModuleFormat::Haste)
}
ExecutableDefinition::Fragment(fragment) => {
print_fragment(&TEST_SCHEMA, fragment, JsModuleFormat::Haste)
}
ExecutableDefinition::Operation(operation) => print_operation(
&TEST_SCHEMA,
operation,
JsModuleFormat::Haste,
&defer_stream_interface,
),
ExecutableDefinition::Fragment(fragment) => print_fragment(
&TEST_SCHEMA,
fragment,
JsModuleFormat::Haste,
&defer_stream_interface,
),
})
.collect::<Vec<_>>()
.join("\n\n")
Expand Down
15 changes: 8 additions & 7 deletions compiler/crates/relay-codegen/tests/react_flight_codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::react_flight;
use relay_transforms::{react_flight, DeferStreamInterface};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -27,17 +27,18 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let ir = build(&schema, &ast.definitions)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;
let program = Program::from_definitions(Arc::clone(&schema), ir);
let defer_stream_interface = DeferStreamInterface::default();

react_flight(&program)
.map(|next_program| {
next_program
.fragments()
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste))
.chain(
next_program
.operations()
.map(|def| print_operation(&schema, def, JsModuleFormat::Haste)),
)
.map(|def| {
print_fragment(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
})
.chain(next_program.operations().map(|def| {
print_operation(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
}))
.collect::<Vec<_>>()
.join("\n\n")
})
Expand Down
13 changes: 6 additions & 7 deletions compiler/crates/relay-codegen/tests/relay_actor_change/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use graphql_test_helpers::diagnostics_to_sorted_string;
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::get_test_schema;
use relay_transforms::relay_actor_change_transform;
use relay_transforms::{relay_actor_change_transform, DeferStreamInterface};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -27,14 +27,13 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let program = Program::from_definitions(Arc::clone(&schema), ir);
let next_program = relay_actor_change_transform(&program, &FeatureFlag::Enabled)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;
let defer_stream_interface = DeferStreamInterface::default();
let mut result = next_program
.fragments()
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste))
.chain(
next_program
.operations()
.map(|def| print_operation(&schema, def, JsModuleFormat::Haste)),
)
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste, &defer_stream_interface))
.chain(next_program.operations().map(|def| {
print_operation(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
}))
.collect::<Vec<_>>();
result.sort_unstable();
Ok(result.join("\n\n"))
Expand Down
12 changes: 9 additions & 3 deletions compiler/crates/relay-codegen/tests/request_metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use graphql_syntax::parse_executable;
use intern::string_key::Intern;
use relay_codegen::{build_request_params, print_fragment, print_request, JsModuleFormat};
use relay_test_schema::TEST_SCHEMA;
use relay_transforms::DeferStreamInterface;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let ast = parse_executable(
Expand All @@ -23,6 +24,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
)
.unwrap();
let program = build(&TEST_SCHEMA, &ast.definitions);
let defer_stream_interface = DeferStreamInterface::default();
program
.map(|definitions| {
definitions
Expand Down Expand Up @@ -67,11 +69,15 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
&operation_fragment,
request_parameters,
JsModuleFormat::Haste,
&defer_stream_interface,
)
}
ExecutableDefinition::Fragment(fragment) => {
print_fragment(&TEST_SCHEMA, fragment, JsModuleFormat::Haste)
}
ExecutableDefinition::Fragment(fragment) => print_fragment(
&TEST_SCHEMA,
fragment,
JsModuleFormat::Haste,
&defer_stream_interface,
),
})
.collect::<Vec<_>>()
.join("\n\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::required_directive;
use relay_transforms::{required_directive, DeferStreamInterface};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -27,17 +27,17 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let ir = build(&schema, &ast.definitions)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;
let program = Program::from_definitions(Arc::clone(&schema), ir);

let defer_stream_interface = DeferStreamInterface::default();
required_directive(&program)
.map(|next_program| {
next_program
.fragments()
.map(|def| print_fragment(&schema, def, JsModuleFormat::Haste))
.chain(
next_program
.operations()
.map(|def| print_operation(&schema, def, JsModuleFormat::Haste)),
)
.map(|def| {
print_fragment(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
})
.chain(next_program.operations().map(|def| {
print_operation(&schema, def, JsModuleFormat::Haste, &defer_stream_interface)
}))
.collect::<Vec<_>>()
.join("\n\n")
})
Expand Down
Loading

0 comments on commit 7b5414c

Please sign in to comment.