Skip to content

Commit

Permalink
Correctly remove RefetchableFragment artifacts for ClientEdges in inc…
Browse files Browse the repository at this point in the history
…remental mode.

Summary:
The root cause of the issue was an incorrect artifact mapping from the source to the generated artifacts for a fragment.

For `RefetchableFragments` generated for client-edge queries the source was the name of the virtually created fragment, where we should be using the original "client-edge" fragment spread source.

Interestingly, we already have a special case for these client-edge generated fragments, where their source hash (see the directive CLIENT_EDGE_GENERATED_FRAGMENT_KEY) was generated for the "client-edge".

This diff also passes this `source_name` to the reader's `source_definition_names`, which later will be used in the compiler's artifact map to correctly attribute generated artifacts to their source fragments.

Reviewed By: josephsavona

Differential Revision: D37116613

fbshipit-source-id: 3bccc96a5358dd53ab8f114407e07239f37a56c5
  • Loading branch information
alunyov authored and facebook-github-bot committed Jun 14, 2022
1 parent 6b7c7b2 commit 735c496
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ pub fn generate_artifacts(
};

let source_hash = source_hashes.get(&source_name).cloned().unwrap();
generate_reader_artifact(project_config, programs, reader_fragment, source_hash)
let source_definition_names = vec![source_name];
generate_reader_artifact(
project_config,
programs,
reader_fragment,
source_hash,
source_definition_names,
)
}))
.collect();
}
Expand Down Expand Up @@ -212,14 +219,15 @@ fn generate_reader_artifact(
programs: &Programs,
reader_fragment: &Arc<FragmentDefinition>,
source_hash: String,
source_definition_names: Vec<StringKey>,
) -> Artifact {
let name = reader_fragment.name.item;
let typegen_fragment = programs
.typegen
.fragment(name)
.expect("a type fragment should be generated for this fragment");
Artifact {
source_definition_names: vec![name],
source_definition_names,
path: project_config
.path_for_artifact(reader_fragment.name.location.source_location(), name),
content: ArtifactContent::Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Relay Resolver', () => {
expect(data.me.name).toEqual(undefined); // Fields needed by resolver's fragment don't end up in the result
});

it('can create a client edge query in our test enviornment that has valid import', () => {
it('can create a client edge query in our test environment that has valid import', () => {
// This is not really a runtime test, but more a test to confirm that this query generates
// an artifact with valid imports in our non-Haste test environment.
const clientEdgeRuntimeArtifact = graphql`
Expand Down

0 comments on commit 735c496

Please sign in to comment.