@@ -35,6 +35,7 @@ use graphql_syntax::OperationKind;
35
35
use intern:: string_key:: StringKeyMap ;
36
36
use node_query_generator:: NODE_QUERY_GENERATOR ;
37
37
use query_query_generator:: QUERY_QUERY_GENERATOR ;
38
+ use relay_config:: ProjectConfig ;
38
39
use relay_config:: SchemaConfig ;
39
40
use schema:: SDLSchema ;
40
41
use schema:: Schema ;
@@ -70,13 +71,13 @@ use crate::root_variables::VariableMap;
70
71
/// Fragment to Root IR nodes.
71
72
pub fn transform_refetchable_fragment (
72
73
program : & Program ,
73
- schema_config : & SchemaConfig ,
74
+ project_config : & ProjectConfig ,
74
75
base_fragment_names : & ' _ FragmentDefinitionNameSet ,
75
76
for_typegen : bool ,
76
77
) -> DiagnosticsResult < Program > {
77
78
let mut next_program = Program :: new ( Arc :: clone ( & program. schema ) ) ;
78
79
79
- let mut transformer = RefetchableFragment :: new ( program, schema_config , for_typegen) ;
80
+ let mut transformer = RefetchableFragment :: new ( program, project_config , for_typegen) ;
80
81
81
82
for operation in program. operations ( ) {
82
83
next_program. insert_operation ( Arc :: clone ( operation) ) ;
@@ -113,26 +114,26 @@ pub fn transform_refetchable_fragment(
113
114
114
115
type ExistingRefetchOperations = StringKeyMap < WithLocation < FragmentDefinitionName > > ;
115
116
116
- pub struct RefetchableFragment < ' program , ' sc > {
117
+ pub struct RefetchableFragment < ' program , ' pc > {
117
118
connection_constants : ConnectionConstants ,
118
119
existing_refetch_operations : ExistingRefetchOperations ,
119
120
for_typegen : bool ,
120
121
program : & ' program Program ,
121
- schema_config : & ' sc SchemaConfig ,
122
+ project_config : & ' pc ProjectConfig ,
122
123
}
123
124
124
- impl < ' program , ' sc > RefetchableFragment < ' program , ' sc > {
125
+ impl < ' program , ' pc > RefetchableFragment < ' program , ' pc > {
125
126
pub fn new (
126
127
program : & ' program Program ,
127
- schema_config : & ' sc SchemaConfig ,
128
+ project_config : & ' pc ProjectConfig ,
128
129
for_typegen : bool ,
129
130
) -> Self {
130
131
RefetchableFragment {
131
132
connection_constants : Default :: default ( ) ,
132
133
existing_refetch_operations : Default :: default ( ) ,
133
134
for_typegen,
134
135
program,
135
- schema_config ,
136
+ project_config ,
136
137
}
137
138
}
138
139
@@ -170,10 +171,12 @@ impl<'program, 'sc> RefetchableFragment<'program, 'sc> {
170
171
let variables_map =
171
172
InferVariablesVisitor :: new ( self . program ) . infer_fragment_variables ( fragment) ;
172
173
173
- for generator in GENERATORS . iter ( ) {
174
+ let generators = get_query_generators ( self . project_config ) ;
175
+
176
+ for generator in generators {
174
177
if let Some ( refetch_root) = ( generator. build_refetch_operation ) (
175
178
& self . program . schema ,
176
- self . schema_config ,
179
+ & self . project_config . schema_config ,
177
180
fragment,
178
181
refetchable_directive. query_name . item ,
179
182
& variables_map,
@@ -185,7 +188,7 @@ impl<'program, 'sc> RefetchableFragment<'program, 'sc> {
185
188
}
186
189
}
187
190
let mut descriptions = String :: new ( ) ;
188
- for generator in GENERATORS . iter ( ) {
191
+ for generator in generators . iter ( ) {
189
192
writeln ! ( descriptions, " - {}" , generator. description) . unwrap ( ) ;
190
193
}
191
194
descriptions. pop ( ) ;
@@ -367,6 +370,24 @@ const GENERATORS: [QueryGenerator; 4] = [
367
370
FETCHABLE_QUERY_GENERATOR ,
368
371
] ;
369
372
373
+ const PREFER_FETCHABLE_GENERATORS : [ QueryGenerator ; 4 ] = [
374
+ VIEWER_QUERY_GENERATOR ,
375
+ QUERY_QUERY_GENERATOR ,
376
+ FETCHABLE_QUERY_GENERATOR ,
377
+ NODE_QUERY_GENERATOR ,
378
+ ] ;
379
+
380
+ fn get_query_generators ( project_config : & ProjectConfig ) -> & ' static [ QueryGenerator ; 4 ] {
381
+ if project_config
382
+ . feature_flags
383
+ . prefer_fetchable_in_refetch_queries
384
+ {
385
+ & PREFER_FETCHABLE_GENERATORS
386
+ } else {
387
+ & GENERATORS
388
+ }
389
+ }
390
+
370
391
pub struct RefetchRoot {
371
392
pub fragment : Arc < FragmentDefinition > ,
372
393
pub selections : Vec < Selection > ,
0 commit comments