Skip to content

Commit 5a630e6

Browse files
committed
fix provided variables in split operation
1 parent 82bbc4a commit 5a630e6

13 files changed

+56
-63
lines changed

compiler/crates/relay-codegen/src/build_ast.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ pub fn build_request_params_ast_key(
8383
operation: &OperationDefinition,
8484
definition_source_location: WithLocation<StringKey>,
8585
project_config: &ProjectConfig,
86-
maybe_provided_variables: Option<AstKey>,
8786
) -> AstKey {
8887
let mut operation_builder = CodegenBuilder::new(
8988
schema,
@@ -92,11 +91,7 @@ pub fn build_request_params_ast_key(
9291
project_config,
9392
definition_source_location,
9493
);
95-
operation_builder.build_request_parameters(
96-
operation,
97-
request_parameters,
98-
maybe_provided_variables,
99-
)
94+
operation_builder.build_request_parameters(operation, request_parameters)
10095
}
10196

10297
pub fn build_provided_variables(
@@ -1840,7 +1835,6 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> {
18401835
&mut self,
18411836
operation: &OperationDefinition,
18421837
request_parameters: RequestParameters<'_>,
1843-
maybe_provided_variables: Option<AstKey>,
18441838
) -> AstKey {
18451839
let mut metadata_items: Vec<ObjectEntry> = operation
18461840
.directives
@@ -1929,7 +1923,7 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> {
19291923
},
19301924
});
19311925

1932-
if let Some(provided_variables) = maybe_provided_variables {
1926+
if let Some(provided_variables) = self.build_operation_provided_variables(operation) {
19331927
params_object.push(ObjectEntry {
19341928
key: CODEGEN_CONSTANTS.provided_variables,
19351929
value: Primitive::Key(provided_variables),

compiler/crates/relay-codegen/src/printer.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,12 @@ pub fn print_request(
7676
project_config: &ProjectConfig,
7777
top_level_statements: &mut TopLevelStatements,
7878
) -> String {
79-
let mut builder: AstBuilder = AstBuilder::default();
80-
let maybe_provided_variables = build_provided_variables(
81-
schema,
82-
&mut builder,
83-
operation,
84-
operation.name.map(|x| x.0),
85-
project_config,
86-
);
8779
Printer::without_dedupe(project_config).print_request(
8880
schema,
8981
operation,
9082
fragment,
9183
request_parameters,
9284
top_level_statements,
93-
maybe_provided_variables,
9485
)
9586
}
9687

@@ -104,21 +95,13 @@ pub fn print_request_params(
10495
let mut request_parameters = build_request_params(operation);
10596
request_parameters.id = query_id;
10697
let mut builder: AstBuilder = AstBuilder::default();
107-
let maybe_provided_variables = build_provided_variables(
108-
schema,
109-
&mut builder,
110-
operation,
111-
operation.name.map(|x| x.0),
112-
project_config,
113-
);
11498
let request_parameters_ast_key = build_request_params_ast_key(
11599
schema,
116100
request_parameters,
117101
&mut builder,
118102
operation,
119103
operation.name.map(|x| x.0),
120104
project_config,
121-
maybe_provided_variables,
122105
);
123106
let printer = JSONPrinter::new(&builder, project_config, top_level_statements);
124107
printer.print(request_parameters_ast_key, false)
@@ -165,25 +148,19 @@ impl<'p> Printer<'p> {
165148
}
166149
}
167150

168-
pub fn prepare_provided_variables_object(
151+
pub fn print_provided_variables(
169152
&mut self,
170153
schema: &SDLSchema,
171154
operation: &OperationDefinition,
172-
) -> Option<AstKey> {
173-
build_provided_variables(
155+
top_level_statements: &mut TopLevelStatements,
156+
) -> Option<String> {
157+
let provided_variables = build_provided_variables(
174158
schema,
175159
&mut self.builder,
176160
operation,
177161
operation.name.map(|x| x.0),
178162
self.project_config,
179-
)
180-
}
181-
182-
pub fn print_provided_variables(
183-
&mut self,
184-
provided_variables: AstKey,
185-
top_level_statements: &mut TopLevelStatements,
186-
) -> Option<String> {
163+
)?;
187164
let printer = JSONPrinter::new(&self.builder, self.project_config, top_level_statements);
188165
Some(printer.print(provided_variables, self.dedupe))
189166
}
@@ -222,7 +199,6 @@ impl<'p> Printer<'p> {
222199
fragment: &FragmentDefinition,
223200
request_parameters: RequestParameters<'_>,
224201
top_level_statements: &mut TopLevelStatements,
225-
maybe_provided_variables: Option<AstKey>,
226202
) -> String {
227203
let request_parameters = build_request_params_ast_key(
228204
schema,
@@ -231,7 +207,6 @@ impl<'p> Printer<'p> {
231207
operation,
232208
operation.name.map(|x| x.0),
233209
self.project_config,
234-
maybe_provided_variables,
235210
);
236211

237212
let key = build_request(
@@ -287,7 +262,6 @@ impl<'p> Printer<'p> {
287262
request_parameters: RequestParameters<'_>,
288263
operation: &OperationDefinition,
289264
top_level_statements: &mut TopLevelStatements,
290-
maybe_provided_variables: Option<AstKey>,
291265
) -> String {
292266
let key = build_request_params_ast_key(
293267
schema,
@@ -296,7 +270,6 @@ impl<'p> Printer<'p> {
296270
operation,
297271
operation.name.map(|x| x.0),
298272
self.project_config,
299-
maybe_provided_variables,
300273
);
301274
let printer = JSONPrinter::new(&self.builder, self.project_config, top_level_statements);
302275
printer.print(key, self.dedupe)

compiler/crates/relay-codegen/tests/connections/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
6666
&operation_fragment,
6767
request_parameters,
6868
&mut import_statements,
69-
None,
7069
);
7170
format!("{}{}", import_statements, request)
7271
})

compiler/crates/relay-compiler/src/artifact_content/content.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,12 @@ pub fn generate_operation(
264264

265265
// -- Generate provided variables --
266266
let mut top_level_statements = Default::default();
267-
let maybe_provided_variables =
268-
printer.prepare_provided_variables_object(schema, normalization_operation);
269-
270267
if !skip_types {
271-
let provided_variables_text = maybe_provided_variables.and_then(|provided_variables| {
272-
printer.print_provided_variables(provided_variables, &mut top_level_statements)
273-
});
274-
268+
let maybe_provided_variables = printer.print_provided_variables(
269+
schema,
270+
normalization_operation,
271+
&mut top_level_statements,
272+
);
275273
write!(
276274
section,
277275
"{}",
@@ -281,7 +279,7 @@ pub fn generate_operation(
281279
schema,
282280
project_config,
283281
fragment_locations,
284-
provided_variables_text,
282+
maybe_provided_variables,
285283
)
286284
)?;
287285
}
@@ -305,7 +303,6 @@ pub fn generate_operation(
305303
&operation_fragment,
306304
request_parameters,
307305
&mut top_level_statements,
308-
maybe_provided_variables,
309306
);
310307

311308
let mut section = GenericSection::default();

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-directive.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ fragment providedVariableDirective_DeferredFragment on Image {
115115
"name": "providedVariableDirectiveQuery",
116116
"operationKind": "query",
117117
"text": null,
118-
"providedVariables": {}
118+
"providedVariables": {
119+
"__relay_internal__pv__jsProvider": require('jsProvider')
120+
}
119121
}
120122
}
121123

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-in-fragment.expected

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ fragment providedVariableInFragment_Fragment2 on User
181181
"name": "providedVariableInFragment_Query",
182182
"operationKind": "query",
183183
"text": null,
184-
"providedVariables": {}
184+
"providedVariables": {
185+
"__relay_internal__pv__fooGKProvider": require('fooGKProvider'),
186+
"__relay_internal__pv__foobarGKProvider": require('foobarGKProvider'),
187+
"__relay_internal__pv__barGKProvider": require('barGKProvider')
188+
}
185189
}
186190
}
187191

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-multiple-queries.expected

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ fragment providedVariableMultipleQueries_MultiProvidedVar on User
217217
"name": "providedVariableMultipleQueries_MultiFragmentQuery",
218218
"operationKind": "query",
219219
"text": null,
220-
"providedVariables": {}
220+
"providedVariables": {
221+
"__relay_internal__pv__includeNameProvider": require('includeNameProvider'),
222+
"__relay_internal__pv__numberOfFriendsProvider": require('numberOfFriendsProvider')
223+
}
221224
}
222225
}
223226

@@ -358,7 +361,9 @@ fragment providedVariableMultipleQueries_OneProvidedVar on User {
358361
"name": "providedVariableMultipleQueries_OneFragmentQuery",
359362
"operationKind": "query",
360363
"text": null,
361-
"providedVariables": {}
364+
"providedVariables": {
365+
"__relay_internal__pv__includeNameProvider": require('includeNameProvider')
366+
}
362367
}
363368
}
364369

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-nested-split-operation.expected

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ fragment providedVariableNestedSplitOperation_Plain2 on PlainUserNameRenderer
466466
"name": "providedVariableNestedSplitOperation_Query",
467467
"operationKind": "query",
468468
"text": null,
469-
"providedVariables": {}
469+
"providedVariables": {
470+
"__relay_internal__pv__shouldIncludeMarkdown_RelayProvider": require('shouldIncludeMarkdown_RelayProvider'),
471+
"__relay_internal__pv__shouldIncludeData_RelayProvider": require('shouldIncludeData_RelayProvider')
472+
}
470473
}
471474
}
472475

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-no-inline-fragment.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ fragment providedVariableNoInlineFragment on User
118118
"name": "providedVariableNoInlineFragment_Query",
119119
"operationKind": "query",
120120
"text": null,
121-
"providedVariables": {}
121+
"providedVariables": {
122+
"__relay_internal__pv__jsScaleProvider": require('jsScaleProvider')
123+
}
122124
}
123125
}
124126

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-refetchable-fragment.expected

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ fragment providedVariableRefetchableFragment_providedVariableFragment on User
129129
"name": "providedVariableRefetchableFragmentQuery",
130130
"operationKind": "query",
131131
"text": null,
132-
"providedVariables": {}
132+
"providedVariables": {
133+
"__relay_internal__pv__includeName_RelayProvider": require('includeName_RelayProvider')
134+
}
133135
}
134136
}
135137

