Skip to content

Commit

Permalink
Allow @dangerously_unaliased on @inline fragments
Browse files Browse the repository at this point in the history
Reviewed By: gordyf

Differential Revision: D64069021

fbshipit-source-id: 9214e0bfe956f47e9fece6c3db81b4ffdc10247c
  • Loading branch information
captbaritone authored and facebook-github-bot committed Oct 8, 2024
1 parent 2cf6c7f commit 5c548bd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
10 changes: 5 additions & 5 deletions compiler/crates/relay-transforms/src/inline_data_fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use lazy_static::lazy_static;
use thiserror::Error;

use crate::fragment_alias_directive::FRAGMENT_ALIAS_DIRECTIVE_NAME;
use crate::fragment_alias_directive::FRAGMENT_DANGEROUSLY_UNALIAS_DIRECTIVE_NAME;

lazy_static! {
pub static ref INLINE_DIRECTIVE_NAME: DirectiveName = DirectiveName("inline".intern());
Expand Down Expand Up @@ -67,11 +68,10 @@ impl<'s> InlineDataFragmentsTransform<'s> {
inline_directive: &Directive,
spread: &FragmentSpread,
) {
if let Some(not_allowed_directive) = spread
.directives
.iter()
.find(|directive| directive.name.item != *FRAGMENT_ALIAS_DIRECTIVE_NAME)
{
if let Some(not_allowed_directive) = spread.directives.iter().find(|directive| {
directive.name.item != *FRAGMENT_ALIAS_DIRECTIVE_NAME
&& directive.name.item != *FRAGMENT_DANGEROUSLY_UNALIAS_DIRECTIVE_NAME
}) {
self.errors.push(
Diagnostic::error(
ValidationMessage::InlineDataFragmentDirectivesNotSupported {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
==================================== INPUT ====================================
fragment User on User {
...UserName @dangerously_unaliased_fixme
}

fragment UserName on User @inline {
name
}
==================================== OUTPUT ===================================
fragment User on User {
... @__InlineDirectiveMetadata
# InlineDirectiveMetadata {
# fragment_name: FragmentDefinitionName(
# "UserName",
# ),
# arguments: [],
# variable_definitions: [],
# used_global_variables: [],
# }
{
... on User {
name
}
}
}

fragment UserName on User @inline {
name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fragment User on User {
...UserName @dangerously_unaliased_fixme
}

fragment UserName on User @inline {
name
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e779a3c82aab3df8d15ef5462a13009b>>
* @generated SignedSource<<238b6fdb89e0e9b03d9470ea14326584>>
*/

mod inline_data_fragment;
Expand All @@ -19,6 +19,13 @@ async fn alias() {
test_fixture(transform_fixture, file!(), "alias.graphql", "inline_data_fragment/fixtures/alias.expected", input, expected).await;
}

#[tokio::test]
async fn dangerously_unaliased() {
let input = include_str!("inline_data_fragment/fixtures/dangerously_unaliased.graphql");
let expected = include_str!("inline_data_fragment/fixtures/dangerously_unaliased.expected");
test_fixture(transform_fixture, file!(), "dangerously_unaliased.graphql", "inline_data_fragment/fixtures/dangerously_unaliased.expected", input, expected).await;
}

#[tokio::test]
async fn recursive() {
let input = include_str!("inline_data_fragment/fixtures/recursive.graphql");
Expand Down

0 comments on commit 5c548bd

Please sign in to comment.