Skip to content

Commit

Permalink
Back out "Revert D54206758: [relay][PR] Validate edgeTypeName argumen…
Browse files Browse the repository at this point in the history
…t points to an existing type"

Reviewed By: tyao1

Differential Revision: D58677254

fbshipit-source-id: 70d98778daec367d77ba358dd12b68172bb7afbf
  • Loading branch information
captbaritone authored and facebook-github-bot committed Jun 20, 2024
1 parent 6150200 commit 8badceb
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 10 deletions.
4 changes: 4 additions & 0 deletions compiler/crates/common/src/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub struct FeatureFlags {
/// in @refetchable transform
#[serde(default)]
pub prefer_fetchable_in_refetch_queries: bool,

/// Disable validation of the `edgeTypeName` argument on `@prependNode` and `@appendNode`.
#[serde(default)]
pub disable_edge_type_name_validation_on_declerative_connection_directives: FeatureFlag,
}

fn default_as_true() -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
==================================== INPUT ====================================
# expected-to-throw

mutation appendNodeLiteralEdgeTypeNameInvalidCommentCreateMutation(
$connections: [ID!]!
$input: CommentCreateInput
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: "CommentEdge") {
id
}
}
}
==================================== ERROR ====================================
✖︎ Expected the 'edgeTypeName' argument value on @appendNode to be the name of an object type. 'CommentEdge' does not refer to a known object type. Did you mean `CommentsEdge`, `Comment`, or `SegmentsEdge`?

append-node-literal-edge-type-name-invalid.graphql:9:60
8 │ comment
9 │ @appendNode(connections: $connections, edgeTypeName: "CommentEdge") {
│ ^^^^^^^^^^^^^
10 │ id
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# expected-to-throw

mutation appendNodeLiteralEdgeTypeNameInvalidCommentCreateMutation(
$connections: [ID!]!
$input: CommentCreateInput
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: "CommentEdge") {
id
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
==================================== INPUT ====================================
# expected-to-throw

mutation appendNodeLiteralEdgeTypeNameNotObjectTypeMutation(
$connections: [ID!]!
$input: CommentCreateInput
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: "Node") {
id
}
}
}
==================================== ERROR ====================================
✖︎ Expected the 'edgeTypeName' argument value on @appendNode to be the name of an object type. 'Node' does not refer to a known object type.

append-node-literal-edge-type-name-not-object-type.graphql:9:60
8 │ comment
9 │ @appendNode(connections: $connections, edgeTypeName: "Node") {
│ ^^^^^^
10 │ id
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# expected-to-throw

mutation appendNodeLiteralEdgeTypeNameNotObjectTypeMutation(
$connections: [ID!]!
$input: CommentCreateInput
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: "Node") {
id
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
==================================== INPUT ====================================
mutation appendNodeLiteralEdgeTypeNameVariableMutation(
$connections: [ID!]!
$input: CommentCreateInput
$edgeTypeName: String!
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: $edgeTypeName) {
id
}
}
}
==================================== OUTPUT ===================================
{
"fragment": {
"argumentDefinitions": [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "connections"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "edgeTypeName"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
"kind": "Fragment",
"metadata": null,
"name": "appendNodeLiteralEdgeTypeNameVariableMutation",
"selections": [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "CommentCreateResponsePayload",
"kind": "LinkedField",
"name": "commentCreate",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Comment",
"kind": "LinkedField",
"name": "comment",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
],
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "connections"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "edgeTypeName"
}
],
"kind": "Operation",
"name": "appendNodeLiteralEdgeTypeNameVariableMutation",
"selections": [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "CommentCreateResponsePayload",
"kind": "LinkedField",
"name": "commentCreate",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Comment",
"kind": "LinkedField",
"name": "comment",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"filters": null,
"handle": "appendNode",
"key": "",
"kind": "LinkedHandle",
"name": "comment",
"handleArgs": [
{
"kind": "Variable",
"name": "connections",
"variableName": "connections"
},
{
"kind": "Variable",
"name": "edgeTypeName",
"variableName": "edgeTypeName"
}
]
}
],
"storageKey": null
}
]
},
"params": {
"cacheID": "c6c4a56d7ea1db74c1935491b7a2e10a",
"id": null,
"metadata": {},
"name": "appendNodeLiteralEdgeTypeNameVariableMutation",
"operationKind": "mutation",
"text": null
}
}

QUERY:

mutation appendNodeLiteralEdgeTypeNameVariableMutation(
$input: CommentCreateInput
) {
commentCreate(input: $input) {
comment {
id
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mutation appendNodeLiteralEdgeTypeNameVariableMutation(
$connections: [ID!]!
$input: CommentCreateInput
$edgeTypeName: String!
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: $edgeTypeName) {
id
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mutation appendNodeLiteralEdgeTypeNameCommentCreateMutation(
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: "CommentEdge") {
@appendNode(connections: $connections, edgeTypeName: "CommentsEdge") {
id
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ mutation appendNodeLiteralEdgeTypeNameCommentCreateMutation(
{
"kind": "Literal",
"name": "edgeTypeName",
"value": "CommentEdge"
"value": "CommentsEdge"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mutation appendNodeLiteralEdgeTypeNameCommentCreateMutation(
) {
commentCreate(input: $input) {
comment
@appendNode(connections: $connections, edgeTypeName: "CommentEdge") {
@appendNode(connections: $connections, edgeTypeName: "CommentsEdge") {
id
}
}
Expand Down
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<<742eb57a3eb061bcf247ff05572ac49d>>
* @generated SignedSource<<a462cf5b6b402f99514438fe2a6c56fe>>
*/

mod compile_relay_artifacts;
Expand Down Expand Up @@ -145,6 +145,27 @@ async fn append_node_literal_edge_type_name() {
test_fixture(transform_fixture, file!(), "append-node-literal-edge-type-name.graphql", "compile_relay_artifacts/fixtures/append-node-literal-edge-type-name.expected", input, expected).await;
}

#[tokio::test]
async fn append_node_literal_edge_type_name_invalid() {
let input = include_str!("compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-invalid.graphql");
let expected = include_str!("compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-invalid.expected");
test_fixture(transform_fixture, file!(), "append-node-literal-edge-type-name-invalid.graphql", "compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-invalid.expected", input, expected).await;
}

#[tokio::test]
async fn append_node_literal_edge_type_name_not_object_type() {
let input = include_str!("compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-not-object-type.graphql");
let expected = include_str!("compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-not-object-type.expected");
test_fixture(transform_fixture, file!(), "append-node-literal-edge-type-name-not-object-type.graphql", "compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-not-object-type.expected", input, expected).await;
}

#[tokio::test]
async fn append_node_literal_edge_type_name_variable() {
let input = include_str!("compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-variable.graphql");
let expected = include_str!("compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-variable.expected");
test_fixture(transform_fixture, file!(), "append-node-literal-edge-type-name-variable.graphql", "compile_relay_artifacts/fixtures/append-node-literal-edge-type-name-variable.expected", input, expected).await;
}

#[tokio::test]
async fn auto_filled_argument_on_defer() {
let input = include_str!("compile_relay_artifacts/fixtures/auto-filled-argument-on-defer.graphql");
Expand Down
1 change: 1 addition & 0 deletions compiler/crates/relay-transforms/src/apply_transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ fn apply_operation_transforms(
transform_declarative_connection(
&program,
&project_config.schema_config.connection_interface,
&project_config.feature_flags,
)
})?;

Expand Down
Loading

0 comments on commit 8badceb

Please sign in to comment.