Skip to content

Commit

Permalink
pass default DeferStreamInterface to tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	compiler/crates/relay-compiler/tests/compile_relay_artifacts/mod.rs
#	compiler/crates/relay-lsp/src/graphql_tools/mod.rs
#	compiler/crates/relay-typegen/tests/generate_flow/mod.rs
#	compiler/crates/relay-typegen/tests/generate_typescript/mod.rs
  • Loading branch information
robrichard committed Dec 17, 2021
1 parent 2165915 commit efb0550
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 67 deletions.
13 changes: 7 additions & 6 deletions compiler/crates/relay-codegen/tests/client_edges/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fixture_tests::Fixture;
use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::get_test_schema_with_extensions;
use relay_transforms::{client_edges, relay_resolvers, sort_selections};
use std::sync::Arc;
Expand All @@ -26,14 +27,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
12 changes: 6 additions & 6 deletions compiler/crates/relay-codegen/tests/client_extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ use fixture_tests::Fixture;
use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::get_test_schema_with_extensions;
use relay_transforms::{client_extensions, sort_selections};
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 +26,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
16 changes: 13 additions & 3 deletions compiler/crates/relay-codegen/tests/connections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use graphql_ir::{build, FragmentDefinition, Program};
use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_codegen::{build_request_params, JsModuleFormat, Printer};
use relay_config::DeferStreamInterface;
use relay_test_schema::get_test_schema;
use relay_transforms::{transform_connections, validate_connections, ConnectionInterface};
use std::sync::Arc;
Expand All @@ -32,7 +33,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 +50,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 @@ -10,6 +10,7 @@ use fixture_tests::Fixture;
use graphql_ir::build;
use graphql_syntax::parse_executable;
use relay_codegen::{JsModuleFormat, Printer};
use relay_config::DeferStreamInterface;
use relay_test_schema::TEST_SCHEMA;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
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
15 changes: 8 additions & 7 deletions compiler/crates/relay-codegen/tests/defer_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fixture_tests::Fixture;
use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::get_test_schema;
use relay_transforms::{sort_selections, transform_defer_stream};
use std::sync::Arc;
Expand All @@ -23,15 +24,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 @@ -10,6 +10,7 @@ use fixture_tests::Fixture;
use graphql_ir::{build, ExecutableDefinition};
use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::TEST_SCHEMA;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -18,17 +19,24 @@ 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 {
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
14 changes: 8 additions & 6 deletions compiler/crates/relay-codegen/tests/react_flight_codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::react_flight;
use std::sync::Arc;
Expand All @@ -27,17 +28,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
12 changes: 6 additions & 6 deletions compiler/crates/relay-codegen/tests/relay_actor_change/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use graphql_test_helpers::diagnostics_to_sorted_string;

use graphql_syntax::parse_executable;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::get_test_schema;
use relay_transforms::relay_actor_change_transform;
use std::sync::Arc;
Expand All @@ -27,14 +28,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 @@ -14,6 +14,7 @@ use graphql_ir::{
use graphql_syntax::parse_executable;
use intern::string_key::Intern;
use relay_codegen::{build_request_params, print_fragment, print_request, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::TEST_SCHEMA;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
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 @@ -11,6 +11,7 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_codegen::{print_fragment, print_operation, JsModuleFormat};
use relay_config::DeferStreamInterface;
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::required_directive;
use std::sync::Arc;
Expand All @@ -27,17 +28,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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
.named(*DIRECTIVE_SPLIT_OPERATION)
.is_some()
{
print_operation(&schema, operation, JsModuleFormat::Haste)
print_operation(
&schema,
operation,
JsModuleFormat::Haste,
&project_config.schema_config.defer_stream_interface,
)
} else {
let name = operation.name.item;
let print_operation_node = programs
Expand Down Expand Up @@ -132,7 +137,8 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
operation,
&operation_fragment,
request_parameters,
JsModuleFormat::Haste
JsModuleFormat::Haste,
&project_config.schema_config.defer_stream_interface
),
text
)
Expand All @@ -142,9 +148,14 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let mut fragments: Vec<&std::sync::Arc<FragmentDefinition>> =
programs.reader.fragments().collect();
fragments.sort_by_key(|fragment| fragment.name.item);
fragments
.into_iter()
.map(|fragment| print_fragment(&schema, fragment, JsModuleFormat::Haste))
fragments.into_iter().map(|fragment| {
print_fragment(
&schema,
fragment,
JsModuleFormat::Haste,
&project_config.schema_config.defer_stream_interface,
)
})
})
.collect::<Vec<_>>();
Ok(result.join("\n\n"))
Expand Down
6 changes: 4 additions & 2 deletions compiler/crates/relay-transforms/tests/defer_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

use fixture_tests::Fixture;
use graphql_test_helpers::apply_transform_for_test;
use relay_config::DeferStreamInterface;
use relay_transforms::{transform_defer_stream, unwrap_custom_directive_selection};

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
apply_transform_for_test(fixture, |program| {
let program = transform_defer_stream(program)?;
let program = unwrap_custom_directive_selection(&program);
let defer_stream_interface = DeferStreamInterface::default();
let program = transform_defer_stream(program, &defer_stream_interface)?;
let program = unwrap_custom_directive_selection(&program, &defer_stream_interface);
Ok(program)
})
}
Loading

0 comments on commit efb0550

Please sign in to comment.