Skip to content

Commit 513d6e3

Browse files
authored
Relay deprecation removal and documentation (#660)
1 parent 6011fd3 commit 513d6e3

8 files changed

Lines changed: 62 additions & 134 deletions

File tree

src/main/java/graphql/relay/Connection.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
import java.util.List;
66

77
/**
8-
* represents a connection in relay.
8+
* This represents a connection in Relay, which is a list of {@link graphql.relay.Edge edge}s
9+
* as well as a {@link graphql.relay.PageInfo pageInfo} that describes the pagination of that list.
10+
*
11+
* See <a href="https://facebook.github.io/relay/graphql/connections.htm">https://facebook.github.io/relay/graphql/connections.htm</a>
912
*/
1013
@PublicApi
1114
public interface Connection<T> {
1215

16+
/**
17+
* @return a list of {@link graphql.relay.Edge}s that are really a node of data and its cursor
18+
*/
1319
List<Edge<T>> getEdges();
1420

21+
/**
22+
* @return {@link graphql.relay.PageInfo} pagination data about about that list of edges
23+
*/
1524
PageInfo getPageInfo();
1625

1726
}

src/main/java/graphql/relay/ConnectionCursor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
import graphql.PublicApi;
44

55
/**
6-
* represents a {@link Connection connection} cursor in relay.
6+
* Represents a {@link Connection connection} cursor in Relay which is an opaque
7+
* string that the server understands. Often this is base64 encoded but the spec only
8+
* mandates that it be an opaque cursor so meaning can't be inferred from it (to prevent cheating like
9+
* pre calculating the next cursor on the client say)
10+
*
11+
* See <a href="https://facebook.github.io/relay/graphql/connections.htm#sec-Cursor">https://facebook.github.io/relay/graphql/connections.htm#sec-Cursor</a>
712
*/
813
@PublicApi
914
public interface ConnectionCursor {
1015

16+
/**
17+
* @return an opaque string that represents this cursor.
18+
*/
1119
String getValue();
1220

1321
}

src/main/java/graphql/relay/DefaultConnection.java

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,44 @@
22

33
import graphql.PublicApi;
44

5-
import java.util.ArrayList;
65
import java.util.Collections;
76
import java.util.List;
87

98
import static graphql.Assert.assertNotNull;
9+
import static java.util.Collections.unmodifiableList;
1010

11+
/**
12+
* A default implementation of {@link graphql.relay.Connection}
13+
*/
1114
@PublicApi
1215
public class DefaultConnection<T> implements Connection<T> {
1316

14-
private List<Edge<T>> edges = new ArrayList<>();
15-
16-
private PageInfo pageInfo;
17-
18-
/**
19-
* @deprecated prefer {@link #DefaultConnection(List, PageInfo)}
20-
*/
21-
@Deprecated
22-
public DefaultConnection() {
23-
}
17+
private final List<Edge<T>> edges;
18+
private final PageInfo pageInfo;
2419

2520
/**
26-
* @param edges edges
27-
* @param pageInfo page info
21+
* A connection consists of a list of edges and page info
22+
*
23+
* @param edges a non null list of edges
24+
* @param pageInfo a non null page info
2825
*
2926
* @throws IllegalArgumentException if edges or page info is null. use {@link Collections#emptyList()} for empty edges.
3027
*/
3128
public DefaultConnection(List<Edge<T>> edges, PageInfo pageInfo) {
32-
// TODO make defensive copy
33-
this.edges = assertNotNull(edges, "edges cannot be null");
29+
this.edges = unmodifiableList(assertNotNull(edges, "edges cannot be null"));
3430
this.pageInfo = assertNotNull(pageInfo, "page info cannot be null");
3531
}
3632

3733
@Override
3834
public List<Edge<T>> getEdges() {
39-
return Collections.unmodifiableList(edges);
40-
}
41-
42-
/**
43-
* @param edges edges
44-
*
45-
* @deprecated prefer {@link #DefaultConnection(List, PageInfo)} and avoid mutation
46-
*/
47-
@Deprecated
48-
public void setEdges(List<Edge<T>> edges) {
49-
if (edges == null) { // TODO remove setter
50-
edges = Collections.emptyList();
51-
}
52-
this.edges = edges;
35+
return edges;
5336
}
5437

5538
@Override
5639
public PageInfo getPageInfo() {
5740
return pageInfo;
5841
}
5942

60-
/**
61-
* @param pageInfo page info
62-
*
63-
* @deprecated prefer {@link #DefaultConnection(List, PageInfo)} and avoid mutation
64-
*/
65-
@Deprecated
66-
public void setPageInfo(PageInfo pageInfo) {
67-
this.pageInfo = pageInfo;
68-
}
69-
7043
@Override
7144
public String toString() {
7245
return "DefaultConnection{" +

src/main/java/graphql/relay/DefaultEdge.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,25 @@
77
@PublicApi
88
public class DefaultEdge<T> implements Edge<T> {
99

10+
private final T node;
11+
private final ConnectionCursor cursor;
12+
1013
public DefaultEdge(T node, ConnectionCursor cursor) {
1114
this.cursor = assertNotNull(cursor, "cursor cannot be null");
1215
this.node = node;
1316
}
1417

15-
/**
16-
* @deprecated prefer {@link #DefaultEdge(Object, ConnectionCursor)}
17-
*/
18-
@Deprecated
19-
public DefaultEdge() {
20-
}
21-
22-
private T node;
23-
private ConnectionCursor cursor;
2418

2519
@Override
2620
public T getNode() {
2721
return node;
2822
}
2923

30-
/**
31-
* @param node node
32-
*
33-
* @deprecated prefer {@link #DefaultEdge(Object, ConnectionCursor)} and avoid mutation.
34-
*/
35-
@Deprecated
36-
public void setNode(T node) {
37-
this.node = node;
38-
}
39-
4024
@Override
4125
public ConnectionCursor getCursor() {
4226
return cursor;
4327
}
4428

45-
/**
46-
* @param cursor cursor
47-
*
48-
* @deprecated prefer {@link #DefaultEdge(Object, ConnectionCursor)} and avoid mutation.
49-
*/
50-
@Deprecated
51-
public void setCursor(ConnectionCursor cursor) {
52-
this.cursor = cursor;
53-
}
54-
5529
@Override
5630
public String toString() {
5731
return "DefaultEdge{" +

src/main/java/graphql/relay/DefaultPageInfo.java

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@
66
@PublicApi
77
public class DefaultPageInfo implements PageInfo {
88

9-
private ConnectionCursor startCursor;
10-
private ConnectionCursor endCursor;
11-
private boolean hasPreviousPage;
12-
private boolean hasNextPage;
13-
14-
/**
15-
* @deprecated prefer {@link #DefaultPageInfo(ConnectionCursor, ConnectionCursor, boolean, boolean)}
16-
*/
17-
@Deprecated
18-
public DefaultPageInfo() {
19-
}
9+
private final ConnectionCursor startCursor;
10+
private final ConnectionCursor endCursor;
11+
private final boolean hasPreviousPage;
12+
private final boolean hasNextPage;
2013

2114
public DefaultPageInfo(ConnectionCursor startCursor, ConnectionCursor endCursor, boolean hasPreviousPage, boolean hasNextPage) {
2215
this.startCursor = startCursor;
@@ -30,61 +23,22 @@ public ConnectionCursor getStartCursor() {
3023
return startCursor;
3124
}
3225

33-
/**
34-
* @param startCursor startCursor
35-
*
36-
* @deprecated prefer {@link #DefaultPageInfo(ConnectionCursor, ConnectionCursor, boolean, boolean)} and avoid mutation
37-
*/
38-
@Deprecated
39-
public void setStartCursor(ConnectionCursor startCursor) {
40-
this.startCursor = startCursor;
41-
}
4226

4327
@Override
4428
public ConnectionCursor getEndCursor() {
4529
return endCursor;
4630
}
4731

48-
/**
49-
* @param endCursor endCursor
50-
*
51-
* @deprecated prefer {@link #DefaultPageInfo(ConnectionCursor, ConnectionCursor, boolean, boolean)} and avoid mutation
52-
*/
53-
@Deprecated
54-
public void setEndCursor(ConnectionCursor endCursor) {
55-
this.endCursor = endCursor;
56-
}
57-
5832
@Override
5933
public boolean isHasPreviousPage() {
6034
return hasPreviousPage;
6135
}
6236

63-
/**
64-
* @param hasPreviousPage previous page
65-
*
66-
* @deprecated prefer {@link #DefaultPageInfo(ConnectionCursor, ConnectionCursor, boolean, boolean)} and avoid mutation
67-
*/
68-
@Deprecated
69-
public void setHasPreviousPage(boolean hasPreviousPage) {
70-
this.hasPreviousPage = hasPreviousPage;
71-
}
72-
7337
@Override
7438
public boolean isHasNextPage() {
7539
return hasNextPage;
7640
}
7741

78-
/**
79-
* @param hasNextPage has next page
80-
*
81-
* @deprecated prefer {@link #DefaultPageInfo(ConnectionCursor, ConnectionCursor, boolean, boolean)}
82-
*/
83-
@Deprecated
84-
public void setHasNextPage(boolean hasNextPage) {
85-
this.hasNextPage = hasNextPage;
86-
}
87-
8842
@Override
8943
public String toString() {
9044
return "DefaultPageInfo{" +

src/main/java/graphql/relay/Edge.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
import graphql.PublicApi;
44

55
/**
6-
* represents an edge in relay.
6+
* Represents an edge in Relay which is essentially a node of data T and the cursor for that node.
7+
*
8+
* See <a href="https://facebook.github.io/relay/graphql/connections.htm#sec-Edge-Types">https://facebook.github.io/relay/graphql/connections.htm#sec-Edge-Types</a>
79
*/
810
@PublicApi
911
public interface Edge<T> {
1012

13+
/**
14+
* @return the node of data that this edge represents
15+
*/
1116
T getNode();
1217

18+
/**
19+
* @return the cursor for this edge node
20+
*/
1321
ConnectionCursor getCursor();
1422

1523
}

src/main/java/graphql/relay/PageInfo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import graphql.PublicApi;
44

55
/**
6-
* represents a page in relay.
6+
* Represents pagination information in Relay about {@link graphql.relay.Edge edges} when used
7+
* inside a {@link graphql.relay.Connection connection}
8+
*
9+
* See <a href="https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo">https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo</a>
710
*/
811
@PublicApi
912
public interface PageInfo {
@@ -19,12 +22,12 @@ public interface PageInfo {
1922
ConnectionCursor getEndCursor();
2023

2124
/**
22-
* @return true if and only if this page is not the first page. only meaningful when you gave {@code last} argument.
25+
* @return true if and only if this page is not the first page. only meaningful when you gave the {@code last} argument.
2326
*/
2427
boolean isHasPreviousPage();
2528

2629
/**
27-
* @return true if and only if this page is not the last page. only meaningful when you gave {@code first} argument.
30+
* @return true if and only if this page is not the last page. only meaningful when you gave the {@code first} argument.
2831
*/
2932
boolean isHasNextPage();
3033
}

src/main/java/graphql/relay/Relay.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import graphql.schema.GraphQLObjectType;
1313
import graphql.schema.GraphQLOutputType;
1414
import graphql.schema.TypeResolver;
15+
1516
import java.nio.charset.StandardCharsets;
1617
import java.util.ArrayList;
1718
import java.util.List;
@@ -27,6 +28,12 @@
2728
import static graphql.schema.GraphQLInterfaceType.newInterface;
2829
import static graphql.schema.GraphQLObjectType.newObject;
2930

31+
/**
32+
* This can be used to compose graphql runtime types that implement
33+
* that Relay specification.
34+
*
35+
* See <a href="https://facebook.github.io/relay/graphql/connections.htm">https://facebook.github.io/relay/graphql/connections.htm</a>
36+
*/
3037
@PublicApi
3138
public class Relay {
3239

@@ -202,16 +209,8 @@ public ResolvedGlobalId(String type, String id) {
202209
this.id = id;
203210
}
204211

205-
/**
206-
* @deprecated use {@link #getType()}
207-
*/
208-
@Deprecated
209-
public String type;
210-
/**
211-
* @deprecated use {@link #getId()}
212-
*/
213-
@Deprecated
214-
public String id;
212+
private String type;
213+
private String id;
215214

216215
public String getType() {
217216
return type;

0 commit comments

Comments
 (0)