Skip to content

Commit

Permalink
Add location to the SplitOperationMetadata
Browse files Browse the repository at this point in the history
Summary:
This diffs add `location` (location of the source file for the split operation) to the SplitOperationMetadata.

- We can use this location directly in the codegen, instead of a fragment lookup.
- This will also be used for split operations that are derived from generated sources (I'm planning to use this for the D38426796 - relay resolvers that want to return nested objects)

Reviewed By: rbalicki2

Differential Revision: D39135955

fbshipit-source-id: cf75248231660c0f7759d027ba3a1dd5794ddb7f
  • Loading branch information
alunyov authored and facebook-github-bot committed Sep 6, 2022
1 parent 9f400b6 commit 6efa1a0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ pub fn generate_artifacts(
{
// Generate normalization file for SplitOperation
let metadata = SplitOperationMetadata::from(directive);
let source_fragment = programs
.source
.fragment(metadata.derived_from)
.expect("Expected the source document for the SplitOperation to exist.");
let source_hash = source_hashes.get(&metadata.derived_from.0).cloned().unwrap();
let source_file = source_fragment.name.location.source_location();
let source_file = metadata.location.source_location();
let typegen_operation = if metadata.raw_response_type {
Some(Arc::clone(normalization))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ impl ApplyFragmentArgumentsTransform<'_, '_, '_> {
}
let mut metadata = SplitOperationMetadata {
derived_from: fragment.name.item,
location: fragment.name.location,
parent_documents: Default::default(),
raw_response_type: is_raw_response_type_enabled(directive),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl Transformer for SplitModuleImportTransform<'_, '_> {
(
SplitOperationMetadata {
derived_from: module_metadata.fragment_name,
location: module_metadata.location,
parent_documents: Default::default(),
raw_response_type: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use common::ArgumentName;
use common::DirectiveName;
use common::Location;
use common::NamedItem;
use common::WithLocation;
use graphql_ir::Argument;
Expand Down Expand Up @@ -53,6 +54,9 @@ pub struct SplitOperationMetadata {
/// to determine the name of the generated artifact.
pub derived_from: FragmentDefinitionName,

/// Location of the source file for this split operation
pub location: Location,

/// The names of the fragments and operations that included this fragment.
/// They are the reason this split operation exist. If they are all removed,
/// this file also needs to be removed.
Expand Down Expand Up @@ -89,7 +93,7 @@ impl SplitOperationMetadata {
});
}
Directive {
name: WithLocation::generated(*DIRECTIVE_SPLIT_OPERATION),
name: WithLocation::new(self.location, *DIRECTIVE_SPLIT_OPERATION),
arguments,
data: None,
}
Expand All @@ -99,10 +103,12 @@ impl SplitOperationMetadata {
impl From<&Directive> for SplitOperationMetadata {
fn from(directive: &Directive) -> Self {
debug_assert!(directive.name.item == *DIRECTIVE_SPLIT_OPERATION);
let location = directive.name.location;
let derived_from_arg = directive
.arguments
.named(ARG_DERIVED_FROM.0)
.expect("Expected derived_from arg to exist");

let derived_from =
FragmentDefinitionName(derived_from_arg.value.item.expect_string_literal());
let parent_documents_arg = directive
Expand All @@ -127,6 +133,7 @@ impl From<&Directive> for SplitOperationMetadata {
.collect();
Self {
derived_from,
location,
parent_documents,
raw_response_type,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl<'program, 'flag> RelayClientComponentTransform<'program, 'flag> {
(
SplitOperationMetadata {
derived_from: spread.fragment.item,
location: spread.fragment.location,
parent_documents: Default::default(),
raw_response_type: false,
},
Expand Down

0 comments on commit 6efa1a0

Please sign in to comment.