Skip to content

Commit

Permalink
work with initialCount
Browse files Browse the repository at this point in the history
  • Loading branch information
robrichard committed Jul 7, 2020
1 parent e441592 commit b58a501
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/relay-compiler/core/IR.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export type Stream = {|
+selections: $ReadOnlyArray<Selection>,
+label: string,
+if: ArgumentValue | null,
+initialCount: ArgumentValue,
+initialCount: Argument,
+useCustomizedBatch: ArgumentValue | null,
|};

Expand Down
4 changes: 2 additions & 2 deletions packages/relay-compiler/core/IRPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ function printSelection(
streamStr += `, if: ${printValue(schema, selection.if, null) ?? ''}`;
}
if (selection.initialCount !== null) {
streamStr += `, initial_count: ${printValue(
streamStr += `, ${selection.initialCount.name}: ${printValue(
schema,
selection.initialCount,
selection.initialCount.value,
null,
) ?? ''}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ function transformDeferStreamNode<T: Defer | Stream>(
}
if (nextNode.initialCount) {
//$FlowFixMe nextNode is uniquely owned
nextNode.initialCount = transformValue(
nextNode.initialCount.value = transformValue(
scope,
nextNode.initialCount,
nextNode.initialCount.value,
errorContext,
);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/relay-compiler/transforms/ConnectionTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const SCHEMA_EXTENSION = `
key: String!
filters: [String]
handler: String
initial_count: Int!
initial_count: Int
initialCount: Int
if: Boolean = true
use_customized_batch: Boolean = false
dynamicKey_UNSTABLE: String
Expand Down Expand Up @@ -294,7 +295,7 @@ function buildConnectionArguments(
let stream = null;
if (connectionDirective.name === STREAM_CONNECTION) {
const initialCountArg = connectionDirective.args.find(
arg => arg.name === 'initial_count',
arg => arg.name === 'initial_count' || arg.name === 'initialCount',
);
const useCustomizedBatchArg = connectionDirective.args.find(
arg => arg.name === 'use_customized_batch',
Expand Down
6 changes: 3 additions & 3 deletions packages/relay-compiler/transforms/DeferStreamTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ function visitLinkedField(
return transformedField;
}
const initialCount = streamDirective.args.find(
arg => arg.name === 'initial_count',
arg => arg.name === 'initial_count' || arg.name === 'initialCount',
);
if (initialCount == null) {
throw createUserError(
"Invalid use of @stream, the 'initial_count' argument is required.",
"Invalid use of @stream, the 'initial_count' or 'initialCount' argument is required.",
[streamDirective.loc],
);
}
Expand All @@ -136,7 +136,7 @@ function visitLinkedField(
state.recordLabel(transformedLabel, streamDirective);
return {
if: ifArg?.value ?? null,
initialCount: initialCount.value,
initialCount: initialCount,
useCustomizedBatch: useCustomizedBatch?.value ?? null,
kind: 'Stream',
label: transformedLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,82 @@ query NodeQuery(
}
`;
exports[`matches expected output: stream-connection-oss.graphql 1`] = `
~~~~~~~~~~ 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!
) {
node(id: $id) {
id
... on Story {
comments(first: 10) @__clientField(handle: "connection", key: "NodeQuery_comments") {
edges @stream(initialCount: 0, label: "NodeQuery_comments") {
node {
actor {
name
}
}
... on CommentsEdge {
cursor
node {
__typename
}
}
}
... @defer(label: "NodeQuery$defer$NodeQuery_comments$pageInfo") {
pageInfo {
endCursor
hasNextPage
... on PageInfo {
endCursor
hasNextPage
}
}
}
}
}
}
}
# Metadata:
{
"connection": [
{
"count": null,
"cursor": null,
"direction": "forward",
"path": [
"node",
"comments"
],
"stream": true
}
]
}
`;
exports[`matches expected output: stream-connection-with-aliased-edges.invalid.graphql 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
# expected-to-throw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,42 @@ fragment FeedbackFragment on Feedback {
`;
exports[`DeferStreamTransform when streaming is enabled matches expected output: fragment-with-stream-initial-count-arg-oss.graphql 1`] = `
~~~~~~~~~~ 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
}
}
`;
exports[`DeferStreamTransform when streaming is enabled matches expected output: fragment-with-stream-missing-initial-count-arg.invalid.graphql 1`] = `
~~~~~~~~~~ INPUT ~~~~~~~~~~
# expected-to-throw
Expand All @@ -467,7 +503,7 @@ fragment FeedbackFragment on Feedback {
~~~~~~~~~~ OUTPUT ~~~~~~~~~~
THROWN EXCEPTION:
Invalid use of @stream, the 'initial_count' argument is required.
Invalid use of @stream, the 'initial_count' or 'initialCount' argument is required.
Source: GraphQL request (11:10)
10: id
Expand Down
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
@@ -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
}
}
3 changes: 2 additions & 1 deletion packages/relay-test-utils-internal/testschema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ directive @defer(

directive @stream(
label: String!
initial_count: Int!
initial_count: Int
initialCount: Int
if: Boolean = true
use_customized_batch: Boolean = false
) on FIELD
Expand Down

0 comments on commit b58a501

Please sign in to comment.