diff --git a/compiler/crates/graphql-ir/src/errors.rs b/compiler/crates/graphql-ir/src/errors.rs index e6db4d62d1966..226220f25de87 100644 --- a/compiler/crates/graphql-ir/src/errors.rs +++ b/compiler/crates/graphql-ir/src/errors.rs @@ -407,7 +407,7 @@ pub enum ValidationMessage { #[error("Invalid use of @stream on scalar field '{field_name}'")] InvalidStreamOnScalarField { field_name: StringKey }, - #[error("Invalid use of @stream, the 'initial_count' argument is required.")] + #[error("Invalid use of @stream, the 'initialCount' argument is required.")] StreamInitialCountRequired, #[error("Variable `${variable_name}` is never used in operation `{operation_name}`")] diff --git a/compiler/crates/relay-codegen/src/build_ast.rs b/compiler/crates/relay-codegen/src/build_ast.rs index 5405e071377e9..70cc6e054db63 100644 --- a/compiler/crates/relay-codegen/src/build_ast.rs +++ b/compiler/crates/relay-codegen/src/build_ast.rs @@ -20,10 +20,10 @@ use relay_transforms::{ extract_connection_metadata_from_directive, extract_handle_field_directives, extract_refetch_metadata_from_directive, extract_values_from_handle_field_directive, extract_variable_name, generate_abstract_type_refinement_key, remove_directive, - ConnectionConstants, ConnectionMetadata, DeferDirective, RelayDirective, StreamDirective, - ACTION_ARGUMENT, CLIENT_EXTENSION_DIRECTIVE_NAME, DEFER_STREAM_CONSTANTS, - DIRECTIVE_SPLIT_OPERATION, INLINE_DATA_CONSTANTS, INTERNAL_METADATA_DIRECTIVE, MATCH_CONSTANTS, - PATH_METADATA_ARGUMENT, REACT_FLIGHT_SCALAR_FLIGHT_FIELD_METADATA_KEY, REQUIRED_METADATA_KEY, + ConnectionConstants, ConnectionMetadata, DeferDirective, DeferStreamInterface, RelayDirective, + StreamDirective, ACTION_ARGUMENT, CLIENT_EXTENSION_DIRECTIVE_NAME, DIRECTIVE_SPLIT_OPERATION, + INLINE_DATA_CONSTANTS, INTERNAL_METADATA_DIRECTIVE, MATCH_CONSTANTS, PATH_METADATA_ARGUMENT, + REACT_FLIGHT_SCALAR_FLIGHT_FIELD_METADATA_KEY, REQUIRED_METADATA_KEY, TYPE_DISCRIMINATOR_DIRECTIVE_NAME, }; use schema::Schema; @@ -33,9 +33,14 @@ pub fn build_request_params_ast_key( request_parameters: RequestParameters, ast_builder: &mut AstBuilder, operation: &OperationDefinition, + defer_stream_interface: &DeferStreamInterface, ) -> AstKey { - let mut operation_builder = - CodegenBuilder::new(schema, CodegenVariant::Normalization, ast_builder); + let mut operation_builder = CodegenBuilder::new( + schema, + CodegenVariant::Normalization, + ast_builder, + defer_stream_interface, + ); operation_builder.build_request_parameters(operation, request_parameters) } @@ -45,11 +50,21 @@ pub fn build_request( operation: &OperationDefinition, fragment: &FragmentDefinition, request_parameters: AstKey, + defer_stream_interface: &DeferStreamInterface, ) -> AstKey { - let mut operation_builder = - CodegenBuilder::new(schema, CodegenVariant::Normalization, ast_builder); + let mut operation_builder = CodegenBuilder::new( + schema, + CodegenVariant::Normalization, + ast_builder, + defer_stream_interface, + ); let operation = Primitive::Key(operation_builder.build_operation(operation)); - let mut fragment_builder = CodegenBuilder::new(schema, CodegenVariant::Reader, ast_builder); + let mut fragment_builder = CodegenBuilder::new( + schema, + CodegenVariant::Reader, + ast_builder, + defer_stream_interface, + ); let fragment = Primitive::Key(fragment_builder.build_fragment(fragment, true)); ast_builder.intern(Ast::Object(vec![ @@ -86,8 +101,14 @@ pub fn build_operation( schema: &Schema, ast_builder: &mut AstBuilder, operation: &OperationDefinition, + defer_stream_interface: &DeferStreamInterface, ) -> AstKey { - let mut builder = CodegenBuilder::new(schema, CodegenVariant::Normalization, ast_builder); + let mut builder = CodegenBuilder::new( + schema, + CodegenVariant::Normalization, + ast_builder, + defer_stream_interface, + ); builder.build_operation(operation) } @@ -95,13 +116,20 @@ pub fn build_fragment( schema: &Schema, ast_builder: &mut AstBuilder, fragment: &FragmentDefinition, + defer_stream_interface: &DeferStreamInterface, ) -> AstKey { - let mut builder = CodegenBuilder::new(schema, CodegenVariant::Reader, ast_builder); + let mut builder = CodegenBuilder::new( + schema, + CodegenVariant::Reader, + ast_builder, + defer_stream_interface, + ); builder.build_fragment(fragment, false) } -struct CodegenBuilder<'schema, 'builder> { +struct CodegenBuilder<'schema, 'builder, 'dsi> { connection_constants: ConnectionConstants, + defer_stream_interface: &'dsi DeferStreamInterface, schema: &'schema Schema, variant: CodegenVariant, ast_builder: &'builder mut AstBuilder, @@ -113,14 +141,16 @@ enum CodegenVariant { Normalization, } -impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { +impl<'schema, 'builder, 'dsi> CodegenBuilder<'schema, 'builder, 'dsi> { fn new( schema: &'schema Schema, variant: CodegenVariant, ast_builder: &'builder mut AstBuilder, + defer_stream_interface: &'dsi DeferStreamInterface, ) -> Self { Self { connection_constants: Default::default(), + defer_stream_interface, schema, variant, ast_builder, @@ -413,7 +443,7 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { ]; if metadata.is_stream_connection { object.push(ObjectEntry { - key: DEFER_STREAM_CONSTANTS.stream_name, + key: self.defer_stream_interface.stream_name, value: Primitive::Bool(true), }) } @@ -460,7 +490,7 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { Selection::InlineFragment(inline_frag) => { let defer = inline_frag .directives - .named(DEFER_STREAM_CONSTANTS.defer_name); + .named(self.defer_stream_interface.defer_name); if let Some(defer) = defer { vec![self.build_defer(&inline_frag, defer)] } else if let Some(inline_data_directive) = inline_frag @@ -469,12 +499,8 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { { // If inline fragment has @__inline directive (created by inline_data_fragment transform) // we will return selection wrapped with InlineDataFragmentSpread - vec![ - self.build_inline_data_fragment_spread( - &inline_frag, - &inline_data_directive, - ), - ] + vec![self + .build_inline_data_fragment_spread(&inline_frag, &inline_data_directive)] } else if let Some(match_directive) = inline_frag .directives .named(MATCH_CONSTANTS.custom_module_directive_name) @@ -485,7 +511,9 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { } } Selection::LinkedField(field) => { - let stream = field.directives.named(DEFER_STREAM_CONSTANTS.stream_name); + let stream = field + .directives + .named(self.defer_stream_interface.stream_name); match stream { Some(stream) => vec![self.build_stream(&field, stream)], @@ -890,7 +918,8 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { defer: &Directive, ) -> Primitive { let next_selections = self.build_selections(inline_fragment.selections.iter()); - let DeferDirective { if_arg, label_arg } = DeferDirective::from(defer); + let DeferDirective { if_arg, label_arg } = + DeferDirective::from(defer, self.defer_stream_interface); let if_variable_name = extract_variable_name(if_arg); let label_name = label_arg.unwrap().value.item.expect_string_literal(); @@ -918,7 +947,7 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { let next_selections = vec![self.build_linked_field(&LinkedField { directives: remove_directive( &linked_field.directives, - DEFER_STREAM_CONSTANTS.stream_name, + self.defer_stream_interface.stream_name, ), ..linked_field.to_owned() })]; @@ -940,7 +969,7 @@ impl<'schema, 'builder> CodegenBuilder<'schema, 'builder> { label_arg, use_customized_batch_arg, initial_count_arg: _, - } = StreamDirective::from(stream); + } = StreamDirective::from(stream, self.defer_stream_interface); let if_variable_name = extract_variable_name(if_arg); let use_customized_batch_variable_name = extract_variable_name(use_customized_batch_arg); diff --git a/compiler/crates/relay-codegen/src/printer.rs b/compiler/crates/relay-codegen/src/printer.rs index b5b5422b58fc5..93c768a42fdf4 100644 --- a/compiler/crates/relay-codegen/src/printer.rs +++ b/compiler/crates/relay-codegen/src/printer.rs @@ -15,6 +15,7 @@ use crate::indentation::print_indentation; use crate::utils::escape; use graphql_ir::{FragmentDefinition, OperationDefinition}; +use relay_transforms::DeferStreamInterface; use schema::Schema; use fnv::{FnvBuildHasher, FnvHashSet}; @@ -22,12 +23,20 @@ use indexmap::IndexMap; use interner::StringKey; use std::fmt::{Result as FmtResult, Write}; -pub fn print_operation(schema: &Schema, operation: &OperationDefinition) -> String { - Printer::without_dedupe().print_operation(schema, operation) +pub fn print_operation( + schema: &Schema, + operation: &OperationDefinition, + defer_stream_interface: &DeferStreamInterface, +) -> String { + Printer::without_dedupe().print_operation(schema, operation, defer_stream_interface) } -pub fn print_fragment(schema: &Schema, fragment: &FragmentDefinition) -> String { - Printer::without_dedupe().print_fragment(schema, fragment) +pub fn print_fragment( + schema: &Schema, + fragment: &FragmentDefinition, + defer_stream_interface: &DeferStreamInterface, +) -> String { + Printer::without_dedupe().print_fragment(schema, fragment, defer_stream_interface) } pub fn print_request( @@ -35,21 +44,34 @@ pub fn print_request( operation: &OperationDefinition, fragment: &FragmentDefinition, request_parameters: RequestParameters, + defer_stream_interface: &DeferStreamInterface, ) -> String { - Printer::without_dedupe().print_request(schema, operation, fragment, request_parameters) + Printer::without_dedupe().print_request( + schema, + operation, + fragment, + request_parameters, + defer_stream_interface, + ) } pub fn print_request_params( schema: &Schema, operation: &OperationDefinition, query_id: Option, + defer_stream_interface: &DeferStreamInterface, ) -> String { let mut request_parameters = build_request_params(operation); request_parameters.id = query_id; let mut builder = AstBuilder::default(); - let request_parameters_ast_key = - build_request_params_ast_key(schema, request_parameters, &mut builder, operation); + let request_parameters_ast_key = build_request_params_ast_key( + schema, + request_parameters, + &mut builder, + operation, + defer_stream_interface, + ); let printer = JSONPrinter::new(&builder); printer.print(request_parameters_ast_key, false) } @@ -80,28 +102,45 @@ impl Printer { operation: &OperationDefinition, fragment: &FragmentDefinition, request_parameters: RequestParameters, + defer_stream_interface: &DeferStreamInterface, ) -> String { - let request_parameters = - build_request_params_ast_key(schema, request_parameters, &mut self.builder, operation); + let request_parameters = build_request_params_ast_key( + schema, + request_parameters, + &mut self.builder, + operation, + defer_stream_interface, + ); let key = build_request( schema, &mut self.builder, operation, fragment, request_parameters, + defer_stream_interface, ); let printer = JSONPrinter::new(&self.builder); printer.print(key, self.dedupe) } - pub fn print_operation(&mut self, schema: &Schema, operation: &OperationDefinition) -> String { - let key = build_operation(schema, &mut self.builder, operation); + pub fn print_operation( + &mut self, + schema: &Schema, + operation: &OperationDefinition, + defer_stream_interface: &DeferStreamInterface, + ) -> String { + let key = build_operation(schema, &mut self.builder, operation, defer_stream_interface); let printer = JSONPrinter::new(&self.builder); printer.print(key, self.dedupe) } - pub fn print_fragment(&mut self, schema: &Schema, fragment: &FragmentDefinition) -> String { - let key = build_fragment(schema, &mut self.builder, fragment); + pub fn print_fragment( + &mut self, + schema: &Schema, + fragment: &FragmentDefinition, + defer_stream_interface: &DeferStreamInterface, + ) -> String { + let key = build_fragment(schema, &mut self.builder, fragment, defer_stream_interface); let printer = JSONPrinter::new(&self.builder); printer.print(key, self.dedupe) } diff --git a/compiler/crates/relay-codegen/tests/client_extensions/mod.rs b/compiler/crates/relay-codegen/tests/client_extensions/mod.rs index 4c7346f0173af..3a3d530c1130e 100644 --- a/compiler/crates/relay-codegen/tests/client_extensions/mod.rs +++ b/compiler/crates/relay-codegen/tests/client_extensions/mod.rs @@ -11,7 +11,7 @@ use graphql_ir::{build, Program}; use graphql_syntax::parse_executable; use relay_codegen::{print_fragment, print_operation}; 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 { @@ -22,13 +22,14 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let ir = build(&schema, &ast.definitions).unwrap(); let program = Program::from_definitions(Arc::clone(&schema), ir); let next_program = sort_selections(&client_extensions(&program)); + let defer_stream_interface = DeferStreamInterface::default(); let mut result = next_program .fragments() - .map(|def| print_fragment(&schema, &def)) + .map(|def| print_fragment(&schema, &def, &defer_stream_interface)) .chain( next_program .operations() - .map(|def| print_operation(&schema, &def)), + .map(|def| print_operation(&schema, &def, &defer_stream_interface)), ) .collect::>(); result.sort_unstable(); diff --git a/compiler/crates/relay-codegen/tests/connections/mod.rs b/compiler/crates/relay-codegen/tests/connections/mod.rs index e97d4d807a05c..31657677d5d32 100644 --- a/compiler/crates/relay-codegen/tests/connections/mod.rs +++ b/compiler/crates/relay-codegen/tests/connections/mod.rs @@ -12,7 +12,9 @@ use graphql_syntax::parse_executable; use graphql_test_helpers::diagnostics_to_sorted_string; use relay_codegen::{build_request_params, 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 { @@ -28,11 +30,13 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let program = Program::from_definitions(Arc::clone(&schema), ir); let connection_interface = ConnectionInterface::default(); + let defer_stream_interface = DeferStreamInterface::default(); 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, &connection_interface, &defer_stream_interface); let mut printed = next_program .operations() @@ -46,11 +50,17 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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::>(); 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")) diff --git a/compiler/crates/relay-codegen/tests/deduped_json_codegen/mod.rs b/compiler/crates/relay-codegen/tests/deduped_json_codegen/mod.rs index 9f52171b29798..6163e98031fbc 100644 --- a/compiler/crates/relay-codegen/tests/deduped_json_codegen/mod.rs +++ b/compiler/crates/relay-codegen/tests/deduped_json_codegen/mod.rs @@ -11,6 +11,7 @@ use graphql_ir::build; use graphql_syntax::parse_executable; use relay_codegen::Printer; use relay_test_schema::TEST_SCHEMA; +use relay_transforms::DeferStreamInterface; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let mut printer = Printer::with_dedupe(); @@ -19,6 +20,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { SourceLocationKey::standalone(fixture.file_name), ) .unwrap(); + let defer_stream_interface = DeferStreamInterface::default(); build(&TEST_SCHEMA, &ast.definitions) .map(|definitions| { definitions @@ -26,11 +28,11 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { .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::>() diff --git a/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected b/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected index 95222b6649848..a741b1fce7a72 100644 --- a/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected +++ b/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1) { + actors @stream(initialCount: 1) { name } } diff --git a/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql b/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql index 23fa23b3e8e43..739db7de64c6a 100644 --- a/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql +++ b/compiler/crates/relay-codegen/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql @@ -7,7 +7,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1) { + actors @stream(initialCount: 1) { name } } diff --git a/compiler/crates/relay-codegen/tests/defer_stream/mod.rs b/compiler/crates/relay-codegen/tests/defer_stream/mod.rs index 9fdb28309b29a..35c70ce906a57 100644 --- a/compiler/crates/relay-codegen/tests/defer_stream/mod.rs +++ b/compiler/crates/relay-codegen/tests/defer_stream/mod.rs @@ -11,7 +11,7 @@ use graphql_ir::{build, Program}; use graphql_syntax::parse_executable; use relay_codegen::{print_fragment, print_operation}; 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 { @@ -23,14 +23,16 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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)) + .map(|def| print_fragment(&schema, &def, &defer_stream_interface)) .chain( next_program .operations() - .map(|def| print_operation(&schema, &def)), + .map(|def| print_operation(&schema, &def, &defer_stream_interface)), ) .collect::>(); result.sort_unstable(); diff --git a/compiler/crates/relay-codegen/tests/json_codegen/mod.rs b/compiler/crates/relay-codegen/tests/json_codegen/mod.rs index 8d8aaa5a2f64e..000e5115b9913 100644 --- a/compiler/crates/relay-codegen/tests/json_codegen/mod.rs +++ b/compiler/crates/relay-codegen/tests/json_codegen/mod.rs @@ -11,6 +11,7 @@ use graphql_ir::{build, ExecutableDefinition}; use graphql_syntax::parse_executable; use relay_codegen::{print_fragment, print_operation}; use relay_test_schema::TEST_SCHEMA; +use relay_transforms::DeferStreamInterface; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let ast = parse_executable( @@ -18,16 +19,17 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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) + print_operation(&TEST_SCHEMA, operation, &defer_stream_interface) } ExecutableDefinition::Fragment(fragment) => { - print_fragment(&TEST_SCHEMA, fragment) + print_fragment(&TEST_SCHEMA, fragment, &defer_stream_interface) } }) .collect::>() diff --git a/compiler/crates/relay-codegen/tests/react_flight_codegen/mod.rs b/compiler/crates/relay-codegen/tests/react_flight_codegen/mod.rs index 7e587193d2e01..7616bc0362524 100644 --- a/compiler/crates/relay-codegen/tests/react_flight_codegen/mod.rs +++ b/compiler/crates/relay-codegen/tests/react_flight_codegen/mod.rs @@ -12,7 +12,7 @@ use graphql_syntax::parse_executable; use graphql_test_helpers::diagnostics_to_sorted_string; use relay_codegen::{print_fragment, print_operation}; 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 { @@ -27,16 +27,17 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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)) + .map(|def| print_fragment(&schema, &def, &defer_stream_interface)) .chain( next_program .operations() - .map(|def| print_operation(&schema, &def)), + .map(|def| print_operation(&schema, &def, &defer_stream_interface)), ) .collect::>() .join("\n\n") diff --git a/compiler/crates/relay-codegen/tests/request_metadata/mod.rs b/compiler/crates/relay-codegen/tests/request_metadata/mod.rs index 24e79f4381625..b1757da2fafef 100644 --- a/compiler/crates/relay-codegen/tests/request_metadata/mod.rs +++ b/compiler/crates/relay-codegen/tests/request_metadata/mod.rs @@ -15,6 +15,7 @@ use graphql_syntax::parse_executable; use interner::Intern; use relay_codegen::{build_request_params, print_fragment, print_request}; use relay_test_schema::TEST_SCHEMA; +use relay_transforms::DeferStreamInterface; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let ast = parse_executable( @@ -23,6 +24,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { ) .unwrap(); let program = build(&TEST_SCHEMA, &ast.definitions); + let defer_stream_interface = DeferStreamInterface::default(); program .map(|definitions| { definitions @@ -65,10 +67,11 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { &operation, &operation_fragment, request_parameters, + &defer_stream_interface, ) } ExecutableDefinition::Fragment(fragment) => { - print_fragment(&TEST_SCHEMA, fragment) + print_fragment(&TEST_SCHEMA, fragment, &defer_stream_interface) } }) .collect::>() diff --git a/compiler/crates/relay-codegen/tests/required_directive_codegen/mod.rs b/compiler/crates/relay-codegen/tests/required_directive_codegen/mod.rs index ca0b3a22f59b1..aa48954fec082 100644 --- a/compiler/crates/relay-codegen/tests/required_directive_codegen/mod.rs +++ b/compiler/crates/relay-codegen/tests/required_directive_codegen/mod.rs @@ -13,7 +13,7 @@ use graphql_test_helpers::diagnostics_to_sorted_string; use interner::Intern; use relay_codegen::{print_fragment, print_operation}; use relay_test_schema::{get_test_schema, get_test_schema_with_extensions}; -use relay_transforms::{required_directive, FeatureFlags}; +use relay_transforms::{required_directive, DeferStreamInterface, FeatureFlags}; use std::sync::Arc; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { @@ -28,6 +28,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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, @@ -39,11 +40,11 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { .map(|next_program| { next_program .fragments() - .map(|def| print_fragment(&schema, &def)) + .map(|def| print_fragment(&schema, &def, &defer_stream_interface)) .chain( next_program .operations() - .map(|def| print_operation(&schema, &def)), + .map(|def| print_operation(&schema, &def, &defer_stream_interface)), ) .collect::>() .join("\n\n") diff --git a/compiler/crates/relay-compiler-neon/native/src/lib.rs b/compiler/crates/relay-compiler-neon/native/src/lib.rs index 38b14b20926fe..f19b9354d6b1b 100644 --- a/compiler/crates/relay-compiler-neon/native/src/lib.rs +++ b/compiler/crates/relay-compiler-neon/native/src/lib.rs @@ -18,7 +18,7 @@ use relay_compiler::{ status_reporter::ConsoleStatusReporter, ArtifactFileWriter, SourceHashes, }; -use relay_transforms::{ConnectionInterface, FeatureFlags}; +use relay_transforms::{ConnectionInterface, DeferStreamInterface, FeatureFlags}; use schema::build_schema; use std::str; use std::sync::Arc; @@ -107,6 +107,7 @@ fn create_configs() -> (Config, ProjectConfig) { saved_state_loader: None, saved_state_version: "0".to_owned(), connection_interface: Default::default(), + defer_stream_interface: Default::default(), feature_flags: FeatureFlags::default(), operation_persister: None, compile_everything: false, @@ -138,6 +139,7 @@ fn compile(mut cx: FunctionContext<'_>) -> JsResult<'_, JsObject> { Arc::new(program), Arc::new(Default::default()), &ConnectionInterface::default(), + &DeferStreamInterface::default(), Arc::new(FeatureFlags::default()), Arc::new(ConsoleLogger), ) diff --git a/compiler/crates/relay-compiler/src/build_project/apply_transforms.rs b/compiler/crates/relay-compiler/src/build_project/apply_transforms.rs index 00ca584c1053b..1debd2a539906 100644 --- a/compiler/crates/relay-compiler/src/build_project/apply_transforms.rs +++ b/compiler/crates/relay-compiler/src/build_project/apply_transforms.rs @@ -26,6 +26,7 @@ pub fn apply_transforms( program: Arc, base_fragment_names: Arc>, connection_interface: &ConnectionInterface, + defer_stream_interface: &DeferStreamInterface, feature_flags: Arc, perf_logger: Arc, ) -> DiagnosticsResult @@ -50,6 +51,7 @@ where project_name, Arc::clone(&program), connection_interface, + defer_stream_interface, Arc::clone(&feature_flags), Arc::clone(&base_fragment_names), Arc::clone(&perf_logger), @@ -71,6 +73,7 @@ where project_name, Arc::clone(&operation_program), Arc::clone(&perf_logger), + defer_stream_interface, ) }, || { @@ -78,6 +81,7 @@ where project_name, Arc::clone(&operation_program), Arc::clone(&perf_logger), + defer_stream_interface, ) }, ) @@ -89,6 +93,7 @@ where Arc::clone(&feature_flags), Arc::clone(&base_fragment_names), Arc::clone(&perf_logger), + defer_stream_interface, ) }, ) @@ -100,6 +105,7 @@ where Arc::clone(&feature_flags), Arc::clone(&base_fragment_names), Arc::clone(&perf_logger), + defer_stream_interface, ) }, )?; @@ -118,6 +124,7 @@ fn apply_common_transforms( project_name: StringKey, program: Arc, connection_interface: &ConnectionInterface, + defer_stream_interface: &DeferStreamInterface, feature_flags: Arc, base_fragment_names: Arc>, perf_logger: Arc, @@ -133,13 +140,15 @@ fn apply_common_transforms( let log_event = perf_logger.create_event("apply_common_transforms"); log_event.string("project", project_name.to_string()); let program = log_event.time("transform_connections", || { - transform_connections(&program, connection_interface) + transform_connections(&program, connection_interface, defer_stream_interface) }); let program = log_event.time("mask", || mask(&program)); let program = log_event.time("transform_defer_stream", || { - transform_defer_stream(&program) + transform_defer_stream(&program, &defer_stream_interface) + })?; + let program = log_event.time("transform_match", || { + transform_match(&program, &defer_stream_interface) })?; - let program = log_event.time("transform_match", || transform_match(&program))?; let program = log_event.time("transform_refetchable_fragment", || { transform_refetchable_fragment(&program, &base_fragment_names, false) })?; @@ -161,6 +170,7 @@ fn apply_reader_transforms( feature_flags: Arc, base_fragment_names: Arc>, perf_logger: Arc, + defer_stream_interface: &DeferStreamInterface, ) -> DiagnosticsResult> { // JS compiler // + ClientExtensionsTransform @@ -183,7 +193,9 @@ fn apply_reader_transforms( remove_base_fragments(&program, base_fragment_names) }); let program = log_event.time("flatten", || flatten(&program, true))?; - let program = log_event.time("skip_redundant_nodes", || skip_redundant_nodes(&program)); + let program = log_event.time("skip_redundant_nodes", || { + skip_redundant_nodes(&program, defer_stream_interface) + }); let program = log_event.time("generate_data_driven_dependency_metadata", || { generate_data_driven_dependency_metadata(&program) }); @@ -247,6 +259,7 @@ fn apply_normalization_transforms( project_name: StringKey, program: Arc, perf_logger: Arc, + defer_stream_interface: &DeferStreamInterface, ) -> DiagnosticsResult> { // JS compiler // + SkipUnreachableNodeTransform @@ -264,7 +277,9 @@ fn apply_normalization_transforms( let program = log_event.time("client_extensions", || client_extensions(&program)); let program = log_event.time("generate_typename", || generate_typename(&program, true)); let program = log_event.time("flatten", || flatten(&program, true))?; - let program = log_event.time("skip_redundant_nodes", || skip_redundant_nodes(&program)); + let program = log_event.time("skip_redundant_nodes", || { + skip_redundant_nodes(&program, defer_stream_interface) + }); let program = log_event.time("generate_test_operation_metadata", || { generate_test_operation_metadata(&program) }); @@ -282,6 +297,7 @@ fn apply_operation_text_transforms( project_name: StringKey, program: Arc, perf_logger: Arc, + defer_stream_interface: &DeferStreamInterface, ) -> DiagnosticsResult> { // JS compiler // + SkipSplitOperationTransform @@ -313,7 +329,7 @@ fn apply_operation_text_transforms( validate_required_arguments(&program) })?; let program = log_event.time("unwrap_custom_directive_selection", || { - unwrap_custom_directive_selection(&program) + unwrap_custom_directive_selection(&program, defer_stream_interface) }); perf_logger.complete_event(log_event); @@ -326,6 +342,7 @@ fn apply_typegen_transforms( feature_flags: Arc, base_fragment_names: Arc>, perf_logger: Arc, + defer_stream_interface: &DeferStreamInterface, ) -> DiagnosticsResult> { // JS compiler // * RelayDirectiveTransform @@ -337,7 +354,9 @@ fn apply_typegen_transforms( log_event.string("project", project_name.to_string()); let program = log_event.time("mask", || mask(&program)); - let program = log_event.time("transform_match", || transform_match(&program))?; + let program = log_event.time("transform_match", || { + transform_match(&program, defer_stream_interface) + })?; let program = log_event.time("required_directive", || { required_directive(&program, &feature_flags) })?; diff --git a/compiler/crates/relay-compiler/src/build_project/artifact_content.rs b/compiler/crates/relay-compiler/src/build_project/artifact_content.rs index a9c24cc573bc2..bcc3b2db4418e 100644 --- a/compiler/crates/relay-compiler/src/build_project/artifact_content.rs +++ b/compiler/crates/relay-compiler/src/build_project/artifact_content.rs @@ -236,6 +236,7 @@ fn generate_operation( normalization_operation, &operation_fragment, request_parameters, + &config.defer_stream_interface ) ) .unwrap(); @@ -280,7 +281,7 @@ fn generate_split_operation( writeln!( content, "var node/*: NormalizationSplitOperation*/ = {};\n", - printer.print_operation(schema, node) + printer.print_operation(schema, node, &config.defer_stream_interface) ) .unwrap(); writeln!(content, "if (__DEV__) {{").unwrap(); @@ -346,7 +347,7 @@ fn generate_fragment( content, "var node/*: {}*/ = {};\n", reader_node_flow_type, - printer.print_fragment(schema, reader_fragment) + printer.print_fragment(schema, reader_fragment, &config.defer_stream_interface) ) .unwrap(); writeln!(content, "if (__DEV__) {{").unwrap(); diff --git a/compiler/crates/relay-compiler/src/build_project/mod.rs b/compiler/crates/relay-compiler/src/build_project/mod.rs index acddc4fdd841d..ee9d94e94f469 100644 --- a/compiler/crates/relay-compiler/src/build_project/mod.rs +++ b/compiler/crates/relay-compiler/src/build_project/mod.rs @@ -117,6 +117,7 @@ fn build_programs( Arc::new(program), Arc::new(base_fragment_names), &config.connection_interface, + &config.defer_stream_interface, Arc::new(project_config.feature_flags.unwrap_or(config.feature_flags)), perf_logger, ) diff --git a/compiler/crates/relay-compiler/src/config.rs b/compiler/crates/relay-compiler/src/config.rs index d432041c21052..4c5fa6af26b9f 100644 --- a/compiler/crates/relay-compiler/src/config.rs +++ b/compiler/crates/relay-compiler/src/config.rs @@ -16,7 +16,7 @@ use async_trait::async_trait; use persist_query::PersistError; use rayon::prelude::*; use regex::Regex; -use relay_transforms::{ConnectionInterface, FeatureFlags}; +use relay_transforms::{ConnectionInterface, DeferStreamInterface, FeatureFlags}; use relay_typegen::TypegenConfig; use serde::Deserialize; use sha1::{Digest, Sha1}; @@ -59,6 +59,7 @@ pub struct Config { pub repersist_operations: bool, pub connection_interface: ConnectionInterface, + pub defer_stream_interface: DeferStreamInterface, pub feature_flags: FeatureFlags, pub saved_state_config: Option, @@ -202,6 +203,7 @@ impl Config { saved_state_loader: None, saved_state_version: hex::encode(hash.result()), connection_interface: config_file.connection_interface, + defer_stream_interface: config_file.defer_stream_interface, feature_flags: config_file.feature_flags, operation_persister: None, compile_everything: false, @@ -335,6 +337,7 @@ impl fmt::Debug for Config { saved_state_config, saved_state_loader, connection_interface, + defer_stream_interface, feature_flags, saved_state_version, operation_persister, @@ -343,7 +346,11 @@ impl fmt::Debug for Config { } = self; fn option_fn_to_string(option: &Option) -> &'static str { - if option.is_some() { "Some(Fn)" } else { "None" } + if option.is_some() { + "Some(Fn)" + } else { + "None" + } } f.debug_struct("Config") @@ -371,6 +378,7 @@ impl fmt::Debug for Config { &option_fn_to_string(saved_state_loader), ) .field("connection_interface", connection_interface) + .field("defer_stream_interface", defer_stream_interface) .field("feature_flags", feature_flags) .field("saved_state_version", saved_state_version) .field( @@ -441,6 +449,9 @@ struct ConfigFile { #[serde(default)] connection_interface: ConnectionInterface, + #[serde(default)] + defer_stream_interface: DeferStreamInterface, + #[serde(default)] feature_flags: FeatureFlags, diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.expected b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.expected index 903d342ae3aca..9b772ded2ec05 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.expected +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.expected @@ -8,7 +8,7 @@ query fragmentWithDeferInStream_QueryWithFragmentWithStreamQuery($id: ID!) { fragment fragmentWithDeferInStream_FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { ...fragmentWithDeferInStream_ActorFragment @defer } } @@ -195,7 +195,7 @@ fragment fragmentWithDeferInStream_ActorFragment on Actor { fragment fragmentWithDeferInStream_FeedbackFragment on Feedback { id - actors @stream(label: "fragmentWithDeferInStream_FeedbackFragment$stream$StreamedActorsLabel", initial_count: 1) { + actors @stream(label: "fragmentWithDeferInStream_FeedbackFragment$stream$StreamedActorsLabel", initialCount: 1) { __typename ...fragmentWithDeferInStream_ActorFragment @defer(label: "fragmentWithDeferInStream_FeedbackFragment$defer$fragmentWithDeferInStream_ActorFragment") id diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.graphql b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.graphql index 7886bae9ac370..d551db5e514b2 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.graphql +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-defer-in-stream.graphql @@ -7,7 +7,7 @@ query fragmentWithDeferInStream_QueryWithFragmentWithStreamQuery($id: ID!) { fragment fragmentWithDeferInStream_FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { ...fragmentWithDeferInStream_ActorFragment @defer } } diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.expected b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.expected index d7acc2f7df295..4aeb394908b4a 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.expected +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.expected @@ -8,7 +8,7 @@ query fragmentWithStream_QueryWithFragmentWithStreamQuery($id: ID!) { fragment fragmentWithStream_FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { name } } @@ -175,7 +175,7 @@ query fragmentWithStream_QueryWithFragmentWithStreamQuery( fragment fragmentWithStream_FeedbackFragment on Feedback { id - actors @stream(label: "fragmentWithStream_FeedbackFragment$stream$StreamedActorsLabel", initial_count: 1) { + actors @stream(label: "fragmentWithStream_FeedbackFragment$stream$StreamedActorsLabel", initialCount: 1) { __typename name id diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.graphql b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.graphql index e60f16cdf1a39..c9020d678df83 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.graphql +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/fragment-with-stream.graphql @@ -7,7 +7,7 @@ query fragmentWithStream_QueryWithFragmentWithStreamQuery($id: ID!) { fragment fragmentWithStream_FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { name } } diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.expected b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.expected index 38fb08d1722f0..2e5da96c81f83 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.expected +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.expected @@ -9,7 +9,7 @@ fragment refetchableFragmentWithConnectionWithStream_PaginationFragment on Node ... on User { name friends(after: $cursor, first: $count) - @stream_connection(key: "PaginationFragment_friends", initial_count: 1) { + @stream_connection(key: "PaginationFragment_friends", initialCount: 1) { edges { node { id @@ -307,7 +307,7 @@ fragment refetchableFragmentWithConnectionWithStream_PaginationFragment_1G22uz o ... on User { name friends(after: $cursor, first: $count) { - edges @stream(label: "refetchableFragmentWithConnectionWithStream_PaginationFragment$stream$PaginationFragment_friends", initial_count: 1) { + edges @stream(label: "refetchableFragmentWithConnectionWithStream_PaginationFragment$stream$PaginationFragment_friends", initialCount: 1) { node { id __typename diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.graphql b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.graphql index a46be98ae3ff9..bc89a07f01a2b 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.graphql +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/refetchable-fragment-with-connection-with-stream.graphql @@ -8,7 +8,7 @@ fragment refetchableFragmentWithConnectionWithStream_PaginationFragment on Node ... on User { name friends(after: $cursor, first: $count) - @stream_connection(key: "PaginationFragment_friends", initial_count: 1) { + @stream_connection(key: "PaginationFragment_friends", initialCount: 1) { edges { node { id diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.expected b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.expected index 56d00cea90d32..1ddf629ce9a0a 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.expected +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.expected @@ -5,9 +5,9 @@ query streamConnectionConditionalQuery($id: ID!, $cond: Boolean!) { ... on Story { comments(first: 10) @stream_connection( - use_customized_batch: $cond + useCustomizedBatch: $cond if: $cond - initial_count: 0 + initialCount: 0 key: "NodeQuery_comments" ) { edges { @@ -361,7 +361,7 @@ query streamConnectionConditionalQuery( id ... on Story { comments(first: 10) { - edges @stream(label: "streamConnectionConditionalQuery$stream$NodeQuery_comments", if: $cond, initial_count: 0, use_customized_batch: $cond) { + edges @stream(label: "streamConnectionConditionalQuery$stream$NodeQuery_comments", if: $cond, initialCount: 0, useCustomizedBatch: $cond) { node { __typename id diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.graphql b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.graphql index c73f0bc8e57eb..bf937a7fed149 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.graphql +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection-conditional.graphql @@ -4,9 +4,9 @@ query streamConnectionConditionalQuery($id: ID!, $cond: Boolean!) { ... on Story { comments(first: 10) @stream_connection( - use_customized_batch: $cond + useCustomizedBatch: $cond if: $cond - initial_count: 0 + initialCount: 0 key: "NodeQuery_comments" ) { edges { diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.expected b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.expected index e81367b3f4b7d..1b50d9801a2a3 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.expected +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.expected @@ -4,7 +4,7 @@ query streamConnection_NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { edges { node { actor { @@ -401,7 +401,7 @@ query streamConnection_NodeQuery( id ... on Story { comments(first: 10) { - edges @stream(label: "streamConnection_NodeQuery$stream$NodeQuery_comments", initial_count: 0) { + edges @stream(label: "streamConnection_NodeQuery$stream$NodeQuery_comments", initialCount: 0) { node { actor { __typename diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.graphql b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.graphql index f572f9abf5957..73bd62e0133ea 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.graphql +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/stream-connection.graphql @@ -3,7 +3,7 @@ query streamConnection_NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/mod.rs b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/mod.rs index 758b7c8172e1a..0e27031744f31 100644 --- a/compiler/crates/relay-compiler/tests/compile_relay_artifacts/mod.rs +++ b/compiler/crates/relay-compiler/tests/compile_relay_artifacts/mod.rs @@ -15,7 +15,9 @@ use interner::Intern; use relay_codegen::{build_request_params, print_fragment, print_operation, print_request}; use relay_compiler::{apply_transforms, validate}; use relay_test_schema::{get_test_schema, get_test_schema_with_extensions}; -use relay_transforms::{ConnectionInterface, FeatureFlags, DIRECTIVE_SPLIT_OPERATION}; +use relay_transforms::{ + ConnectionInterface, DeferStreamInterface, FeatureFlags, DIRECTIVE_SPLIT_OPERATION, +}; use std::sync::Arc; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { @@ -42,6 +44,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let program = Program::from_definitions(Arc::clone(&schema), ir); let connection_interface = ConnectionInterface::default(); + let defer_stream_interface = DeferStreamInterface::default(); validate(&program, &connection_interface) .map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?; @@ -57,6 +60,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { Arc::new(program), Default::default(), &connection_interface, + &defer_stream_interface, Arc::new(feature_flags), Arc::new(ConsoleLogger), ) @@ -73,7 +77,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { .named(*DIRECTIVE_SPLIT_OPERATION) .is_some() { - print_operation(&schema, operation) + print_operation(&schema, operation, &defer_stream_interface) } else { let name = operation.name.item; let print_operation_node = programs @@ -97,7 +101,13 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let request_parameters = build_request_params(&operation); format!( "{}\n\nQUERY:\n\n{}", - print_request(&schema, operation, &operation_fragment, request_parameters,), + print_request( + &schema, + operation, + &operation_fragment, + request_parameters, + &defer_stream_interface + ), text ) } @@ -108,7 +118,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { fragments.sort_by(|a, b| a.name.item.lookup().cmp(&b.name.item.lookup())); fragments .into_iter() - .map(|fragment| print_fragment(&schema, fragment)) + .map(|fragment| print_fragment(&schema, fragment, &defer_stream_interface)) }) .collect::>(); Ok(result.join("\n\n")) diff --git a/compiler/crates/relay-schema/src/relay-extensions.graphql b/compiler/crates/relay-schema/src/relay-extensions.graphql index 9f06dc8e77b2c..358c1f3741ca2 100644 --- a/compiler/crates/relay-schema/src/relay-extensions.graphql +++ b/compiler/crates/relay-schema/src/relay-extensions.graphql @@ -48,9 +48,9 @@ directive @stream_connection( filters: [String] handler: String label: String - initial_count: Int! + initialCount: Int! if: Boolean = true - use_customized_batch: Boolean = false + useCustomizedBatch: Boolean = false dynamicKey_UNSTABLE: String ) on FIELD diff --git a/compiler/crates/relay-test-schema/src/testschema.graphql b/compiler/crates/relay-test-schema/src/testschema.graphql index 565a86e1897e0..d60ccd7a08ebf 100644 --- a/compiler/crates/relay-test-schema/src/testschema.graphql +++ b/compiler/crates/relay-test-schema/src/testschema.graphql @@ -19,9 +19,9 @@ directive @defer( directive @stream( label: String! - initial_count: Int! + initialCount: Int! if: Boolean = true - use_customized_batch: Boolean = false + useCustomizedBatch: Boolean = false ) on FIELD directive @fetchable(field_name: String!) on OBJECT diff --git a/compiler/crates/relay-transforms/src/defer_stream/defer_stream_interface.rs b/compiler/crates/relay-transforms/src/defer_stream/defer_stream_interface.rs new file mode 100644 index 0000000000000..bc44e4ad47f45 --- /dev/null +++ b/compiler/crates/relay-transforms/src/defer_stream/defer_stream_interface.rs @@ -0,0 +1,35 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +use interner::{Intern, StringKey}; + +use serde::Deserialize; + +/// Configuration where Relay should expect some fields in the schema. +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] +pub struct DeferStreamInterface { + pub defer_name: StringKey, + pub stream_name: StringKey, + pub if_arg: StringKey, + pub label_arg: StringKey, + pub initial_count_arg: StringKey, + pub use_customized_batch_arg: StringKey, +} + +impl Default for DeferStreamInterface { + fn default() -> Self { + DeferStreamInterface { + defer_name: "defer".intern(), + stream_name: "stream".intern(), + if_arg: "if".intern(), + label_arg: "label".intern(), + initial_count_arg: "initialCount".intern(), + use_customized_batch_arg: "useCustomizedBatch".intern(), + } + } +} diff --git a/compiler/crates/relay-transforms/src/defer_stream/directives.rs b/compiler/crates/relay-transforms/src/defer_stream/directives.rs index 949390a259ab5..6b42beacca35d 100644 --- a/compiler/crates/relay-transforms/src/defer_stream/directives.rs +++ b/compiler/crates/relay-transforms/src/defer_stream/directives.rs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -use super::DEFER_STREAM_CONSTANTS; +use crate::defer_stream::DeferStreamInterface; use graphql_ir::{Argument, Directive}; /// Utility to access the arguments of the @defer directive. @@ -18,13 +18,13 @@ impl<'a> DeferDirective<'a> { /// Extracts the arguments from the given directive assumed to be a @defer /// directive. /// Panics on any unexpected arguments. - pub fn from(directive: &'a Directive) -> Self { + pub fn from(directive: &'a Directive, defer_stream_interface: &DeferStreamInterface) -> Self { let mut if_arg = None; let mut label_arg = None; for arg in &directive.arguments { - if arg.name.item == DEFER_STREAM_CONSTANTS.if_arg { + if arg.name.item == defer_stream_interface.if_arg { if_arg = Some(arg); - } else if arg.name.item == DEFER_STREAM_CONSTANTS.label_arg { + } else if arg.name.item == defer_stream_interface.label_arg { label_arg = Some(arg); } else { panic!("Unexpected argument to @defer: {}", arg.name.item); @@ -46,19 +46,19 @@ impl<'a> StreamDirective<'a> { /// Extracts the arguments from the given directive assumed to be a @stream /// directive. /// Panics on any unexpected arguments. - pub fn from(directive: &'a Directive) -> Self { + pub fn from(directive: &'a Directive, defer_stream_interface: &DeferStreamInterface) -> Self { let mut if_arg = None; let mut label_arg = None; let mut initial_count_arg = None; let mut use_customized_batch_arg = None; for arg in &directive.arguments { - if arg.name.item == DEFER_STREAM_CONSTANTS.if_arg { + if arg.name.item == defer_stream_interface.if_arg { if_arg = Some(arg); - } else if arg.name.item == DEFER_STREAM_CONSTANTS.label_arg { + } else if arg.name.item == defer_stream_interface.label_arg { label_arg = Some(arg); - } else if arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg { + } else if arg.name.item == defer_stream_interface.initial_count_arg { initial_count_arg = Some(arg); - } else if arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg { + } else if arg.name.item == defer_stream_interface.use_customized_batch_arg { use_customized_batch_arg = Some(arg); } else { panic!("Unexpected argument to @stream: {}", arg.name.item); diff --git a/compiler/crates/relay-transforms/src/defer_stream/mod.rs b/compiler/crates/relay-transforms/src/defer_stream/mod.rs index 5c24915cf557e..5a67cfb4fc9ea 100644 --- a/compiler/crates/relay-transforms/src/defer_stream/mod.rs +++ b/compiler/crates/relay-transforms/src/defer_stream/mod.rs @@ -5,11 +5,13 @@ * LICENSE file in the root directory of this source tree. */ +mod defer_stream_interface; mod directives; use super::get_applied_fragment_name; use crate::util::{remove_directive, replace_directive}; use common::{Diagnostic, DiagnosticsResult, NamedItem, WithLocation}; +pub use defer_stream_interface::DeferStreamInterface; pub use directives::{DeferDirective, StreamDirective}; use graphql_ir::{ Argument, ConstantValue, Directive, FragmentDefinition, FragmentSpread, InlineFragment, @@ -17,41 +19,18 @@ use graphql_ir::{ ValidationMessage, Value, }; use interner::{Intern, StringKey}; -use lazy_static::lazy_static; use std::{collections::HashMap, sync::Arc}; -pub struct DeferStreamConstants { - pub defer_name: StringKey, - pub stream_name: StringKey, - pub if_arg: StringKey, - pub label_arg: StringKey, - pub initial_count_arg: StringKey, - pub use_customized_batch_arg: StringKey, -} - -impl Default for DeferStreamConstants { - fn default() -> Self { - Self { - defer_name: "defer".intern(), - stream_name: "stream".intern(), - if_arg: "if".intern(), - label_arg: "label".intern(), - initial_count_arg: "initial_count".intern(), - use_customized_batch_arg: "use_customized_batch".intern(), - } - } -} - -lazy_static! { - pub static ref DEFER_STREAM_CONSTANTS: DeferStreamConstants = Default::default(); -} - -pub fn transform_defer_stream(program: &Program) -> DiagnosticsResult { +pub fn transform_defer_stream( + program: &Program, + defer_stream_interface: &DeferStreamInterface, +) -> DiagnosticsResult { let mut transformer = DeferStreamTransform { program, current_document_name: None, labels: Default::default(), errors: Default::default(), + defer_stream_interface, }; let next_program = transformer.transform_program(program); @@ -67,6 +46,7 @@ struct DeferStreamTransform<'s> { current_document_name: Option, labels: HashMap, errors: Vec, + defer_stream_interface: &'s DeferStreamInterface, } impl DeferStreamTransform<'_> { @@ -81,7 +61,7 @@ impl DeferStreamTransform<'_> { self.errors.push( Diagnostic::error( ValidationMessage::LabelNotUniqueForDeferStream { - directive_name: DEFER_STREAM_CONSTANTS.defer_name, + directive_name: self.defer_stream_interface.defer_name, }, prev.name.location, ) @@ -99,7 +79,8 @@ impl DeferStreamTransform<'_> { spread: &FragmentSpread, defer: &Directive, ) -> Result, Diagnostic> { - let DeferDirective { if_arg, label_arg } = DeferDirective::from(defer); + let DeferDirective { if_arg, label_arg } = + DeferDirective::from(defer, self.defer_stream_interface); if is_literal_false_arg(if_arg) { return Ok(Transformed::Replace(Selection::FragmentSpread(Arc::new( @@ -116,14 +97,14 @@ impl DeferStreamTransform<'_> { let transformed_label = transform_label( self.current_document_name .expect("We expect the parent name to be defined here."), - DEFER_STREAM_CONSTANTS.defer_name, + self.defer_stream_interface.defer_name, label, ); self.record_label(transformed_label, defer); let next_label_value = Value::Constant(ConstantValue::String(transformed_label)); let next_label_arg = Argument { name: WithLocation { - item: DEFER_STREAM_CONSTANTS.label_arg, + item: self.defer_stream_interface.label_arg, location: label_arg.map_or(defer.name.location, |arg| arg.name.location), }, value: WithLocation { @@ -165,7 +146,7 @@ impl DeferStreamTransform<'_> { label_arg, initial_count_arg, use_customized_batch_arg, - } = StreamDirective::from(stream); + } = StreamDirective::from(stream, self.defer_stream_interface); let transformed_linked_field = self.default_transform_linked_field(linked_field); let get_next_selection = |directives| match transformed_linked_field { @@ -205,14 +186,14 @@ impl DeferStreamTransform<'_> { let transformed_label = transform_label( self.current_document_name .expect("We expect the parent name to be defined here."), - DEFER_STREAM_CONSTANTS.stream_name, + self.defer_stream_interface.stream_name, label, ); self.record_label(transformed_label, stream); let next_label_value = Value::Constant(ConstantValue::String(transformed_label)); let next_label_arg = Argument { name: WithLocation { - item: DEFER_STREAM_CONSTANTS.label_arg, + item: self.defer_stream_interface.label_arg, location: label_arg.map_or(stream.name.location, |arg| arg.name.location), }, value: WithLocation { @@ -273,10 +254,13 @@ impl<'s> Transformer for DeferStreamTransform<'s> { ) -> Transformed { let defer_directive = inline_fragment .directives - .named(DEFER_STREAM_CONSTANTS.defer_name); + .named(self.defer_stream_interface.defer_name); if let Some(directive) = defer_directive { // Special case for @defer generated by transform_connection - if let Some(label) = directive.arguments.named(DEFER_STREAM_CONSTANTS.label_arg) { + if let Some(label) = directive + .arguments + .named(self.defer_stream_interface.label_arg) + { if let Some(label) = label.value.item.get_string_literal() { if label.lookup().contains("$defer$") { return self.default_transform_inline_fragment(inline_fragment); @@ -294,7 +278,9 @@ impl<'s> Transformer for DeferStreamTransform<'s> { /// Transform of fragment spread with @defer is delegated to `transform_defer`. fn transform_fragment_spread(&mut self, spread: &FragmentSpread) -> Transformed { - let defer_directive = spread.directives.named(DEFER_STREAM_CONSTANTS.defer_name); + let defer_directive = spread + .directives + .named(self.defer_stream_interface.defer_name); if let Some(defer) = defer_directive { match self.transform_defer(spread, defer) { Ok(transformed) => transformed, @@ -312,7 +298,7 @@ impl<'s> Transformer for DeferStreamTransform<'s> { fn transform_scalar_field(&mut self, scalar_field: &ScalarField) -> Transformed { let stream_directive = &scalar_field .directives - .named(DEFER_STREAM_CONSTANTS.stream_name); + .named(self.defer_stream_interface.stream_name); if let Some(directive) = stream_directive { self.errors.push(Diagnostic::error( ValidationMessage::InvalidStreamOnScalarField { @@ -328,7 +314,7 @@ impl<'s> Transformer for DeferStreamTransform<'s> { fn transform_linked_field(&mut self, linked_field: &LinkedField) -> Transformed { let stream_directive = linked_field .directives - .named(DEFER_STREAM_CONSTANTS.stream_name); + .named(self.defer_stream_interface.stream_name); if let Some(stream) = stream_directive { match self.transform_stream(linked_field, stream) { Ok(transformed) => transformed, diff --git a/compiler/crates/relay-transforms/src/lib.rs b/compiler/crates/relay-transforms/src/lib.rs index eeac80be0193f..9de67bd957992 100644 --- a/compiler/crates/relay-transforms/src/lib.rs +++ b/compiler/crates/relay-transforms/src/lib.rs @@ -69,7 +69,7 @@ pub use connections::{ pub use declarative_connection::transform_declarative_connection; pub use dedupe_type_discriminator::dedupe_type_discriminator; pub use defer_stream::{ - transform_defer_stream, DeferDirective, StreamDirective, DEFER_STREAM_CONSTANTS, + transform_defer_stream, DeferDirective, DeferStreamInterface, StreamDirective, }; pub use feature_flags::FeatureFlags; pub use flatten::flatten; diff --git a/compiler/crates/relay-transforms/src/match_/match_transform.rs b/compiler/crates/relay-transforms/src/match_/match_transform.rs index ec6174c240f84..8b6dc80118acc 100644 --- a/compiler/crates/relay-transforms/src/match_/match_transform.rs +++ b/compiler/crates/relay-transforms/src/match_/match_transform.rs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -use crate::defer_stream::DEFER_STREAM_CONSTANTS; +use crate::defer_stream::DeferStreamInterface; use crate::inline_data_fragment::INLINE_DATA_CONSTANTS; use crate::match_::{get_normalization_operation_name, MATCH_CONSTANTS}; use common::{Diagnostic, DiagnosticsResult, Location, NamedItem, WithLocation}; @@ -15,6 +15,7 @@ use graphql_ir::{ LinkedField, OperationDefinition, Program, ScalarField, Selection, Transformed, TransformedValue, Transformer, ValidationMessage, Value, }; + use indexmap::IndexSet; use interner::{Intern, StringKey}; use schema::{FieldID, ScalarID, Type, TypeReference}; @@ -22,8 +23,11 @@ use std::hash::{Hash, Hasher}; use std::sync::Arc; /// Transform and validate @match and @module -pub fn transform_match(program: &Program) -> DiagnosticsResult { - let mut transformer = MatchTransform::new(program); +pub fn transform_match( + program: &Program, + defer_stream_interface: &DeferStreamInterface, +) -> DiagnosticsResult { + let mut transformer = MatchTransform::new(program, defer_stream_interface); let next_program = transformer.transform_program(program); if transformer.errors.is_empty() { Ok(next_program.replace_or_else(|| program.clone())) @@ -66,10 +70,14 @@ pub struct MatchTransform<'program> { errors: Vec, path: Vec, matches_for_path: MatchesForPath, + defer_stream_interface: &'program DeferStreamInterface, } impl<'program> MatchTransform<'program> { - fn new(program: &'program Program) -> Self { + fn new( + program: &'program Program, + defer_stream_interface: &'program DeferStreamInterface, + ) -> Self { Self { program, // Placeholders to make the types non-optional, @@ -79,6 +87,7 @@ impl<'program> MatchTransform<'program> { errors: Vec::new(), path: Default::default(), matches_for_path: Default::default(), + defer_stream_interface, } } @@ -226,7 +235,7 @@ impl<'program> MatchTransform<'program> { if !(spread.directives.len() == 2 && spread .directives - .named(DEFER_STREAM_CONSTANTS.defer_name) + .named(self.defer_stream_interface.defer_name) .is_some()) { // allow @defer and @module in typegen transforms diff --git a/compiler/crates/relay-transforms/src/schema_interface.rs b/compiler/crates/relay-transforms/src/schema_interface.rs new file mode 100644 index 0000000000000..9fbe1696e2a9a --- /dev/null +++ b/compiler/crates/relay-transforms/src/schema_interface.rs @@ -0,0 +1,39 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +use interner::{Intern, StringKey}; + +use serde::Deserialize; + +/// Configuration where Relay should expect some fields in the schema. +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] +pub struct ConnectionInterface { + pub cursor: StringKey, + pub edges: StringKey, + pub end_cursor: StringKey, + pub has_next_page: StringKey, + pub has_previous_page: StringKey, + pub node: StringKey, + pub page_info: StringKey, + pub start_cursor: StringKey, +} + +impl Default for ConnectionInterface { + fn default() -> Self { + ConnectionInterface { + cursor: "cursor".intern(), + edges: "edges".intern(), + end_cursor: "endCursor".intern(), + has_next_page: "hasNextPage".intern(), + has_previous_page: "hasPreviousPage".intern(), + node: "node".intern(), + page_info: "pageInfo".intern(), + start_cursor: "startCursor".intern(), + } + } +} diff --git a/compiler/crates/relay-transforms/src/skip_redundant_nodes.rs b/compiler/crates/relay-transforms/src/skip_redundant_nodes.rs index 59659465dbe4e..8c552225648ad 100644 --- a/compiler/crates/relay-transforms/src/skip_redundant_nodes.rs +++ b/compiler/crates/relay-transforms/src/skip_redundant_nodes.rs @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ +use crate::defer_stream::DeferStreamInterface; use crate::node_identifier::NodeIdentifier; use crate::util::{is_relay_custom_inline_fragment_directive, PointerAddress}; -use crate::DEFER_STREAM_CONSTANTS; use common::NamedItem; use dashmap::DashMap; @@ -111,8 +111,11 @@ use std::sync::Arc; * * 1 can be skipped because it is already fetched at the outer level. */ -pub fn skip_redundant_nodes(program: &Program) -> Program { - let transform = SkipRedundantNodesTransform::new(program); +pub fn skip_redundant_nodes( + program: &Program, + defer_stream_interface: &DeferStreamInterface, +) -> Program { + let transform = SkipRedundantNodesTransform::new(program, defer_stream_interface); transform .transform_program(program) .replace_or_else(|| program.clone()) @@ -123,16 +126,18 @@ struct SelectionMap(VecMap>); type Cache = DashMap, SelectionMap)>; -struct SkipRedundantNodesTransform { +struct SkipRedundantNodesTransform<'s> { schema: Arc, cache: Cache, + defer_stream_interface: &'s DeferStreamInterface, } -impl<'s> SkipRedundantNodesTransform { - fn new(program: &'_ Program) -> Self { +impl<'s> SkipRedundantNodesTransform<'s> { + fn new(program: &'_ Program, defer_stream_interface: &'s DeferStreamInterface) -> Self { Self { schema: Arc::clone(&program.schema), cache: DashMap::new(), + defer_stream_interface, } } @@ -331,7 +336,7 @@ impl<'s> SkipRedundantNodesTransform { } let mut result: Vec = Vec::new(); let mut has_changes = false; - let selections = get_partitioned_selections(selections); + let selections = get_partitioned_selections(selections, self.defer_stream_interface); for (index, prev_item) in selections.iter().enumerate() { let next_item = self.transform_selection(prev_item, selection_map); @@ -429,18 +434,19 @@ impl<'s> SkipRedundantNodesTransform { * guaranteed to be fetched are encountered prior to any duplicates that may be * fetched within a conditional. */ -fn get_partitioned_selections(selections: &[Selection]) -> Vec<&Selection> { +fn get_partitioned_selections<'a>( + selections: &'a [Selection], + defer_stream_interface: &DeferStreamInterface, +) -> Vec<&'a Selection> { let mut result = Vec::with_capacity(selections.len()); - unsafe { - result.set_len(selections.len()) - }; + unsafe { result.set_len(selections.len()) }; let mut non_field_index = selections .iter() - .filter(|sel| is_selection_linked_or_scalar(sel)) + .filter(|sel| is_selection_linked_or_scalar(sel, defer_stream_interface)) .count(); let mut field_index = 0; for sel in selections.iter() { - if is_selection_linked_or_scalar(sel) { + if is_selection_linked_or_scalar(sel, defer_stream_interface) { result[field_index] = sel; field_index += 1; } else { @@ -451,11 +457,14 @@ fn get_partitioned_selections(selections: &[Selection]) -> Vec<&Selection> { result } -fn is_selection_linked_or_scalar(selection: &Selection) -> bool { +fn is_selection_linked_or_scalar( + selection: &Selection, + defer_stream_interface: &DeferStreamInterface, +) -> bool { match selection { Selection::LinkedField(field) => field .directives - .named(DEFER_STREAM_CONSTANTS.stream_name) + .named(defer_stream_interface.stream_name) .is_none(), Selection::ScalarField(_) => true, _ => false, diff --git a/compiler/crates/relay-transforms/src/transform_connections.rs b/compiler/crates/relay-transforms/src/transform_connections.rs index 9c288048ea1b2..e018be226664b 100644 --- a/compiler/crates/relay-transforms/src/transform_connections.rs +++ b/compiler/crates/relay-transforms/src/transform_connections.rs @@ -11,7 +11,7 @@ use crate::connections::{ extract_connection_directive, get_default_filters, ConnectionConstants, ConnectionInterface, ConnectionMetadata, }; -use crate::defer_stream::DEFER_STREAM_CONSTANTS; +use crate::defer_stream::DeferStreamInterface; use crate::handle_fields::{build_handle_field_directive_from_connection_directive, KEY_ARG_NAME}; use common::{NamedItem, WithLocation}; use graphql_ir::{ @@ -24,8 +24,10 @@ use std::sync::Arc; pub fn transform_connections( program: &Program, connection_interface: &ConnectionInterface, + defer_stream_interface: &DeferStreamInterface, ) -> Program { - let mut transform = ConnectionTransform::new(program, connection_interface); + let mut transform = + ConnectionTransform::new(program, connection_interface, defer_stream_interface); transform .transform_program(program) .replace_or_else(|| program.clone()) @@ -33,6 +35,7 @@ pub fn transform_connections( struct ConnectionTransform<'s> { connection_interface: &'s ConnectionInterface, + defer_stream_interface: &'s DeferStreamInterface, connection_constants: ConnectionConstants, current_path: Option>, current_connection_metadata: Vec, @@ -41,10 +44,15 @@ struct ConnectionTransform<'s> { } impl<'s> ConnectionTransform<'s> { - fn new(program: &'s Program, connection_interface: &'s ConnectionInterface) -> Self { + fn new( + program: &'s Program, + connection_interface: &'s ConnectionInterface, + defer_stream_interface: &'s DeferStreamInterface, + ) -> Self { Self { connection_constants: ConnectionConstants::default(), connection_interface, + defer_stream_interface, current_path: None, current_document_name: connection_interface.cursor, // Set an arbitrary value to avoid Option current_connection_metadata: Vec::new(), @@ -112,16 +120,16 @@ impl<'s> ConnectionTransform<'s> { if is_stream_connection { let mut arguments = vec![]; for arg in &connection_directive.arguments { - if arg.name.item == DEFER_STREAM_CONSTANTS.if_arg - || arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg - || arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg + if arg.name.item == self.defer_stream_interface.if_arg + || arg.name.item == self.defer_stream_interface.initial_count_arg + || arg.name.item == self.defer_stream_interface.use_customized_batch_arg { arguments.push(arg.clone()); } else if arg.name.item == *KEY_ARG_NAME { arguments.push(Argument { name: WithLocation::new( arg.name.location, - DEFER_STREAM_CONSTANTS.label_arg, + self.defer_stream_interface.label_arg, ), value: arg.value.clone(), }); @@ -130,7 +138,7 @@ impl<'s> ConnectionTransform<'s> { transformed_edges_field.directives.push(Directive { name: WithLocation::new( connection_directive.name.location, - DEFER_STREAM_CONSTANTS.stream_name, + self.defer_stream_interface.stream_name, ), arguments, }); @@ -197,7 +205,7 @@ impl<'s> ConnectionTransform<'s> { arguments.push(Argument { name: WithLocation::new( key_arg.name.location, - DEFER_STREAM_CONSTANTS.label_arg, + self.defer_stream_interface.label_arg, ), value: WithLocation::new( key_arg.value.location, @@ -213,7 +221,7 @@ impl<'s> ConnectionTransform<'s> { ), }); } - if let Some(if_arg) = connection_args.named(DEFER_STREAM_CONSTANTS.if_arg) { + if let Some(if_arg) = connection_args.named(self.defer_stream_interface.if_arg) { arguments.push(if_arg.clone()); } Selection::InlineFragment(Arc::new(InlineFragment { @@ -224,7 +232,7 @@ impl<'s> ConnectionTransform<'s> { directives: vec![Directive { name: WithLocation::new( connection_directive.name.location, - DEFER_STREAM_CONSTANTS.defer_name, + self.defer_stream_interface.defer_name, ), arguments, }], diff --git a/compiler/crates/relay-transforms/src/unwrap_custom_directive_selection.rs b/compiler/crates/relay-transforms/src/unwrap_custom_directive_selection.rs index 8b448415d9cad..af1510a2930ff 100644 --- a/compiler/crates/relay-transforms/src/unwrap_custom_directive_selection.rs +++ b/compiler/crates/relay-transforms/src/unwrap_custom_directive_selection.rs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -use crate::DEFER_STREAM_CONSTANTS; +use crate::defer_stream::DeferStreamInterface; use common::NamedItem; use graphql_ir::Selection; use graphql_ir::{FragmentSpread, InlineFragment, Program, Transformed, Transformer}; @@ -14,16 +14,29 @@ use std::sync::Arc; /// Transform to unwrap selections wrapped in a InlineFragment with custom /// directive for printing -pub fn unwrap_custom_directive_selection(program: &Program) -> Program { - let mut transform = UnwrapCustomDirectiveSelection; +pub fn unwrap_custom_directive_selection( + program: &Program, + defer_stream_interface: &DeferStreamInterface, +) -> Program { + let mut transform = UnwrapCustomDirectiveSelection::new(defer_stream_interface); transform .transform_program(program) .replace_or_else(|| program.clone()) } -struct UnwrapCustomDirectiveSelection; +struct UnwrapCustomDirectiveSelection<'s> { + defer_stream_interface: &'s DeferStreamInterface, +} + +impl<'s> UnwrapCustomDirectiveSelection<'s> { + fn new(defer_stream_interface: &'s DeferStreamInterface) -> Self { + Self { + defer_stream_interface, + } + } +} -impl Transformer for UnwrapCustomDirectiveSelection { +impl Transformer for UnwrapCustomDirectiveSelection<'_> { const NAME: &'static str = "UnwrapCustomDirectiveSelection"; const VISIT_ARGUMENTS: bool = false; const VISIT_DIRECTIVES: bool = false; @@ -31,7 +44,9 @@ impl Transformer for UnwrapCustomDirectiveSelection { fn transform_inline_fragment(&mut self, fragment: &InlineFragment) -> Transformed { if fragment.type_condition.is_none() { // Remove the wrapping `... @defer` for `@defer` on fragment spreads. - let defer = fragment.directives.named(DEFER_STREAM_CONSTANTS.defer_name); + let defer = fragment + .directives + .named(self.defer_stream_interface.defer_name); if let Some(defer) = defer { if let Selection::FragmentSpread(frag_spread) = &fragment.selections[0] { return Transformed::Replace(Selection::FragmentSpread(Arc::new( diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected index 4b424a088dd26..0061be156e355 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.expected @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1) { + actors @stream(initialCount: 1) { name } } @@ -24,7 +24,7 @@ query QueryWithFragmentWithStream( fragment FeedbackFragment on Feedback { id - actors @stream(label: "FeedbackFragment$stream$actors", initial_count: 1) { + actors @stream(label: "FeedbackFragment$stream$actors", initialCount: 1) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql index 23fa23b3e8e43..739db7de64c6a 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-default-label.graphql @@ -7,7 +7,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1) { + actors @stream(initialCount: 1) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.expected index 1253c531bc1d2..b76da812ca31d 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.expected @@ -9,10 +9,10 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "actors") { + actors @stream(initialCount: 1, label: "actors") { name } - otherActors: actors @stream(initial_count: 1, label: "actors") { + otherActors: actors @stream(initialCount: 1, label: "actors") { # invalid: duplicate label name } @@ -22,7 +22,7 @@ fragment FeedbackFragment on Feedback { fragment-with-stream-duplicate-label.invalid.graphql:11:11 10 │ id - 11 │ actors @stream(initial_count: 1, label: "actors") { + 11 │ actors @stream(initialCount: 1, label: "actors") { │ ^^^^^^ 12 │ name @@ -30,6 +30,6 @@ fragment FeedbackFragment on Feedback { fragment-with-stream-duplicate-label.invalid.graphql:14:24 13 │ } - 14 │ otherActors: actors @stream(initial_count: 1, label: "actors") { + 14 │ otherActors: actors @stream(initialCount: 1, label: "actors") { │ ^^^^^^ 15 │ # invalid: duplicate label diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.graphql index 6f0d3488b2cb9..a05f524d1de46 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-duplicate-label.invalid.graphql @@ -8,10 +8,10 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "actors") { + actors @stream(initialCount: 1, label: "actors") { name } - otherActors: actors @stream(initial_count: 1, label: "actors") { + otherActors: actors @stream(initialCount: 1, label: "actors") { # invalid: duplicate label name } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.expected index 07a4e1cfba531..d3db2ff831380 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.expected @@ -9,7 +9,7 @@ query QueryWithFragmentWithStream($id: ID!, $enableStream: Boolean) { fragment FeedbackFragment on Feedback { id actors - @stream(initial_count: 1, label: "StreamedActorsLabel", if: $enableStream) { + @stream(initialCount: 1, label: "StreamedActorsLabel", if: $enableStream) { name } } @@ -26,7 +26,7 @@ query QueryWithFragmentWithStream( fragment FeedbackFragment on Feedback { id - actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", if: $enableStream, initial_count: 1) { + actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", if: $enableStream, initialCount: 1) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.graphql index 20ae2c07f0bcf..266ebda30663d 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-if-arg.graphql @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!, $enableStream: Boolean) { fragment FeedbackFragment on Feedback { id actors - @stream(initial_count: 1, label: "StreamedActorsLabel", if: $enableStream) { + @stream(initialCount: 1, label: "StreamedActorsLabel", if: $enableStream) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.expected index 4c128c9f3f139..1f8aade373550 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.expected @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: $initialCount, label: "StreamedActorsLabel") { + actors @stream(initialCount: $initialCount, label: "StreamedActorsLabel") { name } } @@ -25,7 +25,7 @@ query QueryWithFragmentWithStream( fragment FeedbackFragment on Feedback { id - actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initial_count: $initialCount) { + actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initialCount: $initialCount) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.graphql index 9e689d6875cb5..338a8274a7ed7 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-initial-count-arg.graphql @@ -7,7 +7,7 @@ query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: $initialCount, label: "StreamedActorsLabel") { + actors @stream(initialCount: $initialCount, label: "StreamedActorsLabel") { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.expected index e8b5acc305d89..58d629b758765 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.expected @@ -10,15 +10,15 @@ query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) { fragment FeedbackFragment on Feedback { id actors @stream(label: "StreamedActorsLabel") { - # invalid: missing initial_count + # invalid: missing initialCount name } } ==================================== ERROR ==================================== -✖︎ Missing required argument: `initial_count` +✖︎ Missing required argument: `initialCount` fragment-with-stream-missing-initial-count-arg.invalid.graphql:11:11 10 │ id 11 │ actors @stream(label: "StreamedActorsLabel") { │ ^^^^^^ - 12 │ # invalid: missing initial_count + 12 │ # invalid: missing initialCount diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.graphql index c21bf7d7967ff..205c6284cd71c 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.graphql @@ -9,7 +9,7 @@ query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) { fragment FeedbackFragment on Feedback { id actors @stream(label: "StreamedActorsLabel") { - # invalid: missing initial_count + # invalid: missing initialCount name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.expected index de1752b3933ae..486d84012eff9 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.expected @@ -9,13 +9,13 @@ query QueryWithFragmentWithStream($id: ID!, $label: String!) { fragment UserFragment on User { id - name @stream(initial_count: 1, label: $label) + name @stream(initialCount: 1, label: $label) } ==================================== ERROR ==================================== ✖︎ Invalid use of @stream on scalar field 'name' fragment-with-stream-on-scalar-field.invalid.graphql:11:9 10 │ id - 11 │ name @stream(initial_count: 1, label: $label) + 11 │ name @stream(initialCount: 1, label: $label) │ ^^^^^^ 12 │ } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.graphql index 5ee3aa3cc33fc..907553dc9f516 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-on-scalar-field.invalid.graphql @@ -8,5 +8,5 @@ query QueryWithFragmentWithStream($id: ID!, $label: String!) { fragment UserFragment on User { id - name @stream(initial_count: 1, label: $label) + name @stream(initialCount: 1, label: $label) } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.expected index fdcdc1f94f927..18a1d123489f1 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.expected @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel", if: false) { + actors @stream(initialCount: 1, label: "StreamedActorsLabel", if: false) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.graphql index cc529d908f6db..9fb1e0e3212d6 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-statically-disabled.graphql @@ -7,7 +7,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel", if: false) { + actors @stream(initialCount: 1, label: "StreamedActorsLabel", if: false) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.expected index e63411c2c5e3f..f7e18f6a86691 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.expected @@ -11,9 +11,9 @@ fragment FeedbackFragment on Feedback { actors @stream( if: true - initial_count: 1 + initialCount: 1 label: "StreamedActorsLabel" - use_customized_batch: $useCustomizedBatch + useCustomizedBatch: $useCustomizedBatch ) { name } @@ -31,7 +31,7 @@ query QueryWithFragmentWithStream( fragment FeedbackFragment on Feedback { id - actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", if: true, initial_count: 1, use_customized_batch: $useCustomizedBatch) { + actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", if: true, initialCount: 1, useCustomizedBatch: $useCustomizedBatch) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.graphql index 5c0f7c15b697e..b252e2ba8dfbe 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-use_customized_batch-arg.graphql @@ -10,9 +10,9 @@ fragment FeedbackFragment on Feedback { actors @stream( if: true - initial_count: 1 + initialCount: 1 label: "StreamedActorsLabel" - use_customized_batch: $useCustomizedBatch + useCustomizedBatch: $useCustomizedBatch ) { name } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.expected index 13fcab383a079..044529f738f7c 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.expected @@ -9,7 +9,7 @@ query QueryWithFragmentWithStream($id: ID!, $label: String!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: $label) { + actors @stream(initialCount: 1, label: $label) { name } } @@ -18,6 +18,6 @@ fragment FeedbackFragment on Feedback { fragment-with-stream-variable-label.invalid.graphql:11:11 10 │ id - 11 │ actors @stream(initial_count: 1, label: $label) { + 11 │ actors @stream(initialCount: 1, label: $label) { │ ^^^^^^ 12 │ name diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.graphql index 0877996f4bd7b..9d6f748019d5d 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream-variable-label.invalid.graphql @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!, $label: String!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: $label) { + actors @stream(initialCount: 1, label: $label) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.expected index 61c9e8b532e49..2c4055bc32bc2 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.expected @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { name } } @@ -24,7 +24,7 @@ query QueryWithFragmentWithStream( fragment FeedbackFragment on Feedback { id - actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initial_count: 1) { + actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initialCount: 1) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.graphql index 8891fba1b9c8d..ceb87c5700edc 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/fragment-with-stream.graphql @@ -7,7 +7,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.expected b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.expected index 94b95aa77dd22..99d8ff40f48c6 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.expected +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.expected @@ -2,7 +2,7 @@ query QueryWithStream($id: ID!) { node(id: $id) { ... on Feedback { - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { name } } @@ -14,7 +14,7 @@ query QueryWithStream( ) { node(id: $id) { ... on Feedback { - actors @stream(label: "QueryWithStream$stream$StreamedActorsLabel", initial_count: 1) { + actors @stream(label: "QueryWithStream$stream$StreamedActorsLabel", initialCount: 1) { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.graphql b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.graphql index 2b7d7173527d1..cb244a79f1267 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.graphql +++ b/compiler/crates/relay-transforms/tests/defer_stream/fixtures/query-with-stream.graphql @@ -1,7 +1,7 @@ query QueryWithStream($id: ID!) { node(id: $id) { ... on Feedback { - actors @stream(initial_count: 1, label: "StreamedActorsLabel") { + actors @stream(initialCount: 1, label: "StreamedActorsLabel") { name } } diff --git a/compiler/crates/relay-transforms/tests/defer_stream/mod.rs b/compiler/crates/relay-transforms/tests/defer_stream/mod.rs index a1467ecb5059f..e178dfef0b0c1 100644 --- a/compiler/crates/relay-transforms/tests/defer_stream/mod.rs +++ b/compiler/crates/relay-transforms/tests/defer_stream/mod.rs @@ -7,12 +7,15 @@ use fixture_tests::Fixture; use graphql_test_helpers::apply_transform_for_test; -use relay_transforms::{transform_defer_stream, unwrap_custom_directive_selection}; +use relay_transforms::{ + transform_defer_stream, unwrap_custom_directive_selection, DeferStreamInterface, +}; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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) }) } diff --git a/compiler/crates/relay-transforms/tests/generate_data_driven_dependency_metadata/mod.rs b/compiler/crates/relay-transforms/tests/generate_data_driven_dependency_metadata/mod.rs index f32ac9972b1e5..0227f47ad3dfa 100644 --- a/compiler/crates/relay-transforms/tests/generate_data_driven_dependency_metadata/mod.rs +++ b/compiler/crates/relay-transforms/tests/generate_data_driven_dependency_metadata/mod.rs @@ -7,11 +7,13 @@ use fixture_tests::Fixture; use graphql_test_helpers::apply_transform_for_test; -use relay_transforms::{generate_data_driven_dependency_metadata, transform_match}; +use relay_transforms::{ + generate_data_driven_dependency_metadata, transform_match, DeferStreamInterface, +}; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { apply_transform_for_test(fixture, |program| { - let program = transform_match(program)?; + let program = transform_match(program, &DeferStreamInterface::default())?; let program = generate_data_driven_dependency_metadata(&program); Ok(program) }) diff --git a/compiler/crates/relay-transforms/tests/match_transform/mod.rs b/compiler/crates/relay-transforms/tests/match_transform/mod.rs index 82a8e1750488d..d81ce257a990e 100644 --- a/compiler/crates/relay-transforms/tests/match_transform/mod.rs +++ b/compiler/crates/relay-transforms/tests/match_transform/mod.rs @@ -7,8 +7,10 @@ use fixture_tests::Fixture; use graphql_test_helpers::apply_transform_for_test; -use relay_transforms::transform_match; +use relay_transforms::{transform_match, DeferStreamInterface}; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { - apply_transform_for_test(fixture, transform_match) + apply_transform_for_test(fixture, |program| { + transform_match(program, &DeferStreamInterface::default()) + }) } diff --git a/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.expected b/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.expected index e973086531083..a0663310064e7 100644 --- a/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.expected +++ b/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.expected @@ -9,7 +9,7 @@ fragment PaginationFragment on Node ... on User { name friends(after: $cursor, first: $count) - @stream_connection(key: "PaginationFragment_friends", initial_count: 1) { + @stream_connection(key: "PaginationFragment_friends", initialCount: 1) { edges { node { id @@ -37,7 +37,7 @@ fragment PaginationFragment on Node @refetchable(queryName: "RefetchableFragment ... on User { name friends(after: $cursor, first: $count) @__clientField(key: "PaginationFragment_friends", handle: "connection") { - edges @stream(label: "PaginationFragment_friends", initial_count: 1) { + edges @stream(label: "PaginationFragment_friends", initialCount: 1) { node { id } diff --git a/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.graphql b/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.graphql index e6fc5872ef07d..a4cf016c7d77a 100644 --- a/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.graphql +++ b/compiler/crates/relay-transforms/tests/refetchable_fragment/fixtures/refetchable-fragment-with-connection-with-stream.graphql @@ -8,7 +8,7 @@ fragment PaginationFragment on Node ... on User { name friends(after: $cursor, first: $count) - @stream_connection(key: "PaginationFragment_friends", initial_count: 1) { + @stream_connection(key: "PaginationFragment_friends", initialCount: 1) { edges { node { id diff --git a/compiler/crates/relay-transforms/tests/refetchable_fragment/mod.rs b/compiler/crates/relay-transforms/tests/refetchable_fragment/mod.rs index a22c2224c434b..39c93b412bf62 100644 --- a/compiler/crates/relay-transforms/tests/refetchable_fragment/mod.rs +++ b/compiler/crates/relay-transforms/tests/refetchable_fragment/mod.rs @@ -8,13 +8,18 @@ use fixture_tests::Fixture; use relay_transforms::{ transform_connections, transform_refetchable_fragment, ConnectionInterface, + DeferStreamInterface, }; use graphql_test_helpers::apply_transform_for_test; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { apply_transform_for_test(fixture, |program| { - let program = transform_connections(&program, &ConnectionInterface::default()); + let program = transform_connections( + &program, + &ConnectionInterface::default(), + &DeferStreamInterface::default(), + ); let base_fragments = Default::default(); transform_refetchable_fragment(&program, &base_fragments, false) }) diff --git a/compiler/crates/relay-transforms/tests/skip_redundant_nodes/mod.rs b/compiler/crates/relay-transforms/tests/skip_redundant_nodes/mod.rs index f2033fb5e7bb8..aa6f15fe21117 100644 --- a/compiler/crates/relay-transforms/tests/skip_redundant_nodes/mod.rs +++ b/compiler/crates/relay-transforms/tests/skip_redundant_nodes/mod.rs @@ -11,18 +11,20 @@ use graphql_ir::{build, Program}; use graphql_syntax::parse_executable; use graphql_text_printer::print_operation; use relay_test_schema::{get_test_schema, get_test_schema_with_extensions}; -use relay_transforms::{inline_fragments, skip_redundant_nodes}; +use relay_transforms::{inline_fragments, skip_redundant_nodes, DeferStreamInterface}; use std::sync::Arc; pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let source_location = SourceLocationKey::standalone(fixture.file_name); let parts: Vec<_> = fixture.content.split("%extensions%").collect(); + 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)) @@ -32,7 +34,8 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { 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)) diff --git a/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.expected b/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.expected index 7cbd27d973980..3b954212f932a 100644 --- a/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.expected +++ b/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.expected @@ -54,7 +54,7 @@ query StreamQuerry($RELAY_INCREMENTAL_DELIVERY: Boolean!) { node(id: 4) { id ... on Feedback { - actors @stream(if: $RELAY_INCREMENTAL_DELIVERY, label: "foo", initial_count: 3) { + actors @stream(if: $RELAY_INCREMENTAL_DELIVERY, label: "foo", initialCount: 3) { name } } @@ -78,7 +78,7 @@ query StreamQuerry( node(id: 4) { id ... on Feedback { - actors @stream(if: $RELAY_INCREMENTAL_DELIVERY, label: "foo", initial_count: 3) { + actors @stream(if: $RELAY_INCREMENTAL_DELIVERY, label: "foo", initialCount: 3) { name } } diff --git a/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.graphql b/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.graphql index 16577bd68b6dd..19ad1dec6ad0e 100644 --- a/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.graphql +++ b/compiler/crates/relay-transforms/tests/skip_unused_variables/fixtures/kitchen-sink.graphql @@ -53,7 +53,7 @@ query StreamQuerry($RELAY_INCREMENTAL_DELIVERY: Boolean!) { node(id: 4) { id ... on Feedback { - actors @stream(if: $RELAY_INCREMENTAL_DELIVERY, label: "foo", initial_count: 3) { + actors @stream(if: $RELAY_INCREMENTAL_DELIVERY, label: "foo", initialCount: 3) { name } } diff --git a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.expected b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.expected index d684ace101691..de86e9f0f896e 100644 --- a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.expected +++ b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.expected @@ -4,7 +4,7 @@ query NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { edges { node { actor { @@ -28,7 +28,7 @@ query NodeQuery( id ... on Story { comments(first: 10) @__clientField(key: "NodeQuery_comments", handle: "connection") { - edges @stream(label: "NodeQuery_comments", initial_count: 0) { + edges @stream(label: "NodeQuery_comments", initialCount: 0) { node { actor { name diff --git a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.graphql b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.graphql index e688708be3259..14406dcf91753 100644 --- a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.graphql +++ b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection-no-label.graphql @@ -3,7 +3,7 @@ query NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.expected b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.expected index 84a7d0a91aab8..50580bdea106a 100644 --- a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.expected +++ b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.expected @@ -6,7 +6,7 @@ query NodeQuery($id: ID!) { comments(first: 10) @stream_connection( key: "NodeQuery_comments" - initial_count: 0 + initialCount: 0 label: "comments" ) { edges { @@ -32,7 +32,7 @@ query NodeQuery( id ... on Story { comments(first: 10) @__clientField(key: "NodeQuery_comments", handle: "connection") { - edges @stream(label: "NodeQuery_comments", initial_count: 0) { + edges @stream(label: "NodeQuery_comments", initialCount: 0) { node { actor { name diff --git a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.graphql b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.graphql index 85b2df8960abc..a635f314c224d 100644 --- a/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.graphql +++ b/compiler/crates/relay-transforms/tests/transform_connections/fixtures/stream-connection.graphql @@ -5,7 +5,7 @@ query NodeQuery($id: ID!) { comments(first: 10) @stream_connection( key: "NodeQuery_comments" - initial_count: 0 + initialCount: 0 label: "comments" ) { edges { diff --git a/compiler/crates/relay-transforms/tests/transform_connections/mod.rs b/compiler/crates/relay-transforms/tests/transform_connections/mod.rs index f2b784cae2960..bf11e3c1f7862 100644 --- a/compiler/crates/relay-transforms/tests/transform_connections/mod.rs +++ b/compiler/crates/relay-transforms/tests/transform_connections/mod.rs @@ -12,7 +12,9 @@ use graphql_syntax::parse_executable; use graphql_test_helpers::diagnostics_to_sorted_string; use graphql_text_printer::{print_fragment, print_operation}; 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 { @@ -27,11 +29,13 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { let program = Program::from_definitions(Arc::clone(&schema), ir); let connection_interface = ConnectionInterface::default(); + let defer_stream_interface = DeferStreamInterface::default(); 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, &connection_interface, &defer_stream_interface); let mut printed = next_program .operations() diff --git a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.expected b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.expected index 2568aa2448730..b89be4b64e55f 100644 --- a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.expected +++ b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.expected @@ -5,7 +5,7 @@ query NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { commentEdges: edges { node { actor { @@ -24,7 +24,7 @@ query NodeQuery($id: ID!) { ✖︎ @stream_connection does not support aliasing the 'edges' field. stream-connection-with-aliased-edges.invalid.graphql:8:23 - 7 │ @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + 7 │ @stream_connection(key: "NodeQuery_comments", initialCount: 0) { 8 │ commentEdges: edges { │ ^^^^^ 9 │ node { diff --git a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.graphql b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.graphql index d0aab1efddabc..fd1e797aae68e 100644 --- a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-edges.invalid.graphql @@ -4,7 +4,7 @@ query NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { commentEdges: edges { node { actor { diff --git a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.expected b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.expected index 0e5eb11245c42..e2bc851831b1d 100644 --- a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.expected +++ b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.expected @@ -5,7 +5,7 @@ query NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.graphql b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.graphql index 07452848d1db5..9252ecd1319c7 100644 --- a/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/validate_connections/fixtures/stream-connection-with-aliased-page-info.invalid.graphql @@ -4,7 +4,7 @@ query NodeQuery($id: ID!) { id ... on Story { comments(first: 10) - @stream_connection(key: "NodeQuery_comments", initial_count: 0) { + @stream_connection(key: "NodeQuery_comments", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.expected b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.expected index 3c94a8b14b049..36ae523576c71 100644 --- a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.expected +++ b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.expected @@ -11,7 +11,7 @@ fragment FeedbackFragment on Feedback { id foo { bar { - users @stream(initial_count: 1, label: "StreamedActorsLabel") { + users @stream(initialCount: 1, label: "StreamedActorsLabel") { id name } @@ -36,7 +36,7 @@ type Bar { fragment-with-stream-child-of-client.invalid.graphql:13:14 12 │ bar { - 13 │ users @stream(initial_count: 1, label: "StreamedActorsLabel") { + 13 │ users @stream(initialCount: 1, label: "StreamedActorsLabel") { │ ^^^^^^ 14 │ id diff --git a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.graphql b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.graphql index 49880cbacd8cc..ce5213ab3d448 100644 --- a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-child-of-client.invalid.graphql @@ -10,7 +10,7 @@ fragment FeedbackFragment on Feedback { id foo { bar { - users @stream(initial_count: 1, label: "StreamedActorsLabel") { + users @stream(initialCount: 1, label: "StreamedActorsLabel") { id name } diff --git a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.expected b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.expected index df2840cb97a7b..45c6ca6608707 100644 --- a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.expected +++ b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.expected @@ -9,7 +9,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - foos @stream(initial_count: 1, label: "StreamedActorsLabel") { + foos @stream(initialCount: 1, label: "StreamedActorsLabel") { bar } } @@ -28,7 +28,7 @@ type Foo { fragment-with-stream-on-client.invalid.graphql:11:9 10 │ id - 11 │ foos @stream(initial_count: 1, label: "StreamedActorsLabel") { + 11 │ foos @stream(initialCount: 1, label: "StreamedActorsLabel") { │ ^^^^^^ 12 │ bar @@ -36,6 +36,6 @@ type Foo { fragment-with-stream-on-client.invalid.graphql:11:3 10 │ id - 11 │ foos @stream(initial_count: 1, label: "StreamedActorsLabel") { + 11 │ foos @stream(initialCount: 1, label: "StreamedActorsLabel") { │ ^^^^ 12 │ bar diff --git a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.graphql b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.graphql index 045192ee83bfa..5a45d44cf6645 100644 --- a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/fragment-with-stream-on-client.invalid.graphql @@ -8,7 +8,7 @@ query QueryWithFragmentWithStream($id: ID!) { fragment FeedbackFragment on Feedback { id - foos @stream(initial_count: 1, label: "StreamedActorsLabel") { + foos @stream(initialCount: 1, label: "StreamedActorsLabel") { bar } } diff --git a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.expected b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.expected index f3773ea516caa..c14ab51e20a1e 100644 --- a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.expected +++ b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.expected @@ -7,7 +7,7 @@ query NodeQuery($id: ID!) { clientComments(first: 10) @stream_connection( key: "NodeQuery_clientComments" - initial_count: 0 + initialCount: 0 label: "comments" ) { edges { diff --git a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.graphql b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.graphql index 965cb04e82ca9..7e675cbd21c30 100644 --- a/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/validate_server_only_directives/fixtures/stream-connection-on-client.invalid.graphql @@ -6,7 +6,7 @@ query NodeQuery($id: ID!) { clientComments(first: 10) @stream_connection( key: "NodeQuery_clientComments" - initial_count: 0 + initialCount: 0 label: "comments" ) { edges { diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected index db869695cc30f..b619bbbd6cccf 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.expected @@ -4,7 +4,7 @@ query TestDefer @raw_response_type { ... on User { name friends(first: 10) - @stream_connection(key: "TestDefer_friends", initial_count: 0) { + @stream_connection(key: "TestDefer_friends", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.graphql b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.graphql index d318b27e3e3f0..88832391bf57e 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.graphql +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream-connection.graphql @@ -3,7 +3,7 @@ query TestDefer @raw_response_type { ... on User { name friends(first: 10) - @stream_connection(key: "TestDefer_friends", initial_count: 0) { + @stream_connection(key: "TestDefer_friends", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected index e79ebc313b654..4fb58e3ead27d 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.expected @@ -6,7 +6,7 @@ query TestStream @raw_response_type { friends(first: 10) @stream_connection( key: "PaginationFragment_friends" - initial_count: 1 + initialCount: 1 ) { edges { node { diff --git a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.graphql b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.graphql index 4d2caacc587ba..0f5e1b4d9b8c8 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.graphql +++ b/compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-stream.graphql @@ -5,7 +5,7 @@ query TestStream @raw_response_type { friends(first: 10) @stream_connection( key: "PaginationFragment_friends" - initial_count: 1 + initialCount: 1 ) { edges { node { diff --git a/compiler/crates/relay-typegen/tests/generate_flow/mod.rs b/compiler/crates/relay-typegen/tests/generate_flow/mod.rs index 879b0c89620ac..0e3c1a69d4d8f 100644 --- a/compiler/crates/relay-typegen/tests/generate_flow/mod.rs +++ b/compiler/crates/relay-typegen/tests/generate_flow/mod.rs @@ -13,7 +13,7 @@ use graphql_syntax::parse_executable; use interner::Intern; use relay_compiler::apply_transforms; use relay_test_schema::{get_test_schema, get_test_schema_with_extensions}; -use relay_transforms::{ConnectionInterface, FeatureFlags}; +use relay_transforms::{ConnectionInterface, DeferStreamInterface, FeatureFlags}; use relay_typegen::{self, TypegenConfig, TypegenLanguage}; use std::sync::Arc; @@ -37,6 +37,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { Arc::new(program), Default::default(), &ConnectionInterface::default(), + &DeferStreamInterface::default(), Arc::new(FeatureFlags { enable_flight_transform: false, enable_required_transform_for_prefix: Some("".intern()), diff --git a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.expected b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.expected index 82ff2bfe6d861..87c1a56e7b32f 100644 --- a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.expected +++ b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.expected @@ -4,7 +4,7 @@ query TestDefer @raw_response_type { ... on User { name friends(first: 10) - @stream_connection(key: "TestDefer_friends", initial_count: 0) { + @stream_connection(key: "TestDefer_friends", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.graphql b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.graphql index d318b27e3e3f0..88832391bf57e 100644 --- a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.graphql +++ b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream-connection.graphql @@ -3,7 +3,7 @@ query TestDefer @raw_response_type { ... on User { name friends(first: 10) - @stream_connection(key: "TestDefer_friends", initial_count: 0) { + @stream_connection(key: "TestDefer_friends", initialCount: 0) { edges { node { actor { diff --git a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.expected b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.expected index 02344516afaf4..29842ac4cbe0b 100644 --- a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.expected +++ b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.expected @@ -6,7 +6,7 @@ query TestStream @raw_response_type { friends(first: 10) @stream_connection( key: "PaginationFragment_friends" - initial_count: 1 + initialCount: 1 ) { edges { node { diff --git a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.graphql b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.graphql index 4d2caacc587ba..0f5e1b4d9b8c8 100644 --- a/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.graphql +++ b/compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-stream.graphql @@ -5,7 +5,7 @@ query TestStream @raw_response_type { friends(first: 10) @stream_connection( key: "PaginationFragment_friends" - initial_count: 1 + initialCount: 1 ) { edges { node { diff --git a/compiler/crates/relay-typegen/tests/generate_typescript/mod.rs b/compiler/crates/relay-typegen/tests/generate_typescript/mod.rs index 8bf1af96878d2..66ec341d49f1a 100644 --- a/compiler/crates/relay-typegen/tests/generate_typescript/mod.rs +++ b/compiler/crates/relay-typegen/tests/generate_typescript/mod.rs @@ -13,7 +13,7 @@ use graphql_syntax::parse_executable; use interner::Intern; use relay_compiler::apply_transforms; use relay_test_schema::{get_test_schema, get_test_schema_with_extensions}; -use relay_transforms::{ConnectionInterface, FeatureFlags}; +use relay_transforms::{ConnectionInterface, DeferStreamInterface, FeatureFlags}; use relay_typegen::{self, TypegenConfig, TypegenLanguage}; use std::sync::Arc; @@ -37,6 +37,7 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result { Arc::new(program), Default::default(), &ConnectionInterface::default(), + &DeferStreamInterface::default(), Arc::new(FeatureFlags { enable_flight_transform: false, enable_required_transform_for_prefix: Some("".intern()),