Skip to content

Commit a5a48a6

Browse files
committed
add initialCount support to rust compiler
1 parent 9e9c8ab commit a5a48a6

File tree

13 files changed

+146
-3
lines changed

13 files changed

+146
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub enum ValidationMessage {
356356
#[error("Invalid use of @stream on scalar field '{field_name}'")]
357357
InvalidStreamOnScalarField { field_name: StringKey },
358358

359-
#[error("Invalid use of @stream, the 'initial_count' argument is required.")]
359+
#[error("Invalid use of @stream, the 'initial_count' or 'initialCount' argument is required.")]
360360
StreamInitialCountRequired,
361361

362362
#[error("{variables_string} never used in operation '{operation_name}'.")]

compiler/crates/graphql-transforms/src/defer_stream/directives.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ impl<'a> StreamDirective<'a> {
5858
label_arg = Some(arg);
5959
} else if arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg {
6060
initial_count_arg = Some(arg);
61+
} else if arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg_oss {
62+
initial_count_arg = Some(arg);
6163
} else if arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg {
6264
use_customized_batch_arg = Some(arg);
6365
} else {

compiler/crates/graphql-transforms/src/defer_stream/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct DeferStreamConstants {
2626
pub if_arg: StringKey,
2727
pub label_arg: StringKey,
2828
pub initial_count_arg: StringKey,
29+
pub initial_count_arg_oss: StringKey,
2930
pub use_customized_batch_arg: StringKey,
3031
}
3132

@@ -37,6 +38,7 @@ impl Default for DeferStreamConstants {
3738
if_arg: "if".intern(),
3839
label_arg: "label".intern(),
3940
initial_count_arg: "initial_count".intern(),
41+
initial_count_arg_oss: "initialCount".intern(),
4042
use_customized_batch_arg: "use_customized_batch".intern(),
4143
}
4244
}

compiler/crates/graphql-transforms/src/transform_connections.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl<'s> ConnectionTransform<'s> {
125125
for arg in &connection_directive.arguments {
126126
if arg.name.item == DEFER_STREAM_CONSTANTS.if_arg
127127
|| arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg
128+
|| arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg_oss
128129
|| arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg
129130
{
130131
arguments.push(arg.clone());
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
==================================== INPUT ====================================
2+
query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) {
3+
node(id: $id) {
4+
id
5+
...FeedbackFragment
6+
}
7+
}
8+
9+
fragment FeedbackFragment on Feedback {
10+
id
11+
actors @stream(initialCount: $initialCount, label: "StreamedActorsLabel") {
12+
name
13+
}
14+
}
15+
==================================== OUTPUT ===================================
16+
query QueryWithFragmentWithStream(
17+
$id: ID!
18+
$initialCount: Int
19+
) {
20+
node(id: $id) {
21+
id
22+
...FeedbackFragment
23+
}
24+
}
25+
26+
fragment FeedbackFragment on Feedback {
27+
id
28+
actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initialCount: $initialCount) {
29+
name
30+
}
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) {
2+
node(id: $id) {
3+
id
4+
...FeedbackFragment
5+
}
6+
}
7+
8+
fragment FeedbackFragment on Feedback {
9+
id
10+
actors @stream(initialCount: $initialCount, label: "StreamedActorsLabel") {
11+
name
12+
}
13+
}

compiler/crates/graphql-transforms/tests/defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fragment FeedbackFragment on Feedback {
1515
}
1616
}
1717
==================================== ERROR ====================================
18-
Invalid use of @stream, the 'initial_count' argument is required.:
18+
Invalid use of @stream, the 'initial_count' or 'initialCount' argument is required.:
1919
fragment-with-stream-missing-initial-count-arg.invalid.graphql:10:11:
2020
actors @stream(label: "StreamedActorsLabel") {

compiler/crates/graphql-transforms/tests/defer_stream_test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ fn fragment_with_stream_initial_count_arg() {
8989
test_fixture(transform_fixture, "fragment-with-stream-initial-count-arg.graphql", "defer_stream/fixtures/fragment-with-stream-initial-count-arg.expected", input, expected);
9090
}
9191

92+
#[test]
93+
fn fragment_with_stream_initial_count_arg_oss() {
94+
let input = include_str!("defer_stream/fixtures/fragment-with-stream-initial-count-arg-oss.graphql");
95+
let expected = include_str!("defer_stream/fixtures/fragment-with-stream-initial-count-arg-oss.expected");
96+
test_fixture(transform_fixture, "fragment-with-stream-initial-count-arg-oss.graphql", "defer_stream/fixtures/fragment-with-stream-initial-count-arg-oss.expected", input, expected);
97+
}
98+
9299
#[test]
93100
fn fragment_with_stream_missing_initial_count_arg_invalid() {
94101
let input = include_str!("defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.graphql");
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
==================================== INPUT ====================================
2+
query NodeQuery($id: ID!) {
3+
node(id: $id) {
4+
id
5+
... on Story {
6+
comments(first: 10)
7+
@stream_connection(key: "NodeQuery_comments", initialCount: 0) {
8+
edges {
9+
node {
10+
actor {
11+
name
12+
}
13+
}
14+
}
15+
pageInfo {
16+
endCursor
17+
hasNextPage
18+
}
19+
}
20+
}
21+
}
22+
}
23+
==================================== OUTPUT ===================================
24+
query NodeQuery(
25+
$id: ID!
26+
) @__connectionMetadata(__connectionMetadataArgument: [[["node", "comments"], "forward", null, null, null, null, true]]) {
27+
node(id: $id) {
28+
id
29+
... on Story {
30+
comments(first: 10) @__clientField(key: "NodeQuery_comments", handle: "connection") {
31+
edges @stream(label: "NodeQuery_comments", initialCount: 0) {
32+
node {
33+
actor {
34+
name
35+
}
36+
}
37+
... on CommentsEdge {
38+
cursor
39+
node {
40+
__typename
41+
}
42+
}
43+
}
44+
... @defer(label: "NodeQuery$defer$NodeQuery_comments$pageInfo") {
45+
pageInfo {
46+
endCursor
47+
hasNextPage
48+
... on PageInfo {
49+
endCursor
50+
hasNextPage
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
query NodeQuery($id: ID!) {
2+
node(id: $id) {
3+
id
4+
... on Story {
5+
comments(first: 10)
6+
@stream_connection(key: "NodeQuery_comments", initialCount: 0) {
7+
edges {
8+
node {
9+
actor {
10+
name
11+
}
12+
}
13+
}
14+
pageInfo {
15+
endCursor
16+
hasNextPage
17+
}
18+
}
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)