Skip to content

Commit

Permalink
Add DeferStreamInterface to conform to proposed graphql spec
Browse files Browse the repository at this point in the history
  • Loading branch information
robrichard committed Dec 22, 2020
1 parent 379bb43 commit 41a33b0
Show file tree
Hide file tree
Showing 52 changed files with 204 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9351,7 +9351,7 @@ query QueryWithFragmentWithStream($id: ID!) {

fragment FeedbackFragment on Feedback {
id
actors @stream(initial_count: 1, label: "StreamedActorsLabel") {
actors @stream(initialCount: 1, label: "StreamedActorsLabel") {
name
}
}
Expand Down Expand Up @@ -9493,7 +9493,7 @@ query QueryWithFragmentWithStream(

fragment FeedbackFragment on Feedback {
id
actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initial_count: 1) {
actors @stream(label: "FeedbackFragment$stream$StreamedActorsLabel", initialCount: 1) {
__typename
name
id
Expand Down Expand Up @@ -18291,7 +18291,7 @@ fragment PaginationFragment on Node
... on User {
name
friends(after: $cursor, first: $count)
@stream_connection(key: "PaginationFragment_friends", initial_count: 1) {
@stream_connection(key: "PaginationFragment_friends", initialCount: 1) {
edges {
node {
id
Expand Down Expand Up @@ -18546,7 +18546,7 @@ fragment PaginationFragment_1G22uz on Node {
... on User {
name
friends(after: $cursor, first: $count) {
edges @stream(label: "PaginationFragment$stream$PaginationFragment_friends", initial_count: 1) {
edges @stream(label: "PaginationFragment$stream$PaginationFragment_friends", initialCount: 1) {
node {
id
__typename
Expand Down Expand Up @@ -18722,7 +18722,7 @@ fragment PaginationFragment on Node
if: {type: "Boolean", defaultValue: false}
count: {type: "Int", defaultValue: 10}
cursor: {type: "ID"}
initial_count: {type: "Int", defaultValue: 5}
initialCount: {type: "Int", defaultValue: 5}
) {
id
... on User {
Expand All @@ -18731,7 +18731,7 @@ fragment PaginationFragment on Node
@stream_connection(
if: $if
key: "PaginationFragment_friends"
initial_count: $initial_count
initialCount: $initialCount
) {
edges {
node {
Expand Down Expand Up @@ -18958,7 +18958,7 @@ Fragment {
},
LocalArgument {
defaultValue: 5,
name: "initial_count",
name: "initialCount",
},
],
metadata: {
Expand Down Expand Up @@ -19090,15 +19090,15 @@ fragment PaginationFragment on Node
@argumentDefinitions(
count: {type: "Int", defaultValue: 10}
cursor: {type: "ID"}
initial_count: {type: "Int", defaultValue: 5}
initialCount: {type: "Int", defaultValue: 5}
) {
id
... on User {
name
friends(after: $cursor, first: $count)
@stream_connection(
key: "PaginationFragment_friends"
initial_count: $initial_count
initialCount: $initialCount
) {
edges {
node {
Expand Down Expand Up @@ -19307,7 +19307,7 @@ fragment PaginationFragment on Node {
... on User {
name
friends(first: 10) {
edges @stream(label: "PaginationFragment$stream$PaginationFragment_friends", initial_count: 5) {
edges @stream(label: "PaginationFragment$stream$PaginationFragment_friends", initialCount: 5) {
node {
id
__typename
Expand Down Expand Up @@ -19337,7 +19337,7 @@ Fragment {
},
LocalArgument {
defaultValue: 5,
name: "initial_count",
name: "initialCount",
},
],
metadata: {
Expand Down Expand Up @@ -20534,7 +20534,7 @@ query NodeQuery($id: ID!) {
id
... on Story {
comments(first: 10)
@stream_connection(key: "NodeQuery_comments", initial_count: 0) {
@stream_connection(key: "NodeQuery_comments", initialCount: 0) {
edges {
node {
actor {
Expand Down Expand Up @@ -20868,7 +20868,7 @@ query NodeQuery(
id
... on Story {
comments(first: 10) {
edges @stream(label: "NodeQuery$stream$NodeQuery_comments", initial_count: 0) {
edges @stream(label: "NodeQuery$stream$NodeQuery_comments", initialCount: 0) {
node {
actor {
__typename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ query QueryWithFragmentWithStream($id: ID!) {

fragment FeedbackFragment on Feedback {
id
actors @stream(initial_count: 1, label: "StreamedActorsLabel") {
actors @stream(initialCount: 1, label: "StreamedActorsLabel") {
name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fragment PaginationFragment on Node
... on User {
name
friends(after: $cursor, first: $count)
@stream_connection(key: "PaginationFragment_friends", initial_count: 1) {
@stream_connection(key: "PaginationFragment_friends", initialCount: 1) {
edges {
node {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fragment PaginationFragment on Node
if: {type: "Boolean", defaultValue: false}
count: {type: "Int", defaultValue: 10}
cursor: {type: "ID"}
initial_count: {type: "Int", defaultValue: 5}
initialCount: {type: "Int", defaultValue: 5}
) {
id
... on User {
Expand All @@ -18,7 +18,7 @@ fragment PaginationFragment on Node
@stream_connection(
if: $if
key: "PaginationFragment_friends"
initial_count: $initial_count
initialCount: $initialCount
) {
edges {
node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ fragment PaginationFragment on Node
@argumentDefinitions(
count: {type: "Int", defaultValue: 10}
cursor: {type: "ID"}
initial_count: {type: "Int", defaultValue: 5}
initialCount: {type: "Int", defaultValue: 5}
) {
id
... on User {
name
friends(after: $cursor, first: $count)
@stream_connection(
key: "PaginationFragment_friends"
initial_count: $initial_count
initialCount: $initialCount
) {
edges {
node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ query NodeQuery($id: ID!) {
id
... on Story {
comments(first: 10)
@stream_connection(key: "NodeQuery_comments", initial_count: 0) {
@stream_connection(key: "NodeQuery_comments", initialCount: 0) {
edges {
node {
actor {
Expand Down
19 changes: 13 additions & 6 deletions packages/relay-compiler/core/IRPrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const invariant = require('invariant');

const {DEFAULT_HANDLE_KEY} = require('../util/DefaultHandleKey');
const {DeferStreamInterface} = require('relay-runtime');

import type {CompilerContextDocument} from './CompilerContext';
import type {
Expand Down Expand Up @@ -130,6 +131,12 @@ function printSelection(
let str;
const parentDirectives = options?.parentDirectives ?? '';
const isClientExtension = options?.isClientExtension === true;
const {
INITIAL_COUNT,
LABEL,
IF,
USE_CUSTOMIZED_BATCH,
} = DeferStreamInterface.get();
if (selection.kind === 'LinkedField') {
str = printField(schema, selection, {parentDirectives, isClientExtension});
str += printSelections(schema, selection, indent + INDENT, {
Expand Down Expand Up @@ -192,19 +199,19 @@ function printSelection(
str = subSelections.join('\n' + indent + INDENT);
} else if (selection.kind === 'Stream') {
let streamStr = parentDirectives;
streamStr += ` @stream(label: "${selection.label}"`;
streamStr += ` @stream(${LABEL}: "${selection.label}"`;
if (selection.if !== null) {
streamStr += `, if: ${printValue(schema, selection.if, null) ?? ''}`;
streamStr += `, ${IF}: ${printValue(schema, selection.if, null) ?? ''}`;
}
if (selection.initialCount !== null) {
streamStr += `, initial_count: ${printValue(
streamStr += `, ${INITIAL_COUNT}: ${printValue(
schema,
selection.initialCount,
null,
) ?? ''}`;
}
if (selection.useCustomizedBatch !== null) {
streamStr += `, use_customized_batch: ${printValue(
streamStr += `, ${USE_CUSTOMIZED_BATCH}: ${printValue(
schema,
selection.useCustomizedBatch,
null,
Expand All @@ -220,9 +227,9 @@ function printSelection(
str = subSelections.join('\n' + INDENT);
} else if (selection.kind === 'Defer') {
let deferStr = parentDirectives;
deferStr += ` @defer(label: "${selection.label}"`;
deferStr += ` @defer(${LABEL}: "${selection.label}"`;
if (selection.if !== null) {
deferStr += `, if: ${printValue(schema, selection.if, null) ?? ''}`;
deferStr += `, ${IF}: ${printValue(schema, selection.if, null) ?? ''}`;
}
deferStr += ')';
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ query TestStream @raw_response_type {
friends(first: 10)
@stream_connection(
key: "PaginationFragment_friends"
initial_count: 1
initialCount: 1
) {
edges {
node {
Expand Down Expand Up @@ -2002,7 +2002,7 @@ query TestDefer @raw_response_type {
... on User {
name
friends(first: 10)
@stream_connection(key: "TestDefer_friends", initial_count: 0) {
@stream_connection(key: "TestDefer_friends", initialCount: 0) {
edges {
node {
actor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ query TestDefer @raw_response_type {
... on User {
name
friends(first: 10)
@stream_connection(key: "TestDefer_friends", initial_count: 0) {
@stream_connection(key: "TestDefer_friends", initialCount: 0) {
edges {
node {
actor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ query TestStream @raw_response_type {
friends(first: 10)
@stream_connection(
key: "PaginationFragment_friends"
initial_count: 1
initialCount: 1
) {
edges {
node {
Expand Down
15 changes: 10 additions & 5 deletions packages/relay-compiler/transforms/ConnectionTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const getLiteralArgumentValues = require('../core/getLiteralArgumentValues');

const {createCompilerError, createUserError} = require('../core/CompilerError');
const {parse} = require('graphql');
const {ConnectionInterface, RelayFeatureFlags} = require('relay-runtime');
const {
ConnectionInterface,
DeferStreamInterface,
RelayFeatureFlags,
} = require('relay-runtime');

import type CompilerContext from '../core/CompilerContext';
import type {
Expand Down Expand Up @@ -109,9 +113,9 @@ const SCHEMA_EXTENSION = `
key: String!
filters: [String]
handler: String
initial_count: Int!
initialCount: Int!
if: Boolean = true
use_customized_batch: Boolean = false
useCustomizedBatch: Boolean = false
dynamicKey_UNSTABLE: String
) on FIELD
`;
Expand Down Expand Up @@ -227,6 +231,7 @@ function buildConnectionArguments(
field: LinkedField,
connectionDirective: Directive,
): ConnectionArguments {
const {INITIAL_COUNT, USE_CUSTOMIZED_BATCH} = DeferStreamInterface.get();
const {
handler,
key,
Expand Down Expand Up @@ -294,10 +299,10 @@ 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,
);
const useCustomizedBatchArg = connectionDirective.args.find(
arg => arg.name === 'use_customized_batch',
arg => arg.name === USE_CUSTOMIZED_BATCH,
);
const ifArg = connectionDirective.args.find(arg => arg.name === 'if');
stream = {
Expand Down

0 comments on commit 41a33b0

Please sign in to comment.