Skip to content

Commit

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

Differential Revision: D63921399

fbshipit-source-id: 7b8795891693b050667e15d3406fb1ddfa6a6501
  • Loading branch information
tyao1 authored and facebook-github-bot committed Oct 22, 2024
1 parent dececd1 commit 9035b32
Show file tree
Hide file tree
Showing 14 changed files with 1,393 additions and 19 deletions.
17 changes: 14 additions & 3 deletions compiler/crates/relay-codegen/src/build_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

use std::path::PathBuf;

use ::intern::intern;
use ::intern::string_key::Intern;
use ::intern::string_key::StringKey;
use ::intern::Lookup;
use common::DirectiveName;
use common::FeatureFlag;
use common::NamedItem;
Expand All @@ -32,9 +36,6 @@ use graphql_ir::Selection;
use graphql_ir::Value;
use graphql_ir::VariableDefinition;
use graphql_syntax::OperationKind;
use intern::string_key::Intern;
use intern::string_key::StringKey;
use intern::Lookup;
use lazy_static::lazy_static;
use md5::Digest;
use md5::Md5;
Expand Down Expand Up @@ -595,6 +596,16 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> {
})),
});
}
if refetch_metadata.is_prefetchable_pagination {
refetch_object.push(ObjectEntry {
key: intern!("edgesFragment"),
value: Primitive::GraphQLModuleDependency(GraphQLModuleDependency::Name(
ExecutableDefinitionName::FragmentDefinitionName(FragmentDefinitionName(
format!("{}__edges", fragment.name.item).intern(),
)),
)),
});
}

metadata.push(ObjectEntry {
key: CODEGEN_CONSTANTS.refetch,
Expand Down
8 changes: 6 additions & 2 deletions compiler/crates/relay-codegen/tests/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String>
validate_connections(&program, &connection_interface)
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?;

let next_program =
transform_connections(&program, &connection_interface, &defer_stream_interface);
let next_program = transform_connections(
&program,
&connection_interface,
&defer_stream_interface,
false,
);

let mut printed = next_program
.operations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,26 @@ impl ArtifactGeneratedTypes {
)),
}
} else if let Some(refetchable_metadata) = RefetchableMetadata::find(&fragment.directives) {
Self {
imported_types: "ReaderFragment, RefetchableFragment",
ast_type: "ReaderFragment",
exported_type: Some(format!(
"RefetchableFragment<\n {name}$fragmentType,\n {name}$data,\n {refetchable_name}$variables,\n>",
name = fragment.name.item,
refetchable_name = refetchable_metadata.operation_name
)),
if refetchable_metadata.is_prefetchable_pagination {
Self {
imported_types: "ReaderFragment, PrefetchableRefetchableFragment",
ast_type: "ReaderFragment",
exported_type: Some(format!(
"PrefetchableRefetchableFragment<\n {name}$fragmentType,\n {name}$data,\n {name}__edges$data,\n {refetchable_name}$variables,\n>",
name = fragment.name.item,
refetchable_name = refetchable_metadata.operation_name
)),
}
} else {
Self {
imported_types: "ReaderFragment, RefetchableFragment",
ast_type: "ReaderFragment",
exported_type: Some(format!(
"RefetchableFragment<\n {name}$fragmentType,\n {name}$data,\n {refetchable_name}$variables,\n>",
name = fragment.name.item,
refetchable_name = refetchable_metadata.operation_name
)),
}
}
} else if is_updatable_fragment {
Self {
Expand Down
Loading

0 comments on commit 9035b32

Please sign in to comment.