Skip to content

Commit

Permalink
add initialCount support to rust compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
robrichard committed Jul 7, 2020
1 parent 9e9c8ab commit a5a48a6
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/crates/graphql-ir/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub enum ValidationMessage {
#[error("Invalid use of @stream on scalar field '{field_name}'")]
InvalidStreamOnScalarField { field_name: StringKey },

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

#[error("{variables_string} never used in operation '{operation_name}'.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl<'a> StreamDirective<'a> {
label_arg = Some(arg);
} else if arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg {
initial_count_arg = Some(arg);
} else if arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg_oss {
initial_count_arg = Some(arg);
} else if arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg {
use_customized_batch_arg = Some(arg);
} else {
Expand Down
2 changes: 2 additions & 0 deletions compiler/crates/graphql-transforms/src/defer_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct DeferStreamConstants {
pub if_arg: StringKey,
pub label_arg: StringKey,
pub initial_count_arg: StringKey,
pub initial_count_arg_oss: StringKey,
pub use_customized_batch_arg: StringKey,
}

Expand All @@ -37,6 +38,7 @@ impl Default for DeferStreamConstants {
if_arg: "if".intern(),
label_arg: "label".intern(),
initial_count_arg: "initial_count".intern(),
initial_count_arg_oss: "initialCount".intern(),
use_customized_batch_arg: "use_customized_batch".intern(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<'s> ConnectionTransform<'s> {
for arg in &connection_directive.arguments {
if arg.name.item == DEFER_STREAM_CONSTANTS.if_arg
|| arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg
|| arg.name.item == DEFER_STREAM_CONSTANTS.initial_count_arg_oss
|| arg.name.item == DEFER_STREAM_CONSTANTS.use_customized_batch_arg
{
arguments.push(arg.clone());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
==================================== INPUT ====================================
query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) {
node(id: $id) {
id
...FeedbackFragment
}
}

fragment FeedbackFragment on Feedback {
id
actors @stream(initialCount: $initialCount, label: "StreamedActorsLabel") {
name
}
}
==================================== OUTPUT ===================================
query QueryWithFragmentWithStream(
$id: ID!
$initialCount: Int
) {
node(id: $id) {
id
...FeedbackFragment
}
}

fragment FeedbackFragment on Feedback {
id
actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initialCount: $initialCount) {
name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query QueryWithFragmentWithStream($id: ID!, $initialCount: Int) {
node(id: $id) {
id
...FeedbackFragment
}
}

fragment FeedbackFragment on Feedback {
id
actors @stream(initialCount: $initialCount, label: "StreamedActorsLabel") {
name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fragment FeedbackFragment on Feedback {
}
}
==================================== ERROR ====================================
Invalid use of @stream, the 'initial_count' argument is required.:
Invalid use of @stream, the 'initial_count' or 'initialCount' argument is required.:
fragment-with-stream-missing-initial-count-arg.invalid.graphql:10:11:
actors @stream(label: "StreamedActorsLabel") {
7 changes: 7 additions & 0 deletions compiler/crates/graphql-transforms/tests/defer_stream_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ fn fragment_with_stream_initial_count_arg() {
test_fixture(transform_fixture, "fragment-with-stream-initial-count-arg.graphql", "defer_stream/fixtures/fragment-with-stream-initial-count-arg.expected", input, expected);
}

#[test]
fn fragment_with_stream_initial_count_arg_oss() {
let input = include_str!("defer_stream/fixtures/fragment-with-stream-initial-count-arg-oss.graphql");
let expected = include_str!("defer_stream/fixtures/fragment-with-stream-initial-count-arg-oss.expected");
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);
}

#[test]
fn fragment_with_stream_missing_initial_count_arg_invalid() {
let input = include_str!("defer_stream/fixtures/fragment-with-stream-missing-initial-count-arg.invalid.graphql");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
==================================== INPUT ====================================
query NodeQuery($id: ID!) {
node(id: $id) {
id
... on Story {
comments(first: 10)
@stream_connection(key: "NodeQuery_comments", initialCount: 0) {
edges {
node {
actor {
name
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
==================================== OUTPUT ===================================
query NodeQuery(
$id: ID!
) @__connectionMetadata(__connectionMetadataArgument: [[["node", "comments"], "forward", null, null, null, null, true]]) {
node(id: $id) {
id
... on Story {
comments(first: 10) @__clientField(key: "NodeQuery_comments", handle: "connection") {
edges @stream(label: "NodeQuery_comments", initialCount: 0) {
node {
actor {
name
}
}
... on CommentsEdge {
cursor
node {
__typename
}
}
}
... @defer(label: "NodeQuery$defer$NodeQuery_comments$pageInfo") {
pageInfo {
endCursor
hasNextPage
... on PageInfo {
endCursor
hasNextPage
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query NodeQuery($id: ID!) {
node(id: $id) {
id
... on Story {
comments(first: 10)
@stream_connection(key: "NodeQuery_comments", initialCount: 0) {
edges {
node {
actor {
name
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ fn stream_connection() {
test_fixture(transform_fixture, "stream-connection.graphql", "transform_connections/fixtures/stream-connection.expected", input, expected);
}

#[test]
fn stream_connection_oss() {
let input = include_str!("transform_connections/fixtures/stream-connection-oss.graphql");
let expected = include_str!("transform_connections/fixtures/stream-connection-oss.expected");
test_fixture(transform_fixture, "stream-connection-oss.graphql", "transform_connections/fixtures/stream-connection-oss.expected", input, expected);
}

#[test]
fn stream_connection_no_label() {
let input = include_str!("transform_connections/fixtures/stream-connection-no-label.graphql");
Expand Down
3 changes: 2 additions & 1 deletion compiler/crates/schema/src/relay-extensions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ directive @stream_connection(
filters: [String]
handler: String
label: String!
initial_count: Int!
initial_count: Int
initialCount: Int
if: Boolean = true
use_customized_batch: Boolean = false
dynamicKey_UNSTABLE: String
Expand Down
1 change: 1 addition & 0 deletions compiler/crates/test-schema/src/testschema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ directive @defer(
directive @stream(
label: String!
initial_count: Int!
initialCount: Int
if: Boolean = true
use_customized_batch: Boolean = false
) on FIELD
Expand Down

0 comments on commit a5a48a6

Please sign in to comment.