-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude updatable queries from operation transforms pipeline
Summary: Updatable queries do not get sent to the server. Consider usePrivacyIncidentFactGatheringContentStateQuery.graphql.js. The generated artifact only includes fragment and kind fields, i.e. no operation and no metadata. As a consequence, all of the work that we do to updatable queries in the `apply_operation_transforms`, `apply_normalization_transforms`, and `apply_operation_text_transforms` pipelines in apply_transforms.rs: * is useless, since the results aren't used * are actively harmful, in that the transforms in this pipeline enforce certain invariants that make no sense. e.g. updatable queries with only client only fields are disallowed — but that is in fact fine! This change modifies the underpinnings to properly skip client-side-only `updatable` Queries. The core problem of erroring out remains, since other logic causes empty queries to panic. Reviewed By: rbalicki2 Differential Revision: D38132333 fbshipit-source-id: f1dea8f449ac9d5d289edaadcbdad18e1ee27987
- Loading branch information
1 parent
168a9fc
commit 44ecca8
Showing
4 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
compiler/crates/relay-transforms/src/skip_updatable_queries.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use crate::UPDATABLE_DIRECTIVE; | ||
use common::Named; | ||
use graphql_ir::OperationDefinition; | ||
use graphql_ir::Program; | ||
use graphql_ir::Transformed; | ||
use graphql_ir::Transformer; | ||
|
||
pub fn skip_updatable_queries(program: &Program) -> Program { | ||
let mut transform = SkipUpdatableQueries::new(program); | ||
let transformed = transform.transform_program(program); | ||
|
||
transformed.replace_or_else(|| program.clone()) | ||
} | ||
|
||
#[allow(dead_code)] | ||
struct SkipUpdatableQueries<'s> { | ||
program: &'s Program, | ||
} | ||
|
||
impl<'s> SkipUpdatableQueries<'s> { | ||
fn new(program: &'s Program) -> Self { | ||
Self { program } | ||
} | ||
} | ||
|
||
impl<'s> Transformer for SkipUpdatableQueries<'s> { | ||
const NAME: &'static str = "SkipUpdatableQueriesTransform"; | ||
const VISIT_ARGUMENTS: bool = false; | ||
const VISIT_DIRECTIVES: bool = true; | ||
|
||
fn transform_operation( | ||
&mut self, | ||
operation: &OperationDefinition, | ||
) -> Transformed<OperationDefinition> { | ||
if operation | ||
.directives | ||
.iter() | ||
.any(|directive| directive.name() == *UPDATABLE_DIRECTIVE) | ||
{ | ||
Transformed::Delete | ||
} else { | ||
Transformed::Keep | ||
} | ||
} | ||
} |