@@ -17,11 +17,11 @@ use isograph_lang_types::{
1717} ;
1818use isograph_schema:: {
1919 ClientFieldVariant , ClientScalarSelectable , ClientSelectableId , FieldMapItem ,
20- FieldTraversalResult , NameAndArguments , NetworkProtocol , NormalizationKey , ScalarSelectableId ,
21- Schema , ServerEntityName , ServerObjectSelectableVariant , UserWrittenClientTypeInfo ,
22- ValidatedSelection , ValidatedVariableDefinition , WrappedSelectionMapSelection ,
23- accessible_client_fields , description , inline_fragment_reader_selection_set ,
24- output_type_annotation, selection_map_wrapped,
20+ FieldTraversalResult , NameAndArguments , NetworkProtocol , NormalizationKey , RefetchStrategy ,
21+ ScalarSelectableId , Schema , ServerEntityName , ServerObjectSelectableVariant ,
22+ UserWrittenClientTypeInfo , ValidatedSelection , ValidatedVariableDefinition ,
23+ WrappedSelectionMapSelection , accessible_client_fields , description ,
24+ inline_fragment_reader_selection_set , output_type_annotation, selection_map_wrapped,
2525} ;
2626use lazy_static:: lazy_static;
2727use std:: {
@@ -271,26 +271,11 @@ fn get_artifact_path_and_content_impl<TNetworkProtocol: NetworkProtocol>(
271271 This is indicative of a bug in Isograph.",
272272 ) ;
273273
274- if schema
275- . fetchable_types
276- . contains_key ( & client_scalar_selectable. parent_object_entity_name )
277- {
278- panic ! ( "Loadable fields on root objects are not yet supported" ) ;
279- }
280-
281- let wrapped_map = selection_map_wrapped (
282- merged_selection_map. clone ( ) ,
283- vec ! [
284- WrappedSelectionMapSelection :: InlineFragment (
285- type_to_refine_to. name. item,
286- ) ,
287- WrappedSelectionMapSelection :: LinkedField {
288- server_object_selectable_name: "node" . intern( ) . into( ) ,
289- arguments: vec![ id_arg. clone( ) ] ,
290- concrete_type: None ,
291- } ,
292- ] ,
293- ) ;
274+ let variable_definitions_iter = client_scalar_selectable
275+ . variable_definitions
276+ . iter ( )
277+ . map ( |variable_definition| & variable_definition. item ) ;
278+
294279 let id_var = ValidatedVariableDefinition {
295280 name : WithLocation :: new ( "id" . intern ( ) . into ( ) , Location :: Generated ) ,
296281 type_ : GraphQLTypeAnnotation :: NonNull ( Box :: new (
@@ -305,11 +290,42 @@ fn get_artifact_path_and_content_impl<TNetworkProtocol: NetworkProtocol>(
305290 ) ) ,
306291 default_value : None ,
307292 } ;
308- let variable_definitions_iter = client_scalar_selectable
309- . variable_definitions
310- . iter ( )
311- . map ( |variable_definition| & variable_definition. item )
312- . chain ( std:: iter:: once ( & id_var) ) ;
293+
294+ let ( wrapped_map, variable_definitions_iter) : ( _ , Vec < _ > ) =
295+ match client_scalar_selectable. refetch_strategy . as_ref ( ) . expect (
296+ "Expected a refetch strategy. \
297+ This is indicative of a bug in Isograph.",
298+ ) {
299+ RefetchStrategy :: RefetchFromRoot => (
300+ selection_map_wrapped ( merged_selection_map. clone ( ) , vec ! [ ] ) ,
301+ variable_definitions_iter. collect ( ) ,
302+ ) ,
303+ RefetchStrategy :: UseRefetchField ( _) => {
304+ let wrapped_map = selection_map_wrapped (
305+ merged_selection_map. clone ( ) ,
306+ vec ! [
307+ WrappedSelectionMapSelection :: InlineFragment (
308+ type_to_refine_to. name. item,
309+ ) ,
310+ WrappedSelectionMapSelection :: LinkedField {
311+ server_object_selectable_name: "node"
312+ . intern( )
313+ . into( ) ,
314+ arguments: vec![ id_arg. clone( ) ] ,
315+ concrete_type: None ,
316+ } ,
317+ ] ,
318+ ) ;
319+
320+ (
321+ wrapped_map,
322+ variable_definitions_iter
323+ . chain ( std:: iter:: once ( & id_var) )
324+ . collect ( ) ,
325+ )
326+ }
327+ } ;
328+
313329 let mut traversal_state = traversal_state. clone ( ) ;
314330 traversal_state. refetch_paths = traversal_state
315331 . refetch_paths
0 commit comments