Skip to content

Commit 59ae292

Browse files
lynnshaoyufacebook-github-bot
authored andcommitted
- handle local variables vs global variables in prefetch pagination
Reviewed By: tyao1 Differential Revision: D67991324 fbshipit-source-id: 75b940e993e57edc59457009ad0c3dd987ea03d9
1 parent 3bec307 commit 59ae292

11 files changed

+1277
-67
lines changed

compiler/crates/graphql-ir/src/ir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ pub type FragmentDefinitionNameSet = HashSet<FragmentDefinitionName, BuildIdHash
151151
#[derive(Clone, Debug, Eq, PartialEq)]
152152
pub struct FragmentDefinition {
153153
pub name: WithLocation<FragmentDefinitionName>,
154+
/// Local variables defined in the fragment using the `@argumentDefinitions` directive.
154155
pub variable_definitions: Vec<VariableDefinition>,
156+
/// Global variables that are used but NOT defined within the fragment (they can come from a parent query or fragment).
155157
pub used_global_variables: Vec<VariableDefinition>,
156158
pub type_condition: Type,
157159
pub directives: Vec<Directive>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
==================================== INPUT ====================================
2+
# expected-to-throw
3+
4+
query prefetchablePaginationQueryWithConflictingArgsQuery($site: String) {
5+
node(id: "x") {
6+
...prefetchablePaginationQueryWithConflictingArgs_FirstFragment @arguments(site: $site)
7+
}
8+
}
9+
10+
fragment prefetchablePaginationQueryWithConflictingArgs_FirstFragment on Node
11+
@refetchable(queryName: "RefetchableFragmentQuery")
12+
@argumentDefinitions(
13+
count: {type: "Int", defaultValue: 10}
14+
cursor: {type: "ID"}
15+
site: {type: "String"}
16+
) {
17+
id
18+
...prefetchablePaginationQueryWithConflictingArgs_SecondFragment
19+
... on User {
20+
name
21+
friends(after: $cursor, first: $count)
22+
@connection(key: "PaginationFragment_friends", prefetchable_pagination: true) {
23+
edges {
24+
node {
25+
id
26+
# local $site
27+
url(site: $site)
28+
}
29+
}
30+
}
31+
}
32+
}
33+
34+
fragment prefetchablePaginationQueryWithConflictingArgs_SecondFragment on Node {
35+
# global $site
36+
p2: url(site: $site)
37+
}
38+
==================================== ERROR ====================================
39+
✖︎ Fragment variable `$site` conflicts with a global variable generated by the @refetchable generated query
40+
41+
prefetchable-pagination-query-with-conflicting-args.invalid.graphql:14:5
42+
13 │ cursor: {type: "ID"}
43+
14 │ site: {type: "String"}
44+
│ ^^^^
45+
15 │ ) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# expected-to-throw
2+
3+
query prefetchablePaginationQueryWithConflictingArgsQuery($site: String) {
4+
node(id: "x") {
5+
...prefetchablePaginationQueryWithConflictingArgs_FirstFragment @arguments(site: $site)
6+
}
7+
}
8+
9+
fragment prefetchablePaginationQueryWithConflictingArgs_FirstFragment on Node
10+
@refetchable(queryName: "RefetchableFragmentQuery")
11+
@argumentDefinitions(
12+
count: {type: "Int", defaultValue: 10}
13+
cursor: {type: "ID"}
14+
site: {type: "String"}
15+
) {
16+
id
17+
...prefetchablePaginationQueryWithConflictingArgs_SecondFragment
18+
... on User {
19+
name
20+
friends(after: $cursor, first: $count)
21+
@connection(key: "PaginationFragment_friends", prefetchable_pagination: true) {
22+
edges {
23+
node {
24+
id
25+
# local $site
26+
url(site: $site)
27+
}
28+
}
29+
}
30+
}
31+
}
32+
33+
fragment prefetchablePaginationQueryWithConflictingArgs_SecondFragment on Node {
34+
# global $site
35+
p2: url(site: $site)
36+
}

0 commit comments

Comments
 (0)