Skip to content

Consider fragment on conrete type for union generation #4924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/crates/relay-compiler-playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use relay_transforms::apply_transforms;
use relay_transforms::Programs;
use relay_typegen::generate_fragment_type_exports_section;
use relay_typegen::generate_operation_type_exports_section;
use relay_typegen::FragmentLocations;
use relay_typegen::FragmentInfoLookup;
use relay_typegen::TypegenConfig;
use schema::SDLSchema;
use serde::Serialize;
Expand Down Expand Up @@ -231,7 +231,7 @@ pub fn parse_to_types_impl(
let project_config = get_project_config(feature_flags_json, Some(typegen_config_json))?;
let programs = get_programs(&schema, &project_config, document_text)?;

let fragment_locations = FragmentLocations::new(programs.typegen.fragments());
let fragment_locations = FragmentInfoLookup::new(programs.typegen.fragments());
let types_string = programs
.typegen
.fragments()
Expand Down
12 changes: 6 additions & 6 deletions compiler/crates/relay-compiler/src/artifact_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use graphql_ir::FragmentDefinition;
use graphql_ir::OperationDefinition;
use relay_codegen::Printer;
use relay_codegen::QueryID;
use relay_typegen::FragmentLocations;
use relay_typegen::FragmentInfoLookup;
use schema::SDLSchema;

use self::content::generate_preloadable_query_parameters;
Expand Down Expand Up @@ -76,7 +76,7 @@ impl ArtifactContent {
printer: &mut Printer<'_>,
schema: &SDLSchema,
source_file: SourceLocationKey,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> Vec<u8> {
let skip_types =
if let Some(extra_artifacts_config) = &project_config.extra_artifacts_config {
Expand Down Expand Up @@ -104,7 +104,7 @@ impl ArtifactContent {
text,
id_and_text_hash,
skip_types,
fragment_locations,
fragment_lookup,
)
.unwrap(),
ArtifactContent::UpdatableQuery {
Expand All @@ -120,7 +120,7 @@ impl ArtifactContent {
typegen_operation,
source_hash.into(),
skip_types,
fragment_locations,
fragment_lookup,
)
.unwrap(),
ArtifactContent::PreloadableQueryParameters {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl ArtifactContent {
normalization_operation,
typegen_operation,
source_hash.as_ref(),
fragment_locations,
fragment_lookup,
*no_optional_fields_in_raw_response_type,
)
.unwrap(),
Expand All @@ -165,7 +165,7 @@ impl ArtifactContent {
typegen_fragment,
source_hash.as_ref(),
skip_types,
fragment_locations,
fragment_lookup,
)
.unwrap(),
ArtifactContent::ResolversSchema => {
Expand Down
34 changes: 15 additions & 19 deletions compiler/crates/relay-compiler/src/artifact_content/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use relay_typegen::generate_fragment_type_exports_section;
use relay_typegen::generate_named_validator_export;
use relay_typegen::generate_operation_type_exports_section;
use relay_typegen::generate_split_operation_type_exports_section;
use relay_typegen::FragmentLocations;
use relay_typegen::FragmentInfoLookup;
use relay_typegen::TypegenConfig;
use relay_typegen::TypegenLanguage;
use schema::SDLSchema;
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn generate_updatable_query(
typegen_operation: &OperationDefinition,
source_hash: String,
skip_types: bool,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> Result<Vec<u8>, FmtError> {
let operation_fragment = FragmentDefinition {
name: reader_operation.name.map(|x| FragmentDefinitionName(x.0)),
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn generate_updatable_query(
reader_operation,
schema,
project_config,
fragment_locations,
fragment_lookup,
None, // TODO: Add/investigrate support for provided variables in updatable queries
)
)?;
Expand Down Expand Up @@ -283,7 +283,7 @@ pub fn generate_operation(
text: &Option<String>,
id_and_text_hash: &Option<QueryID>,
skip_types: bool,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> Result<Vec<u8>, FmtError> {
let mut request_parameters = build_request_params(normalization_operation);

Expand Down Expand Up @@ -392,7 +392,7 @@ pub fn generate_operation(
normalization_operation,
schema,
project_config,
fragment_locations,
fragment_lookup,
maybe_provided_variables,
)
)?;
Expand Down Expand Up @@ -508,7 +508,7 @@ pub fn generate_split_operation(
normalization_operation: &OperationDefinition,
typegen_operation: &Option<Arc<OperationDefinition>>,
source_hash: Option<&String>,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
no_optional_fields_in_raw_response_type: bool,
) -> Result<Vec<u8>, FmtError> {
let mut content_sections = ContentSections::default();
Expand Down Expand Up @@ -555,7 +555,7 @@ pub fn generate_split_operation(
normalization_operation,
schema,
project_config,
fragment_locations,
fragment_lookup,
no_optional_fields_in_raw_response_type
)
)?;
Expand Down Expand Up @@ -621,7 +621,7 @@ pub fn generate_fragment(
typegen_fragment: &FragmentDefinition,
source_hash: Option<&String>,
skip_types: bool,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> Result<Vec<u8>, FmtError> {
let is_assignable_fragment = typegen_fragment
.directives
Expand All @@ -634,7 +634,7 @@ pub fn generate_fragment(
schema,
typegen_fragment,
source_hash,
fragment_locations,
fragment_lookup,
)
} else {
generate_read_only_fragment(
Expand All @@ -646,7 +646,7 @@ pub fn generate_fragment(
typegen_fragment,
source_hash,
skip_types,
fragment_locations,
fragment_lookup,
)
}
}
Expand All @@ -661,7 +661,7 @@ fn generate_read_only_fragment(
typegen_fragment: &FragmentDefinition,
source_hash: Option<&String>,
skip_types: bool,
fragment_locations: &FragmentLocations,
fragment_locations: &FragmentInfoLookup,
) -> Result<Vec<u8>, FmtError> {
let mut content_sections = ContentSections::default();

Expand Down Expand Up @@ -787,7 +787,7 @@ fn generate_assignable_fragment(
schema: &SDLSchema,
typegen_fragment: &FragmentDefinition,
source_hash: Option<&String>,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> Result<Vec<u8>, FmtError> {
let mut content_sections = ContentSections::default();

Expand Down Expand Up @@ -824,7 +824,7 @@ fn generate_assignable_fragment(
typegen_fragment,
schema,
project_config,
fragment_locations,
fragment_lookup,
)
)?;

Expand Down Expand Up @@ -871,12 +871,8 @@ fn generate_assignable_fragment(
// don't need to emit a reader fragment.
// Instead, we only need a named validator export, i.e.
// module.exports.validate = ...
let named_validator_export = generate_named_validator_export(
typegen_fragment,
schema,
project_config,
fragment_locations,
);
let named_validator_export =
generate_named_validator_export(typegen_fragment, schema, project_config, fragment_lookup);
writeln!(section, "{}", named_validator_export).unwrap();
content_sections.push(ContentSection::Generic(section));
// -- End Export Section --
Expand Down
12 changes: 6 additions & 6 deletions compiler/crates/relay-compiler/src/build_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use relay_config::ProjectName;
use relay_transforms::apply_transforms;
use relay_transforms::CustomTransformsConfig;
use relay_transforms::Programs;
use relay_typegen::FragmentLocations;
use relay_typegen::FragmentInfoLookup;
use rustc_hash::FxHashMap;
use rustc_hash::FxHashSet;
use schema::SDLSchema;
Expand Down Expand Up @@ -566,7 +566,7 @@ pub async fn commit_project(
log_event.string("project", project_config.name.to_string());
let commit_time = log_event.start("commit_project_time");

let fragment_locations = FragmentLocations::new(programs.typegen.fragments());
let fragment_lookup = FragmentInfoLookup::new(programs.typegen.fragments());
if source_control_update_status.is_started() {
debug!("commit_project cancelled before persisting due to source control updates");
return Err(BuildProjectFailure::Cancelled);
Expand Down Expand Up @@ -650,7 +650,7 @@ pub async fn commit_project(
schema,
should_stop_updating_artifacts,
&artifacts,
&fragment_locations,
&fragment_lookup,
&artifacts_file_hash_map,
)?;
for artifact in &artifacts {
Expand Down Expand Up @@ -686,7 +686,7 @@ pub async fn commit_project(
schema,
should_stop_updating_artifacts,
&artifacts,
&fragment_locations,
&fragment_lookup,
&artifacts_file_hash_map,
)?;
artifacts.into_par_iter().for_each(|artifact| {
Expand Down Expand Up @@ -785,7 +785,7 @@ fn write_artifacts<F: Fn() -> bool + Sync + Send>(
schema: &SDLSchema,
should_stop_updating_artifacts: F,
artifacts: &[Artifact],
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
artifacts_file_hash_map: &Option<FxHashMap<String, Option<String>>>,
) -> Result<(), BuildProjectFailure> {
artifacts.par_chunks(8).try_for_each_init(
Expand All @@ -802,7 +802,7 @@ fn write_artifacts<F: Fn() -> bool + Sync + Send>(
printer,
schema,
artifact.source_file,
fragment_locations,
fragment_lookup,
);
let file_hash = match artifact.path.to_str() {
Some(key) => artifacts_file_hash_map
Expand Down
32 changes: 16 additions & 16 deletions compiler/crates/relay-typegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub use relay_config::TypegenConfig;
pub use relay_config::TypegenLanguage;
use relay_transforms::UPDATABLE_DIRECTIVE;
use schema::SDLSchema;
pub use typegen_state::FragmentLocations;
pub use typegen_state::FragmentInfoLookup;
pub use write::has_raw_response_type_directive;
use write::write_fragment_type_exports_section;
use write::write_operation_type_exports_section;
Expand Down Expand Up @@ -113,13 +113,13 @@ pub fn generate_fragment_type_exports_section_from_extra_artifact(
fragment_definition: &FragmentDefinition,
schema: &SDLSchema,
project_config: &ProjectConfig,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> String {
generate_fragment_type_exports_section_impl(
fragment_definition,
schema,
project_config,
fragment_locations,
fragment_lookup,
true,
)
}
Expand All @@ -128,13 +128,13 @@ pub fn generate_fragment_type_exports_section(
fragment_definition: &FragmentDefinition,
schema: &SDLSchema,
project_config: &ProjectConfig,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> String {
generate_fragment_type_exports_section_impl(
fragment_definition,
schema,
project_config,
fragment_locations,
fragment_lookup,
false,
)
}
Expand All @@ -143,7 +143,7 @@ fn generate_fragment_type_exports_section_impl(
fragment_definition: &FragmentDefinition,
schema: &SDLSchema,
project_config: &ProjectConfig,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
is_extra_artifact_branch_module: bool,
) -> String {
let typegen_context = TypegenContext::new(
Expand All @@ -154,7 +154,7 @@ fn generate_fragment_type_exports_section_impl(
.named(*UPDATABLE_DIRECTIVE)
.is_some(),
fragment_definition.name.map(|x| x.0),
fragment_locations,
fragment_lookup,
TypegenOptions {
no_optional_fields_in_raw_response_type: false,
is_extra_artifact_branch_module,
Expand All @@ -170,7 +170,7 @@ pub fn generate_named_validator_export(
fragment_definition: &FragmentDefinition,
schema: &SDLSchema,
project_config: &ProjectConfig,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
) -> String {
let typegen_context = TypegenContext::new(
schema,
Expand All @@ -180,7 +180,7 @@ pub fn generate_named_validator_export(
.named(*UPDATABLE_DIRECTIVE)
.is_some(),
fragment_definition.name.map(|x| x.0),
fragment_locations,
fragment_lookup,
TypegenOptions {
no_optional_fields_in_raw_response_type: false,
is_extra_artifact_branch_module: false,
Expand All @@ -205,7 +205,7 @@ pub fn generate_operation_type_exports_section(
normalization_operation: &OperationDefinition,
schema: &SDLSchema,
project_config: &ProjectConfig,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
maybe_provided_variables: Option<String>,
) -> String {
let typegen_context = TypegenContext::new(
Expand All @@ -219,7 +219,7 @@ pub fn generate_operation_type_exports_section(
typegen_operation.name.location,
typegen_operation.name.item.0,
),
fragment_locations,
fragment_lookup,
TypegenOptions {
no_optional_fields_in_raw_response_type: false,
is_extra_artifact_branch_module: false,
Expand All @@ -242,7 +242,7 @@ pub fn generate_split_operation_type_exports_section(
normalization_operation: &OperationDefinition,
schema: &SDLSchema,
project_config: &ProjectConfig,
fragment_locations: &FragmentLocations,
fragment_lookup: &FragmentInfoLookup,
no_optional_fields_in_raw_response_type: bool,
) -> String {
let typegen_context = TypegenContext::new(
Expand All @@ -256,7 +256,7 @@ pub fn generate_split_operation_type_exports_section(
typegen_operation.name.location,
typegen_operation.name.item.0,
),
fragment_locations,
fragment_lookup,
TypegenOptions {
no_optional_fields_in_raw_response_type,
is_extra_artifact_branch_module: false,
Expand All @@ -279,7 +279,7 @@ pub fn generate_split_operation_type_exports_section(
struct TypegenContext<'a> {
schema: &'a SDLSchema,
project_config: &'a ProjectConfig,
fragment_locations: &'a FragmentLocations,
fragment_lookup: &'a FragmentInfoLookup,
has_unified_output: bool,
generating_updatable_types: bool,
definition_source_location: WithLocation<StringKey>,
Expand All @@ -292,13 +292,13 @@ impl<'a> TypegenContext<'a> {
project_config: &'a ProjectConfig,
generating_updatable_types: bool,
definition_source_location: WithLocation<StringKey>,
fragment_locations: &'a FragmentLocations,
fragment_lookup: &'a FragmentInfoLookup,
typegen_options: TypegenOptions,
) -> Self {
Self {
schema,
project_config,
fragment_locations,
fragment_lookup,
has_unified_output: project_config.output.is_some(),
generating_updatable_types,
definition_source_location,
Expand Down
Loading
Loading