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 Jan 27, 2022
1 parent ab2480e commit 3ce00b0
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 22 deletions.
5 changes: 3 additions & 2 deletions compiler/crates/relay-codegen/tests/connections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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 next_program = transform_connections(&program, &project_config.schema_config);

let mut printed = next_program
.operations()
Expand All @@ -58,13 +58,14 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
&operation_fragment,
request_parameters,
&mut import_statements,
&project_config,
);
format!("{}{}", import_statements, request)
})
.collect::<Vec<_>>();
let mut import_statements = Default::default();
for def in next_program.fragments() {
printed.push(printer.print_fragment(&schema, def, &mut import_statements));
printed.push(printer.print_fragment(&schema, def, &mut import_statements, &project_config));
}
if !import_statements.is_empty() {
printed.push(import_statements.to_string())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
&TEST_SCHEMA,
operation,
&mut import_statements,
&project_config,
);
format!("Operation:\n{}{}\n", import_statements, operation,)
}
graphql_ir::ExecutableDefinition::Fragment(fragment) => {
let mut import_statements = Default::default();
let fragment =
printer.print_fragment(&TEST_SCHEMA, fragment, &mut import_statements);
let fragment = printer.print_fragment(
&TEST_SCHEMA,
fragment,
&mut import_statements,
&project_config,
);
format!("Fragment:\n{}{}\n", import_statements, fragment)
}
})
Expand Down
6 changes: 4 additions & 2 deletions compiler/crates/relay-codegen/tests/defer_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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::ProjectConfig;
use relay_config::{DeferStreamInterface, ProjectConfig};
use relay_test_schema::get_test_schema;
use relay_transforms::{sort_selections, transform_defer_stream};
use std::sync::Arc;
Expand All @@ -24,7 +24,9 @@ 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| {
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)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use common::FeatureFlags;
use fixture_tests::Fixture;
use graphql_test_helpers::apply_transform_for_test;
use relay_config::DeferStreamInterface;
use relay_transforms::{generate_data_driven_dependency_metadata, transform_match};

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
apply_transform_for_test(fixture, |program| {
let flags = FeatureFlags::default();
let program = transform_match(program, &flags)?;
let defer_stream_interface = DeferStreamInterface::default();
let program = transform_match(program, &flags, &defer_stream_interface)?;
let program = generate_data_driven_dependency_metadata(&program);
Ok(program)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
use common::FeatureFlags;
use fixture_tests::Fixture;
use graphql_test_helpers::apply_transform_for_test;
use relay_config::DeferStreamInterface;
use relay_transforms::transform_match;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let flags = FeatureFlags::default();
apply_transform_for_test(fixture, |program| transform_match(program, &flags))
let defer_stream_interface = DeferStreamInterface::default();
apply_transform_for_test(fixture, |program| {
transform_match(program, &flags, &defer_stream_interface)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
*/

use fixture_tests::Fixture;
use relay_transforms::{
transform_connections, transform_refetchable_fragment, ConnectionInterface,
};
use relay_config::SchemaConfig;
use relay_transforms::{transform_connections, transform_refetchable_fragment};

use graphql_test_helpers::apply_transform_for_test;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
apply_transform_for_test(fixture, |program| {
let program = transform_connections(program, &ConnectionInterface::default());
let program = transform_connections(program, &SchemaConfig::default());
let base_fragments = Default::default();
transform_refetchable_fragment(&program, &Default::default(), &base_fragments, false)
})
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, Program};
use graphql_syntax::parse_executable;
use graphql_text_printer::{print_operation, PrinterOptions};
use relay_config::DeferStreamInterface;
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::{inline_fragments, skip_redundant_nodes};
use std::sync::Arc;
Expand All @@ -21,12 +22,14 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
debug_directive_data: true,
..Default::default()
};
let defer_stream_interface = DeferStreamInterface::default();
let mut printed = if let [base, extensions] = parts.as_slice() {
let ast = parse_executable(base, source_location).unwrap();
let schema = get_test_schema_with_extensions(extensions);
let ir = build(&schema, &ast.definitions).unwrap();
let program = Program::from_definitions(Arc::clone(&schema), ir);
let next_program = skip_redundant_nodes(&inline_fragments(&program));
let next_program =
skip_redundant_nodes(&inline_fragments(&program), &defer_stream_interface);
next_program
.operations()
.map(|def| print_operation(&schema, def, printer_options.clone()))
Expand All @@ -36,7 +39,8 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let ast = parse_executable(fixture.content, source_location).unwrap();
let ir = build(&schema, &ast.definitions).unwrap();
let program = Program::from_definitions(Arc::clone(&schema), ir);
let next_program = skip_redundant_nodes(&inline_fragments(&program));
let next_program =
skip_redundant_nodes(&inline_fragments(&program), &defer_stream_interface);
next_program
.operations()
.map(|def| print_operation(&schema, def, printer_options.clone()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

use fixture_tests::Fixture;
use graphql_test_helpers::apply_transform_for_test;
use relay_config::DeferStreamInterface;
use relay_transforms::skip_unreachable_node;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
apply_transform_for_test(fixture, skip_unreachable_node)
let defer_stream_interface = DeferStreamInterface::default();
apply_transform_for_test(fixture, |program| {
skip_unreachable_node(program, &defer_stream_interface)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use graphql_test_helpers::diagnostics_to_sorted_string;
use graphql_text_printer::{print_fragment, print_operation, PrinterOptions};
use relay_config::SchemaConfig;
use relay_test_schema::get_test_schema;
use relay_transforms::{transform_connections, validate_connections, ConnectionInterface};
use relay_transforms::{transform_connections, validate_connections};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand All @@ -26,12 +27,12 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {

let program = Program::from_definitions(Arc::clone(&schema), ir);

let connection_interface = ConnectionInterface::default();
let schema_config = SchemaConfig::default();

validate_connections(&program, &connection_interface)
validate_connections(&program, &schema_config.connection_interface)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;

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

let printer_options = PrinterOptions {
debug_directive_data: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use graphql_cli::DiagnosticPrinter;
use graphql_ir::{build, Program};
use graphql_syntax::{parse_executable, GraphQLSource};
use graphql_test_helpers::diagnostics_to_sorted_string;
use relay_config::DeferStreamInterface;
use relay_test_schema::TEST_SCHEMA;
use relay_transforms::validate_selection_conflict;
use std::sync::Arc;
Expand Down Expand Up @@ -40,7 +41,8 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
};

let program = Program::from_definitions(Arc::clone(&TEST_SCHEMA), ir);
validate_selection_conflict(&program)
let defer_stream_interface = DeferStreamInterface::default();
validate_selection_conflict(&program, &defer_stream_interface)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;

Ok("OK".to_owned())
Expand Down

0 comments on commit 3ce00b0

Please sign in to comment.