Skip to content

Commit

Permalink
Add fixture test to assert we don't allow duplicate resolver definitions
Browse files Browse the repository at this point in the history
Summary: * Add a fixture asserting we don't allow duplicate resolver definitions

Reviewed By: captbaritone

Differential Revision: D44265525

fbshipit-source-id: 7022f4925fe03db6428005a7d68048e5afe069e2
  • Loading branch information
Robert Balicki authored and facebook-github-bot committed Mar 27, 2023
1 parent 35fea88 commit 0466d31
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
==================================== INPUT ====================================
/**
* 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.
*/

// expected-to-throw

/**
* @RelayResolver User.favorite_page: Page
* @rootFragment myRootFragment
*
* The user's favorite page! They probably clicked something in the UI
* to tell us that it was their favorite page and then we put that in a
* database or something. Then we got that info out again and put it out
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
*/
graphql`
fragment myRootFragment on User {
name
}
`

/**
* @RelayResolver User.favorite_page: Page
* @rootFragment myRootFragment2
*
* The user's favorite page! They probably clicked something in the UI
* to tell us that it was their favorite page and then we put that in a
* database or something. Then we got that info out again and put it out
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
*/
graphql`
fragment myRootFragment2 on User {
name
}
`
==================================== ERROR ====================================
✖︎ Duplicate field definition 'favorite_page' found.

/path/to/test/fixture/terse-resolver-duplicated.invalid.js:2:23
1 │ *
2 │ * @RelayResolver User.favorite_page: Page
│ ^^^^^^^^^^^^^
3 │ * @rootFragment myRootFragment2

ℹ︎ previously defined here

/path/to/test/fixture/terse-resolver-duplicated.invalid.js:2:24
1 │ *
2 │ * @RelayResolver User.favorite_page: Page
│ ^^^^^^^^^^^^^
3 │ * @rootFragment myRootFragment2
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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.
*/

// expected-to-throw

/**
* @RelayResolver User.favorite_page: Page
* @rootFragment myRootFragment
*
* The user's favorite page! They probably clicked something in the UI
* to tell us that it was their favorite page and then we put that in a
* database or something. Then we got that info out again and put it out
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
*/
graphql`
fragment myRootFragment on User {
name
}
`

/**
* @RelayResolver User.favorite_page: Page
* @rootFragment myRootFragment2
*
* The user's favorite page! They probably clicked something in the UI
* to tell us that it was their favorite page and then we put that in a
* database or something. Then we got that info out again and put it out
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
*/
graphql`
fragment myRootFragment2 on User {
name
}
`
9 changes: 8 additions & 1 deletion compiler/crates/relay-docblock/tests/to_schema_test.rs
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<<8cf2bea87a87f4c48d8c0b53b4e0c616>>
* @generated SignedSource<<8c829590b9a20caf63439cd36a113237>>
*/

mod to_schema;
Expand Down Expand Up @@ -243,6 +243,13 @@ fn terse_relay_resolver_with_output_type() {
test_fixture(transform_fixture, "terse-relay-resolver-with-output-type.js", "to_schema/fixtures/terse-relay-resolver-with-output-type.expected", input, expected);
}

#[test]
fn terse_resolver_duplicated_invalid() {
let input = include_str!("to_schema/fixtures/terse-resolver-duplicated.invalid.js");
let expected = include_str!("to_schema/fixtures/terse-resolver-duplicated.invalid.expected");
test_fixture(transform_fixture, "terse-resolver-duplicated.invalid.js", "to_schema/fixtures/terse-resolver-duplicated.invalid.expected", input, expected);
}

#[test]
fn weak_type() {
let input = include_str!("to_schema/fixtures/weak-type.js");
Expand Down

0 comments on commit 0466d31

Please sign in to comment.