Skip to content

Commit

Permalink
Add test with conflicting client fields
Browse files Browse the repository at this point in the history
Summary: Add a test-case that demonstrates a bug in the relay-compiler where we do not validate conflicts in client fields.

Reviewed By: tyao1

Differential Revision: D37069157

fbshipit-source-id: 2e3210abd9ea1cecbde7acfeb8761aa715a330b1
  • Loading branch information
alunyov authored and facebook-github-bot committed Jun 13, 2022
1 parent 0d173d6 commit 1450153
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'s, B: LocationAgnosticBehavior + Sync> ValidateSelectionConflict<'s, B> {
fn validate_program(&self, program: &'s Program) -> DiagnosticsResult<()> {
// NOTE: Fragments may be visited multiple times due to the parallel traversal for
// operations! Today the extra overhead is acceptable, compared to single thread
// `try_map` for opeartions.
// `try_map` for operations.
// TODO: visit the fragments in parallel with topology order before visiting the operations.
par_try_map(&program.operations, |operation| {
self.validate_operation(operation)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
==================================== INPUT ====================================
query clientFieldsOverlappingErrorQuery {
client_field(arg: "Value1")
client_field(arg: "Value2")
}

# %extensions%

extend type Query {
client_field(arg: String): String
}
==================================== OUTPUT ===================================
{
"fragment": {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "clientFieldsOverlappingErrorQuery",
"selections": [
{
"kind": "ClientExtension",
"selections": [
{
"alias": null,
"args": [
{
"kind": "Literal",
"name": "arg",
"value": "Value1"
}
],
"kind": "ScalarField",
"name": "client_field",
"storageKey": "client_field(arg:\"Value1\")"
}
]
}
],
"type": "Query",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": [],
"kind": "Operation",
"name": "clientFieldsOverlappingErrorQuery",
"selections": [
{
"kind": "ClientExtension",
"selections": [
{
"alias": null,
"args": [
{
"kind": "Literal",
"name": "arg",
"value": "Value1"
}
],
"kind": "ScalarField",
"name": "client_field",
"storageKey": "client_field(arg:\"Value1\")"
}
]
}
]
},
"params": {
"cacheID": "94883f2a9cbd52c2f01b84f026506e89",
"id": null,
"metadata": {},
"name": "clientFieldsOverlappingErrorQuery",
"operationKind": "query",
"text": null
}
}

QUERY:

Query Text is Empty.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query clientFieldsOverlappingErrorQuery {
client_field(arg: "Value1")
client_field(arg: "Value2")
}

# %extensions%

extend type Query {
client_field(arg: String): String
}
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<<59b1c85f3ba2eb81497bc11cbebf03d1>>
* @generated SignedSource<<bb7596b7998f023dd0b3b055928030cb>>
*/

mod compile_relay_artifacts;
Expand Down Expand Up @@ -215,6 +215,13 @@ fn client_fields_only_no_fragment_invalid() {
test_fixture(transform_fixture, "client_fields_only_no_fragment_invalid.graphql", "compile_relay_artifacts/fixtures/client_fields_only_no_fragment_invalid.expected", input, expected);
}

#[test]
fn client_fields_overlapping_error_invalid() {
let input = include_str!("compile_relay_artifacts/fixtures/client-fields-overlapping-error.invalid.graphql");
let expected = include_str!("compile_relay_artifacts/fixtures/client-fields-overlapping-error.invalid.expected");
test_fixture(transform_fixture, "client-fields-overlapping-error.invalid.graphql", "compile_relay_artifacts/fixtures/client-fields-overlapping-error.invalid.expected", input, expected);
}

#[test]
fn client_fragment_spreads() {
let input = include_str!("compile_relay_artifacts/fixtures/client-fragment-spreads.graphql");
Expand Down

0 comments on commit 1450153

Please sign in to comment.