Skip to content

Commit

Permalink
Generate metadata for prefetchable pagination
Browse files Browse the repository at this point in the history
Reviewed By: captbaritone

Differential Revision: D63917160

fbshipit-source-id: a1a8e19aee2e31ac0d2db76c049c90f3b438d502
  • Loading branch information
tyao1 authored and facebook-github-bot committed Oct 22, 2024
1 parent 4a67ddd commit dececd1
Show file tree
Hide file tree
Showing 33 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use super::build_fragment_metadata_as_directive;
use super::build_fragment_spread;
use super::build_operation_variable_definitions;
use super::build_used_global_variables;
use super::uses_prefetchable_pagination_in_connection;
use super::validation_message::ValidationMessage;
use super::QueryGenerator;
use super::RefetchRoot;
Expand Down Expand Up @@ -78,6 +79,9 @@ fn build_refetch_operation(
identifier_query_variable_name: schema_config
.node_interface_id_variable_name,
}),
is_prefetchable_pagination: uses_prefetchable_pagination_in_connection(
fragment,
),
},
),
selections: enforce_selections_with_id_field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use super::build_fragment_metadata_as_directive;
use super::build_fragment_spread;
use super::build_operation_variable_definitions;
use super::build_used_global_variables;
use super::uses_prefetchable_pagination_in_connection;
use super::validation_message::ValidationMessage;
use super::QueryGenerator;
use super::RefetchRoot;
Expand Down Expand Up @@ -124,6 +125,9 @@ fn build_refetch_operation(
identifier_query_variable_name: schema_config
.node_interface_id_variable_name,
}),
is_prefetchable_pagination: uses_prefetchable_pagination_in_connection(
fragment,
),
},
),
used_global_variables: build_used_global_variables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use super::build_fragment_metadata_as_directive;
use super::build_fragment_spread;
use super::build_operation_variable_definitions;
use super::build_used_global_variables;
use super::uses_prefetchable_pagination_in_connection;
use super::QueryGenerator;
use super::RefetchRoot;
use super::RefetchableMetadata;
Expand All @@ -42,6 +43,7 @@ fn build_refetch_operation(
operation_name: query_name,
path: vec![],
identifier_info: None,
is_prefetchable_pagination: uses_prefetchable_pagination_in_connection(fragment),
},
),
used_global_variables: build_used_global_variables(
Expand Down
12 changes: 12 additions & 0 deletions compiler/crates/relay-transforms/src/refetchable_fragment/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use intern::string_key::StringKey;
use lazy_static::lazy_static;

use super::validation_message::ValidationMessage;
use crate::extract_connection_metadata_from_directive;
use crate::root_variables::VariableMap;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand All @@ -43,6 +44,7 @@ pub struct RefetchableMetadata {
pub operation_name: OperationDefinitionName,
pub path: Vec<StringKey>,
pub identifier_info: Option<RefetchableIdentifierInfo>,
pub is_prefetchable_pagination: bool,
}
associated_data_impl!(RefetchableMetadata);

Expand Down Expand Up @@ -144,6 +146,16 @@ pub fn build_fragment_metadata_as_directive(
next_directives
}

pub fn uses_prefetchable_pagination_in_connection(fragment: &FragmentDefinition) -> bool {
if let Some(metadatas) = extract_connection_metadata_from_directive(&fragment.directives) {
if metadatas.len() == 1 {
let metadata = &metadatas[0];
return metadata.is_prefetchable_pagination;
}
}
false
}

/// Metadata attached to generated refetch queries storing the name of the
/// fragment the operation was derived from.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use super::build_fragment_metadata_as_directive;
use super::build_fragment_spread;
use super::build_operation_variable_definitions;
use super::build_used_global_variables;
use super::uses_prefetchable_pagination_in_connection;
use super::validation_message::ValidationMessage;
use super::QueryGenerator;
use super::RefetchRoot;
Expand Down Expand Up @@ -51,6 +52,7 @@ fn build_refetch_operation(
operation_name: query_name,
path: vec![CONSTANTS.viewer_field_name],
identifier_info: None,
is_prefetchable_pagination: uses_prefetchable_pagination_in_connection(fragment),
},
),
used_global_variables: build_used_global_variables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
doesViewerLike
Expand Down Expand Up @@ -141,6 +142,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend_1 on User @__ClientEdge
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fragment RefetchableClientEdgeQuery_Foo_node_PhotoStory__author__best_friend on
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down Expand Up @@ -149,6 +150,7 @@ fragment RefetchableClientEdgeQuery_Foo_node_Story__author__best_friend on User
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
doesViewerLike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
url(site: $site)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_nearest_neighbor__best_friend on Us
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
url(site: $top_level_site)
Expand Down Expand Up @@ -162,6 +163,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend__best_friend on User @_
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__ClientEdgeGe
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
... @__ClientEdgeMetadataDirective
Expand Down Expand Up @@ -156,6 +157,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend__best_friend on User @_
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fragment RefetchableFragment on Actor @refetchable(queryName: "RefetchableFragme
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fragment RefetchableFragment on AllConcreteTypesImplementNode @refetchable(query
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fragment RefetchableFragment on Node @refetchable(queryName: "RefetchableFragmen
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
... on User {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fragment RefetchableFragment on Node @refetchable(queryName: "RefetchableFragmen
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fragment RefetchableFragment on NonNodeStory @refetchable(queryName: "Refetchabl
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
actor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fragment RefetchableFragment on User @refetchable(queryName: "RefetchableFragmen
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
__id: id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fragment RefetchableFragment on User @refetchable(queryName: "RefetchableFragmen
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fragment RefetchableFragment on Query @refetchable(queryName: "RefetchableFragme
# ),
# path: [],
# identifier_info: None,
# is_prefetchable_pagination: false,
# }
{
node(id: $id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fragment RefetchableFragment on Query @refetchable(queryName: "RefetchableFragme
# ),
# path: [],
# identifier_info: None,
# is_prefetchable_pagination: false,
# }
{
node(id: $id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fragment RefetchableFragment on Viewer @refetchable(queryName: "RefetchableFragm
# "viewer",
# ],
# identifier_info: None,
# is_prefetchable_pagination: false,
# }
{
actor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fragment RefetchableFragment on User @refetchable(queryName: "RefetchableFragmen
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fragment RefetchableFragment on Query @refetchable(queryName: "RefetchableFragme
# ),
# path: [],
# identifier_info: None,
# is_prefetchable_pagination: false,
# }
{
node(id: $id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fragment RefetchableFragment on Viewer @refetchable(queryName: "RefetchableFragm
# "viewer",
# ],
# identifier_info: None,
# is_prefetchable_pagination: false,
# }
{
actor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fragment PaginationFragment on Node @refetchable(queryName: "RefetchableFragment
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fragment PaginationFragment on Node @refetchable(queryName: "RefetchableFragment
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fragment PaginationFragment on Node @refetchable(queryName: "RefetchableFragment
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fragment RefetchableFragment on RefetchableInterface @refetchable(queryName: "Re
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fragment RefetchableFragmentFoo on RefetchableInterfaceFoo @refetchable(queryNam
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fragment RefetchableFragment on RefetchableInterface @refetchable(queryName: "Re
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fragment RefetchableFragment on RefetchableInterface @refetchable(queryName: "Re
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
id
Expand All @@ -94,6 +95,7 @@ fragment RefetchableFragment2 on RefetchableInterface2 @refetchable(queryName: "
# identifier_query_variable_name: "id",
# },
# ),
# is_prefetchable_pagination: false,
# }
{
__typename
Expand Down

0 comments on commit dececd1

Please sign in to comment.