Skip to content

Commit

Permalink
Improve error messages related to @refetchable
Browse files Browse the repository at this point in the history
Summary:
* Improve error messages related to refetchable
* Note that our logic is wrong:
  * It looks like we currently accept interfaces, as long as all of their (directly) implementing objects implement Node. However, an interface is an "open" union, i.e. there could always be new concrete types that implement a given interface that we receive at runtime! These new types may not implement node, and we may not be able to refetch them.
* There is also the separate bug that we should probably correctly handle recursively implementing objects, but that's a new addition so it makes sense that this bug exists.

Reviewed By: tyao1

Differential Revision: D41507465

fbshipit-source-id: 99f3cf6d3603e5a6a4cf490d61b8115a6dbf36f1
  • Loading branch information
Robert Balicki authored and facebook-github-bot committed Nov 29, 2022
1 parent bf8fa2f commit 8eea4aa
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ fn enforce_selections_with_id_field(
}

pub const FETCHABLE_QUERY_GENERATOR: QueryGenerator = QueryGenerator {
description: "@fetchable type",
// T138625502 we should support interfaces and maybe unions
description: "server objects with the @fetchable directive",
build_refetch_operation,
};
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,6 @@ fn enforce_selections_with_id_field(
}

pub const NODE_QUERY_GENERATOR: QueryGenerator = QueryGenerator {
description: "the Node interface or types implementing the Node interface",
description: "the Node interface, object types that implement the Node interface, interfaces whose implementing objects all implement Node, and unions whose members all implement Node",
build_refetch_operation,
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ fragment UserName on UserNameRenderable
✖︎ Invalid use of @refetchable on fragment 'UserName', only supported are fragments on:
- the Viewer type
- the Query type
- the Node interface or types implementing the Node interface
- @fetchable type
- the Node interface, object types that implement the Node interface, interfaces whose implementing objects all implement Node, and unions whose members all implement Node
- server objects with the @fetchable directive

fragment-on-interface-which-implmentations-not-implement-node.invalid.graphql:2:10
fragment-on-interface-which-implementations-not-implement-node.invalid.graphql:2:10
1 │ # expected-to-throw
2 │ fragment UserName on UserNameRenderable
│ ^^^^^^^^
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<<8cfbe364f914c89ce9b2405a88713948>>
* @generated SignedSource<<a4ac9b5a5be2f2b7e2e1b3dc40f11ab3>>
*/

mod refetchable_fragment;
Expand All @@ -13,17 +13,17 @@ use refetchable_fragment::transform_fixture;
use fixture_tests::test_fixture;

#[test]
fn fragment_on_interface_which_implmentations_implement_node() {
let input = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implmentations-implement-node.graphql");
let expected = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implmentations-implement-node.expected");
test_fixture(transform_fixture, "fragment-on-interface-which-implmentations-implement-node.graphql", "refetchable_fragment/fixtures/fragment-on-interface-which-implmentations-implement-node.expected", input, expected);
fn fragment_on_interface_which_implementations_implement_node() {
let input = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implementations-implement-node.graphql");
let expected = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implementations-implement-node.expected");
test_fixture(transform_fixture, "fragment-on-interface-which-implementations-implement-node.graphql", "refetchable_fragment/fixtures/fragment-on-interface-which-implementations-implement-node.expected", input, expected);
}

#[test]
fn fragment_on_interface_which_implmentations_not_implement_node_invalid() {
let input = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implmentations-not-implement-node.invalid.graphql");
let expected = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implmentations-not-implement-node.invalid.expected");
test_fixture(transform_fixture, "fragment-on-interface-which-implmentations-not-implement-node.invalid.graphql", "refetchable_fragment/fixtures/fragment-on-interface-which-implmentations-not-implement-node.invalid.expected", input, expected);
fn fragment_on_interface_which_implementations_not_implement_node_invalid() {
let input = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implementations-not-implement-node.invalid.graphql");
let expected = include_str!("refetchable_fragment/fixtures/fragment-on-interface-which-implementations-not-implement-node.invalid.expected");
test_fixture(transform_fixture, "fragment-on-interface-which-implementations-not-implement-node.invalid.graphql", "refetchable_fragment/fixtures/fragment-on-interface-which-implementations-not-implement-node.invalid.expected", input, expected);
}

#[test]
Expand Down

0 comments on commit 8eea4aa

Please sign in to comment.