@@ -278,7 +280,9 @@ fragment providedVariableRefetchableFragment_providedVariableFragment on User {
278280
"name": "refetchableQuery",
279281
"operationKind": "query",
280282
"text": null,
281-
"providedVariables": {}
283+
"providedVariables": {
284+
"__relay_internal__pv__includeName_RelayProvider": require('includeName_RelayProvider')
285+
}
282286
}
283287
}
284288

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-reused-nested-fragment.expected

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ fragment providedVariableReusedNestedFragment_FragmentWithProvider on User
152152
"name": "providedVariableReusedNestedFragment_1Query",
153153
"operationKind": "query",
154154
"text": null,
155-
"providedVariables": {}
155+
"providedVariables": {
156+
"__relay_internal__pv__barGKProvider": require('barGKProvider')
157+
}
156158
}
157159
}
158160

@@ -303,7 +305,9 @@ fragment providedVariableReusedNestedFragment_FragmentWithProvider on User {
303305
"name": "providedVariableReusedNestedFragment_2Query",
304306
"operationKind": "query",
305307
"text": null,
306-
"providedVariables": {}
308+
"providedVariables": {
309+
"__relay_internal__pv__barGKProvider": require('barGKProvider')
310+
}
307311
}
308312
}
309313

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-reused-nested-linked-fragment.expected

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ fragment providedVariableReusedNestedLinkedFragment_FragmentWithProvider on User
125125
"name": "providedVariableReusedNestedLinkedFragment_1Query",
126126
"operationKind": "query",
127127
"text": null,
128-
"providedVariables": {}
128+
"providedVariables": {
129+
"__relay_internal__pv__barGKProvider": require('barGKProvider')
130+
}
129131
}
130132
}
131133

@@ -251,7 +253,9 @@ fragment providedVariableReusedNestedLinkedFragment_FragmentWithProvider on User
251253
"name": "providedVariableReusedNestedLinkedFragment_2Query",
252254
"operationKind": "query",
253255
"text": null,
254-
"providedVariables": {}
256+
"providedVariables": {
257+
"__relay_internal__pv__barGKProvider": require('barGKProvider')
258+
}
255259
}
256260
}
257261

compiler/crates/relay-compiler/tests/compile_relay_artifacts/fixtures/provided-variable-split-operation.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ fragment providedVariableSplitOperation_PlainUserNameRenderer_name on PlainUserN
277277
"name": "providedVariableSplitOperation_Query",
278278
"operationKind": "query",
279279
"text": null,
280-
"providedVariables": {}
280+
"providedVariables": {
281+
"__relay_internal__pv__shouldIncludeData_RelayProvider": require('shouldIncludeData_RelayProvider')
282+
}
281283
}
282284
}
283285

0 commit comments

Comments
 (0)